1
0

Merge branch 'dev' into 'master'

Merge current dev state into the master branch

See merge request !2
This commit is contained in:
Christiaan Goossens 2017-03-26 14:23:58 +00:00
commit ab8f1efa5d
31 changed files with 1006 additions and 97 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
/vendor/ /vendor/
/logs/* /logs/*
/tmp/

2
.htaccess Normal file
View File

@ -0,0 +1,2 @@
RewriteEngine On
RewriteRule ^$ /public [L]

8
DATABASE.md Normal file
View File

@ -0,0 +1,8 @@
Om phpMyAdmin te gebruiken voor de database moet je het volgende doen:
Inloggen op http://cpanel.verictas.nl met:
gebruikersnaam: inforbank
wachtwoord: inforban
Klik op phpMyAdmin onder "Databases".

BIN
Eindopdracht.pdf Normal file

Binary file not shown.

View File

@ -4,7 +4,7 @@ Om te kunnen werken aan dit project moet je het volgende doen:
Je doet een git clone (in een random map) (het spreekt voor zich dat je hiervoor eerst git (https://git-scm.com/downloads) moet installeren) met `git clone https://git.verictas.com/InformaticaD4p/informatica-eindproject.git`. Er verschijnt nu een nieuwe map genaamd `informatica-eindproject`. In deze map ga je werken. Je doet een git clone (in een random map) (het spreekt voor zich dat je hiervoor eerst git (https://git-scm.com/downloads) moet installeren) met `git clone https://git.verictas.com/InformaticaD4p/informatica-eindproject.git`. Er verschijnt nu een nieuwe map genaamd `informatica-eindproject`. In deze map ga je werken.
Om te starten heb je ook een PHP installatie nodig op je PC. Ik heb een zip bestand met de php installatie op http://christiaangoossens.nl/uploads/afc06760-f1b9-4458-8d93-fc6ea8b2a828/php7.zip. Je pakt dit bestand uit en vindt dan een map genaamd `php7`. Deze map zet je neer op een logische plek (bijvoorbeeld C:/php7 of C:/Program Files/php7) en die voeg je dan toe aan je windows path (dat kun je doen via Configuratischerm>System>Opstartvariabelen of met dit commando in de shell (cmd): `set PATH=%PATH%;C:\php7` (let op, wel het path veranderen naar de map waar je de `php7` map hebt neergezet). Om te starten heb je ook een PHP installatie nodig op je PC. Ik heb een zip bestand met de php installatie op http://christiaangoossens.nl/uploads/afc06760-f1b9-4458-8d93-fc6ea8b2a828/php7.zip. Je pakt dit bestand uit en vindt dan een map genaamd `php7`. Deze map zet je neer op een logische plek (bijvoorbeeld C:/php7 of C:/Program Files/php7) en die voeg je dan toe aan je windows path (dat kun je doen via Configuratischerm>System>Opstartvariabelen (let op, wel het path veranderen naar de map waar je de `php7` map hebt neergezet).
Als het goed is kun je in de `informatica-eindproject` map nu het volgende commando uitvoeren (mag in CMD of de Git shell): `php -v`. Je krijgt dan het volgende te zien: Als het goed is kun je in de `informatica-eindproject` map nu het volgende commando uitvoeren (mag in CMD of de Git shell): `php -v`. Je krijgt dan het volgende te zien:
@ -15,11 +15,10 @@ Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
``` ```
Je bent nu klaar om Composer te installeren. Composer is een hulpprogramma dat alle benodigdheden voor jouw project automatisch downloadt en toevoegt. Je kunt de Composer installer vinden op: https://getcomposer.org/download/. (Je kunt ook zelf updaten naar de laatste versie van PHP, deze is een beetje verouderd.)
Switch nu naar de dev branch en je dan ben je klaar om Composer te installeren. Composer is een hulpprogramma dat alle benodigdheden voor jouw project automatisch downloadt en toevoegt. Je kunt de Composer installer vinden op: https://getcomposer.org/download/.
Composer zal je tijdens de installatie vragen om je php versie op te geven, dit staat waarschijnlijk automatisch goed, maar je kunt hem ook zelf zoeken. Composer zal je tijdens de installatie vragen om je php versie op te geven, dit staat waarschijnlijk automatisch goed, maar je kunt hem ook zelf zoeken.
Je kunt je website nu starten via `composer run`. Er zal dan een webserver voor je worden gestart en de benodigdheden worden automatisch geinstalleerd. Je kunt nu zelf een webbrowser openen om naar `http://localhost:8080` te gaan en dan zul je je website zien.
Zodra alles geïnstalleerd is, ga je terug naar de `informatica-eindproject` map en doe je een `composer install` in de commandline. Alle benodigdheden worden nu gedownload en geïnstalleerd.
Je kunt je website nu starten via `composer start`. Er zal dan een webserver voor je worden gestart. Je kunt nu zelf een webbrowser openen om naar `http://localhost:8080` te gaan en dan zul je je website zien.

View File

@ -2,13 +2,17 @@
"require": { "require": {
"php": ">=5.5.0", "php": ">=5.5.0",
"slim/slim": "^3.1", "slim/slim": "^3.1",
"slim/php-view": "^2.0" "slim/php-view": "^2.0",
"vrana/notorm": "dev-master"
}, },
"config": { "config": {
"process-timeout" : 0 "process-timeout" : 0
}, },
"scripts": { "scripts": {
"run": "composer install && composer start",
"start": "php -S 0.0.0.0:8080 -t public public/index.php" "start": "php -S 0.0.0.0:8080 -t public public/index.php"
},
"autoload": {
"psr-4": {"Inforbank\\": "src/"}
} }
} }

108
composer.lock generated
View File

@ -4,22 +4,25 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "37fe8b36d00a40955cbd52e4949aa8f1", "content-hash": "ca8f6133814e92e4e70538a15c4b1a32",
"packages": [ "packages": [
{ {
"name": "container-interop/container-interop", "name": "container-interop/container-interop",
"version": "1.1.0", "version": "1.2.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/container-interop/container-interop.git", "url": "https://github.com/container-interop/container-interop.git",
"reference": "fc08354828f8fd3245f77a66b9e23a6bca48297e" "reference": "79cbf1341c22ec75643d841642dd5d6acd83bdb8"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/container-interop/container-interop/zipball/fc08354828f8fd3245f77a66b9e23a6bca48297e", "url": "https://api.github.com/repos/container-interop/container-interop/zipball/79cbf1341c22ec75643d841642dd5d6acd83bdb8",
"reference": "fc08354828f8fd3245f77a66b9e23a6bca48297e", "reference": "79cbf1341c22ec75643d841642dd5d6acd83bdb8",
"shasum": "" "shasum": ""
}, },
"require": {
"psr/container": "^1.0"
},
"type": "library", "type": "library",
"autoload": { "autoload": {
"psr-4": { "psr-4": {
@ -31,7 +34,8 @@
"MIT" "MIT"
], ],
"description": "Promoting the interoperability of container objects (DIC, SL, etc.)", "description": "Promoting the interoperability of container objects (DIC, SL, etc.)",
"time": "2014-12-30T15:22:37+00:00" "homepage": "https://github.com/container-interop/container-interop",
"time": "2017-02-14T19:40:03+00:00"
}, },
{ {
"name": "nikic/fast-route", "name": "nikic/fast-route",
@ -122,6 +126,55 @@
], ],
"time": "2015-09-11T15:10:35+00:00" "time": "2015-09-11T15:10:35+00:00"
}, },
{
"name": "psr/container",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/container.git",
"reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/container/zipball/b7ce3b176482dbbc1245ebf52b181af44c2cf55f",
"reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Container\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common Container Interface (PHP FIG PSR-11)",
"homepage": "https://github.com/php-fig/container",
"keywords": [
"PSR-11",
"container",
"container-interface",
"container-interop",
"psr"
],
"time": "2017-02-14T16:28:37+00:00"
},
{ {
"name": "psr/http-message", "name": "psr/http-message",
"version": "1.0.1", "version": "1.0.1",
@ -290,12 +343,53 @@
"router" "router"
], ],
"time": "2016-12-20T20:30:47+00:00" "time": "2016-12-20T20:30:47+00:00"
},
{
"name": "vrana/notorm",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/vrana/notorm.git",
"reference": "e49d5d2f1bfe440dc82b61f46172635dfcb6f6dd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/vrana/notorm/zipball/e49d5d2f1bfe440dc82b61f46172635dfcb6f6dd",
"reference": "e49d5d2f1bfe440dc82b61f46172635dfcb6f6dd",
"shasum": ""
},
"type": "library",
"autoload": {
"files": [
"NotORM.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0",
"GPL-2.0+"
],
"authors": [
{
"name": "Jakub Vrána",
"homepage": "http://www.vrana.cz/"
}
],
"description": "NotORM is a PHP library for simple working with data in the database.",
"homepage": "http://www.notorm.com/",
"keywords": [
"database",
"dbal"
],
"time": "2014-10-30 16:55:08"
} }
], ],
"packages-dev": [], "packages-dev": [],
"aliases": [], "aliases": [],
"minimum-stability": "stable", "minimum-stability": "stable",
"stability-flags": [], "stability-flags": {
"vrana/notorm": 20
},
"prefer-stable": false, "prefer-stable": false,
"prefer-lowest": false, "prefer-lowest": false,
"platform": { "platform": {

View File

@ -1,10 +1,4 @@
RewriteEngine On RewriteEngine on
# Some hosts may require you to use the `RewriteBase` directive.
# If you need to use the `RewriteBase` directive, it should be the
# absolute physical path to the directory that contains this htaccess file.
#
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L] RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [NC,L,QSA]

View File

View File

@ -1,4 +1,28 @@
<?php <?php
/**
* Informatica Eindproject D4p
* 6in3, Stedelijk Gymnasium Nijmegen
* Docent: Hans de Wolf
*
* ==================
*
* Daniel Boutros,
* Christiaan Goossens,
* Jelmer Hinssen
*/
/**
* Session fix for development
*/
if (session_save_path() === "") {
ini_set('session.save_path', realpath(__DIR__ . '/../tmp'));
}
/**
* Check if the script is running in CLI mode
*/
if (PHP_SAPI == 'cli-server') { if (PHP_SAPI == 'cli-server') {
// To help the built-in PHP dev server, check if the request was actually for // To help the built-in PHP dev server, check if the request was actually for
// something which should probably be served as a static file // something which should probably be served as a static file
@ -6,25 +30,18 @@ if (PHP_SAPI == 'cli-server') {
$file = __DIR__ . $url['path']; $file = __DIR__ . $url['path'];
if (is_file($file)) { if (is_file($file)) {
return false; return false;
} elseif (pathinfo($url['path'], PATHINFO_EXTENSION) !== "") {
return false;
} }
} }
/**
* Require the Composer autoloader to load dependencies
*/
require __DIR__ . '/../vendor/autoload.php'; require __DIR__ . '/../vendor/autoload.php';
session_start(); /**
* Load the bootstrapping script
*/
// Instantiate the app include __DIR__ . '/../src/bootstrap.php';
$settings = require __DIR__ . '/../src/settings.php';
$app = new \Slim\App($settings);
// Set up dependencies
require __DIR__ . '/../src/dependencies.php';
// Register middleware
require __DIR__ . '/../src/middleware.php';
// Register routes
require __DIR__ . '/../src/routes.php';
// Run app
$app->run();

37
src/Application.php Normal file
View File

@ -0,0 +1,37 @@
<?php
/**
* Informatica Eindproject D4p
* 6in3, Stedelijk Gymnasium Nijmegen
* Docent: Hans de Wolf
*
* ==================
*
* Daniel Boutros,
* Christiaan Goossens,
* Jelmer Hinssen
*/
namespace Inforbank;
class Application
{
public static $container;
public static $app;
public static function set($app)
{
self::$app = $app;
self::$container = $app->getContainer();
}
public static function getContainer()
{
return self::$container;
}
public static function getApplication()
{
return self::$app;
}
}

View File

@ -0,0 +1,130 @@
<?php
/**
* Informatica Eindproject D4p
* 6in3, Stedelijk Gymnasium Nijmegen
* Docent: Hans de Wolf
*
* ==================
*
* Daniel Boutros,
* Christiaan Goossens,
* Jelmer Hinssen
*/
namespace Inforbank\Application\API;
use \Slim\App;
class Handler
{
public function __construct(App $app)
{
/**
* Create the API route group
*/
$app->group('/api', function () {
/**
* TransactionRequest API Endpoint
*
* Requires the following POST arguments:
* - clientId
* - transactionId
* - amount
* - description
* - returnUrl
* - sha1
*/
$this->post('/transactionRequest', function ($request, $response, $args) {
$parsedBody = $request->getParsedBody();
if (isset($parsedBody['clientId']) && isset($parsedBody['transactionId']) && isset($parsedBody['amount']) && isset($parsedBody['description']) && isset($parsedBody['returnUrl']) && isset($parsedBody['sha1'])) {
// Correct request
$clientSecret = Handler::getClientSecret($parsedBody['clientId']);
$sha = sha1($parsedBody['transactionId'] . $parsedBody['amount'] . $clientSecret);
if ($sha === $parsedBody['sha1']) {
$responseJSON = array(
"success" => true,
"redirect" => "https://example.com"
);
} else {
$response = $response->withStatus(403);
$responseJSON = array(
"success" => false,
"error" => "Incorrect sha1 verification hash."
);
}
} else {
$response = $response->withStatus(400);
$responseJSON = array(
"success" => false,
"error" => "Missing one of the following attributes: [clientId, transactionId, amount, description, returnUrl, sha1]"
);
}
$body = $response->getBody();
$body->write(json_encode($responseJSON));
return $response->withBody($body);
});
/**
* StatusRequest API Endpoint
*
* Requires the following POST arguments:
* - clientId
* - transactionId
* - sha1
*/
$this->post('/statusRequest', function ($request, $response, $args) {
$parsedBody = $request->getParsedBody();
if (isset($parsedBody['clientId']) && isset($parsedBody['transactionId']) && isset($parsedBody['sha1'])) {
// Correct request
$clientSecret = Handler::getClientSecret($parsedBody['clientId']);
$sha = sha1($parsedBody['transactionId'] . $clientSecret);
if ($sha === $parsedBody['sha1']) {
$responseJSON = array(
"success" => true,
"transaction" => array(
"status" => "Success",
"transactionId" => "notyetfromdb",
"someotherrandomkey" => "changethis"
)
);
} else {
$response = $response->withStatus(403);
$responseJSON = array(
"success" => false,
"error" => "Incorrect sha1 verification hash."
);
}
} else {
$response = $response->withStatus(400);
$responseJSON = array(
"success" => false,
"error" => "Missing one of the following attributes: [clientId, transactionId, sha1]"
);
}
$body = $response->getBody();
$body->write(json_encode($responseJSON));
return $response->withBody($body);
});
})->add(function ($request, $response, $next) {
/**
* Add the correct JSON headers to the responses
*/
$response = $response->withHeader('Content-type', 'application/json');
return $next($request, $response);
});
}
public static function getClientSecret($clientId)
{
return '3';
}
}

View File

@ -0,0 +1,59 @@
<?php
/**
* Informatica Eindproject D4p
* 6in3, Stedelijk Gymnasium Nijmegen
* Docent: Hans de Wolf
*
* ==================
*
* Daniel Boutros,
* Christiaan Goossens,
* Jelmer Hinssen
*/
namespace Inforbank\Application\Auth;
use Inforbank\Application;
class Authorization
{
public function login($rekeningnr, $passcode)
{
$container = Application::getContainer();
$db = $container->db;
$rekeningen = $db->rekeningen->where('rekeningnr', $rekeningnr);
if (count($rekeningen) !== 1) {
throw new \Exception("Rekening niet bekend.");
}
$id = $rekeningen->max("id");
$klantnr = $rekeningen[$id]['klantid'];
$klant = $db->klanten->where('id', $klantnr)[$klantnr];
if ($klant['code'] === $passcode) {
$_SESSION['userid'] = $klant['id'];
return true;
}
return false;
}
public function getUserID()
{
return $_SESSION['userid'];
}
public function isUserAuthenticated()
{
return $this->getUserID() !== null;
}
public function logout()
{
unset($_SESSION['userid']);
}
}

View File

@ -0,0 +1,34 @@
<?php
/**
* Informatica Eindproject D4p
* 6in3, Stedelijk Gymnasium Nijmegen
* Docent: Hans de Wolf
*
* ==================
*
* Daniel Boutros,
* Christiaan Goossens,
* Jelmer Hinssen
*/
namespace Inforbank\Application\Auth;
use Inforbank\Application;
use Inforbank\Application\Helper\Redirect;
class Middleware
{
public function __invoke($request, $response, $next)
{
$container = Application::getContainer();
// Check for an existing session
if ($container->auth->isUserAuthenticated()) {
return $next($request, $response);
} else {
// Redirect to the login page
return Redirect::create($response, '/login');
}
}
}

View File

@ -0,0 +1,28 @@
<?php
/**
* Informatica Eindproject D4p
* 6in3, Stedelijk Gymnasium Nijmegen
* Docent: Hans de Wolf
*
* ==================
*
* Daniel Boutros,
* Christiaan Goossens,
* Jelmer Hinssen
*/
namespace Inforbank\Application;
use \Slim\App;
class Daniel
{
public function __construct(App $app)
{
$app->get('/daniel', function ($request, $response, $args) {
// Render index view
return $this->renderer->render($response, 'Daniel.phtml', $args);
});
}
}

View File

@ -0,0 +1,64 @@
<?php
/**
* Informatica Eindproject D4p
* 6in3, Stedelijk Gymnasium Nijmegen
* Docent: Hans de Wolf
*
* ==================
*
* Daniel Boutros,
* Christiaan Goossens,
* Jelmer Hinssen
*/
namespace Inforbank\Application\Helper;
class IBAN
{
private function wordToNumbers($word)
{
$newword = "";
$wordarray = str_split($word);
foreach ($wordarray as $v) {
$newword .= ord(strtolower($v)) - 87;
}
return $newword;
}
public function getIBAN($rekeningnr)
{
$landcode = "NL"; // NL in vertaling
$landnumber = $this->wordToNumbers($landcode);
$bankcode = "INFO";
$banknumber = $this->wordToNumbers($bankcode);
$rekeningnr = str_pad($rekeningnr, 10, 0, STR_PAD_LEFT);
$bignum = $banknumber . $rekeningnr . $landnumber . "00";
$modulo97 = '';
$checkdigits = '00';
// begin modulo staartdeling
$modulo97 = (int)substr($bignum, 0, 6);
$modulo97 = $modulo97 % 97;
$modulo97 = (1000000 * $modulo97) + (int)substr($bignum, 6, 6);
$modulo97 = $modulo97 % 97;
$modulo97 = (1000000 * $modulo97) + (int)substr($bignum, 12, 6);
$modulo97 = $modulo97 % 97;
$modulo97 = (1000000 * $modulo97) + (int)substr($bignum, 18, 6);
$modulo97 = $modulo97 % 97;
$checkdigits = 98 - $modulo97;
// einde modulo staartdeling
if (strlen($checkdigits) < 2) {
$checkdigits = '0' . $checkdigits;
}
$rekeningnrarr = str_split($rekeningnr, 4);
return $landcode.$checkdigits." ".$bankcode." ".$rekeningnrarr[0]." ".$rekeningnrarr[1]." ".$rekeningnrarr[2];
}
}

View File

@ -0,0 +1,41 @@
<?php
/**
* Informatica Eindproject D4p
* 6in3, Stedelijk Gymnasium Nijmegen
* Docent: Hans de Wolf
*
* ==================
*
* Daniel Boutros,
* Christiaan Goossens,
* Jelmer Hinssen
*/
namespace Inforbank\Application\Helper;
use Inforbank\Application;
class Klant
{
public function getCurrentUser()
{
$container = Application::getContainer();
$user = $container->auth->getUserID();
$db = $container->db;
$klant = $db->klanten->where('id', $user)[$user];
return array(
'voornaam' => $klant['voornaam'],
'tussenvoegsel' => $klant['tussenvoegsel'],
'achternaam' => $klant['achternaam'],
'bedrijfsnaam' => $klant['bedrijfsnaam'],
'straat' => $klant['straat'],
'huisnummer' => $klant['huisnummer'],
'postcode' => $klant['postcode'],
'woonplaats' => $klant['woonplaats']
);
}
}

View File

@ -0,0 +1,35 @@
<?php
/**
* Informatica Eindproject D4p
* 6in3, Stedelijk Gymnasium Nijmegen
* Docent: Hans de Wolf
*
* ==================
*
* Daniel Boutros,
* Christiaan Goossens,
* Jelmer Hinssen
*/
namespace Inforbank\Application\Helper;
class Redirect
{
public static function create($response, $path)
{
$response = $response->withStatus(302);
$response = $response->withHeader('Location', Redirect::getBasepath() . $path);
return $response;
}
private static function getBasepath()
{
if (isset($_SERVER['HTTPS'])) {
$protocol = ($_SERVER['HTTPS'] && $_SERVER['HTTPS'] != "off") ? "https" : "http";
} else {
$protocol = 'http';
}
return $protocol . "://" . $_SERVER['HTTP_HOST'];
}
}

View File

@ -0,0 +1,42 @@
<?php
/**
* Informatica Eindproject D4p
* 6in3, Stedelijk Gymnasium Nijmegen
* Docent: Hans de Wolf
*
* ==================
*
* Daniel Boutros,
* Christiaan Goossens,
* Jelmer Hinssen
*/
namespace Inforbank\Application\Helper;
use Inforbank\Application;
class Rekeningen
{
public function getCurrentUserRekeningen()
{
$container = Application::getContainer();
$user = $container->auth->getUserID();
$db = $container->db;
$ibanhelper = new IBAN;
$rekeningen = $db->rekeningen->where('klantid', $user);
$returnArray = array();
foreach ($rekeningen as $rekening) {
$returnArray[] = array(
"rekeningnr" => $ibanhelper->getIBAN($rekening['rekeningnr']),
"saldo" => (double) $rekening['saldo']
);
}
return $returnArray;
}
}

51
src/Application/Login.php Normal file
View File

@ -0,0 +1,51 @@
<?php
/**
* Informatica Eindproject D4p
* 6in3, Stedelijk Gymnasium Nijmegen
* Docent: Hans de Wolf
*
* ==================
*
* Daniel Boutros,
* Christiaan Goossens,
* Jelmer Hinssen
*/
namespace Inforbank\Application;
use \Slim\App;
use Inforbank\Application\Helper\Redirect;
class Login
{
public function __construct(App $app)
{
$app->get('/login', function ($request, $response, $args) {
// Render index view
return $this->renderer->render($response, 'login.phtml', $args);
});
$app->post('/login', function ($request, $response, $args) {
// Render index view
$post = $request->getParsedBody();
try {
$resp = $this->auth->login($post['rekeningnr'], $post['pascode']);
if ($resp) {
return Redirect::create($response, '/');
} else {
return Redirect::create($response, '/login?error');
}
} catch (\Exception $e) {
return Redirect::create($response, '/login?error');
}
});
$app->get('/logout', function ($request, $response, $args) {
$this->auth->logout();
return Redirect::create($response, '/login');
});
}
}

48
src/Application/Main.php Normal file
View File

@ -0,0 +1,48 @@
<?php
/**
* Informatica Eindproject D4p
* 6in3, Stedelijk Gymnasium Nijmegen
* Docent: Hans de Wolf
*
* ==================
*
* Daniel Boutros,
* Christiaan Goossens,
* Jelmer Hinssen
*/
namespace Inforbank\Application;
use \Slim\App;
use Inforbank\Application\Helper\Klant;
use Inforbank\Application\Helper\Rekeningen;
class Main
{
/**
* Constructor function
* @param App $app App Dependency Injection
*
* ==============
* INSTRUCTIEBLOK
* ==============
*
* Hier wordt onze applicatie gestart. De functie hieronder wordt aangeroepen bij het starten van de app. Hier kun je dus routes toevoegen.
*
*/
public function __construct(App $app)
{
$app->get('/', function ($request, $response, $args) {
// Ophalen klant
$klant = Klant::getCurrentUser();
$rekeningen = Rekeningen::getCurrentUserRekeningen();
// Render index view
return $this->renderer->render($response, 'index.phtml', [
'klant' => $klant,
'rekeningen' => $rekeningen
]);
})->add(new Auth\Middleware());
}
}

134
src/bootstrap.php Normal file
View File

@ -0,0 +1,134 @@
<?php
/**
* Informatica Eindproject D4p
* 6in3, Stedelijk Gymnasium Nijmegen
* Docent: Hans de Wolf
*
* ==================
*
* Daniel Boutros,
* Christiaan Goossens,
* Jelmer Hinssen
*/
/**
* BOOTSTRAPPING SCRIPT
*/
session_start();
// Get the Slim framework settings
$settings = require __DIR__ . '/settings.php';
// Create the Slim application object with the settings
/**
* ==============
* INSTRUCTIEBLOK
* ==============
*
* Slim Framework (https://www.slimframework.com/) is een basisframework om routing in PHP gemakkelijker te maken. Je kunt via functies van het Slim\App object verschillende routes aanmaken en daar PHP code aan koppelen. Slim zorgt er dan voor dat je daar automatisch uitkomt als je de opgegeven URL intypt in je browser.
*
* Slim maakt het ook makkelijker om benodigdheden voor je applicatie (dependencies) op een goede (standaardengebaseerde) manier te koppelen. Dit gebeurt bijvoorbeeld hieronder. Slim gebruikt hiervoor een container (http://php-di.org/doc/understanding-di.html)
*
*/
$app = new \Slim\App($settings);
/**
* Setup dependencies
*/
$container = $app->getContainer();
// Create the view renderer
/**
* ==============
* INSTRUCTIEBLOK
* ==============
*
* Hier wordt de 'view renderer' aan de dependency container (zie hierboven) toegevoegd. Dit zorgt dat je in je applicatie deze 'view renderer' kunt gebruiken via `$this->renderer`.
* De renderer wordt gebruikt om een PHP template (https://en.wikipedia.org/wiki/Web_template_system) aan je URL te koppelen.
*
* Dit kun je doen in je 'route' (URL) met de volgende code:
*
* ```
* return $this->renderer->render($response, 'index.phtml', $args);
* ```
*
* (index.phtml kan hier vervangen worden door een template adres uit de map templates)
*/
$container['renderer'] = function ($c) {
$settings = $c->get('settings')['renderer'];
return new Slim\Views\PhpRenderer($settings['template_path']);
};
// Add the database layer
/**
* ==============
* INSTRUCTIEBLOK
* ==============
*
* Je kunt de database gebruiken in je code via $this->db. Vermijd het direct gebruiken van het PDO object via $this->get('db.pdo').
* Je kunt hiervoor beter de ingebouwde functies van NotORM gebruiken.
*/
$container['db.pdo'] = function ($c) {
$settings = $c->get('settings')['db'];
$host = $settings['host'];
$name = $settings['name'];
$user = $settings['user'];
$pass = $settings['pass'];
$charset = $settings['charset'];
return new PDO("mysql:dbname=$name;host=$host;charset=$charset", $user, $pass,
array(
PDO::ATTR_TIMEOUT => 5,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
));
};
$container['db'] = function ($c) {
$settings = $c->get('settings')['db'];
$pdo = $c->get('db.pdo');
return new NotORM($pdo);
};
// Add auth object
$container['auth'] = function () {
return new \Inforbank\Application\Auth\Authorization();
};
// Link static objects
Inforbank\Application::set($app);
// Inject the application main class
/**
* ==============
* INSTRUCTIEBLOK
* ==============
*
* Hieronder wordt de Main class van onze applicatie aangeroepen.
*
* In object georiënteerd PHP is een applicatie vaak gestructureerd in meerdere 'classes', die ook wel objecten worden genoemd. Een object kan worden gemaakt door het volgende:
*
*/
new Inforbank\Application\Login($app);
new Inforbank\Application\Daniel($app);
new Inforbank\Application\Main($app);
// Added API handler
new Inforbank\Application\API\Handler($app);
/**
* Bij het maken van dit object is in de class de __construct functie aangeroepen met de parameter $app. De functies die daar in staan zullen nu worden uitgevoerd.
*
* Je kunt de class herkennen uit talen als Java en C(++ of #), omdat ze daar ook worden gebruikt.
*
* Je kunt voor een beter begrip de volgende sites lezen:
* - https://www.sitepoint.com/php-53-namespaces-basics/ (over namespaces (wij gebruiken InfD4p\Application))
* - http://php.net/manual/en/language.oop5.basic.php (over de class)
*/
// Run app
$app->run();

View File

@ -1,10 +0,0 @@
<?php
// DIC configuration
$container = $app->getContainer();
// view renderer
$container['renderer'] = function ($c) {
$settings = $c->get('settings')['renderer'];
return new Slim\Views\PhpRenderer($settings['template_path']);
};

View File

@ -1,4 +0,0 @@
<?php
// Application middleware
// e.g: $app->add(new \Slim\Csrf\Guard);

View File

@ -1,7 +0,0 @@
<?php
// Routes
$app->get('/[{name}]', function ($request, $response, $args) {
// Render index view
return $this->renderer->render($response, 'index.phtml', $args);
});

View File

@ -7,6 +7,15 @@ return [
// Renderer settings // Renderer settings
'renderer' => [ 'renderer' => [
'template_path' => __DIR__ . '/../templates/', 'template_path' => __DIR__ . '/../templates/',
],
// Database settings
'db' => [
'host' => '185.56.145.27',
'user' => 'inforban_db',
'pass' => 'inforbank',
'name' => 'inforban_db',
'charset' => 'utf8'
] ]
], ],
]; ];

2
templates/__footer.phtml Normal file
View File

@ -0,0 +1,2 @@
</body>
</html>

8
templates/__header.phtml Normal file
View File

@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Inforbank</title>
<link rel="stylesheet" href="assets/css/main.css">
</head>
<body>

59
templates/daniel.phtml Normal file
View File

@ -0,0 +1,59 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>InforBank - Inloggen</title>
<link href='//fonts.googleapis.com/css?family=Lato:300' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!--link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous" -->
</head>
<style>
.form-signin {
max-width: 330px;
padding: 15px;
margin: 0 auto;
}
.btn-primary {
color: #ff6000;
background-color: #2e652c;
border-color: #2e6da4;
margin-top: 5px;
}
.jumbotron{
//text-align: center;
}
.form-control{
margin: 5px 0;
}
body{
color: #ff6000;
}
.footer{
text-align: center;
}
</style>
<body>
<div class="jumbotron">
<div class="container">
<h1>InforBank</h1>
</div>
</div>
<div class="container">
<form class="form-signin" method="post">
<h2 class="form-signin-heading">Inloggen</h2>
<label for="inputUsername" class="sr-only">Rekeningnummer (alleen cijfers)</label>
<input type="text" id="inputUsername" name="rekeningnr" class="form-control" placeholder="012456789"/>
<label for="inputPassword" class="sr-only">Pascode</label>
<input type="password" id="inputPassword" name="pascode" class="form-control" placeholder="0000"/>
<button class="btn btn-lg btn-primary btn-block" type="submit">Inloggen</button>
</form>
</div>
<footer class="footer">
&copy 2017 Alle rechten voorbehouden
</footer>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</body>
</html>

View File

@ -1,38 +1,9 @@
<!DOCTYPE html> <?php include '__header.phtml'; ?>
<html>
<head>
<meta charset="utf-8"/>
<title>Slim 3</title>
<link href='//fonts.googleapis.com/css?family=Lato:300' rel='stylesheet' type='text/css'>
<style>
body {
margin: 50px 0 0 0;
padding: 0;
width: 100%;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
text-align: center;
color: #aaa;
font-size: 18px;
}
h1 { <p>Welkom klant <?= $_SESSION['userid'] ?></p>
color: #719e40; <a href="/logout">Uitloggen</a>
letter-spacing: -3px; <br/>
font-family: 'Lato', sans-serif; <pre><?php echo json_encode($klant); ?></pre>
font-size: 100px; <pre><?php echo json_encode($rekeningen); ?></pre>
font-weight: 200;
margin-bottom: 0;
}
</style>
</head>
<body>
<h1>Slim</h1>
<div>a microframework for PHP</div>
<?php if (isset($name)) : ?> <?php include '__footer.phtml'; ?>
<h2>Hello <?= htmlspecialchars($name); ?>!</h2>
<?php else: ?>
<p>Try <a href="http://www.slimframework.com">SlimFramework</a>
<?php endif; ?>
</body>
</html>

59
templates/login.phtml Normal file
View File

@ -0,0 +1,59 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>InforBank - Inloggen</title>
<link href='//fonts.googleapis.com/css?family=Lato:300' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!--link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous" -->
</head>
<style>
.form-signin {
max-width: 330px;
padding: 15px;
margin: 0 auto;
}
.btn-primary {
color: #ff6000;
background-color: #2e652c;
border-color: #2e6da4;
margin-top: 5px;
}
.jumbotron{
//text-align: center;
}
.form-control{
margin: 5px 0;
}
body{
color: #ff6000;
}
.footer{
text-align: center;
}
</style>
<body>
<div class="jumbotron">
<div class="container">
<h1>InforBank</h1>
</div>
</div>
<div class="container">
<form class="form-signin" method="post">
<h2 class="form-signin-heading">Inloggen</h2>
<label for="inputUsername" class="sr-only">Rekeningnummer (alleen cijfers)</label>
<input type="text" id="inputUsername" name="rekeningnr" class="form-control" placeholder="012456789"/>
<label for="inputPassword" class="sr-only">Pascode</label>
<input type="password" id="inputPassword" name="pascode" class="form-control" placeholder="0000"/>
<button class="btn btn-lg btn-primary btn-block" type="submit">Inloggen</button>
</form>
</div>
<footer class="footer">
&copy 2017 Alle rechten voorbehouden
</footer>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</body>
</html>