Merge remote-tracking branch 'origin/dev' into dev
# Conflicts: # src/bootstrap.php
This commit is contained in:
commit
10c8093ed5
@ -11,6 +11,6 @@
|
|||||||
"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": {
|
"autoload": {
|
||||||
"psr-4": {"InfD4p\\": "src/"}
|
"psr-4": {"Inforbank\\": "src/"}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
18
public/assets/css/demo.css
Normal file
18
public/assets/css/demo.css
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
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 {
|
||||||
|
color: #719e40;
|
||||||
|
letter-spacing: -3px;
|
||||||
|
font-family: 'Lato', sans-serif;
|
||||||
|
font-size: 100px;
|
||||||
|
font-weight: 200;
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
130
src/Application/API/Handler.php
Normal file
130
src/Application/API/Handler.php
Normal 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';
|
||||||
|
}
|
||||||
|
}
|
@ -12,7 +12,7 @@
|
|||||||
* Jelmer Hinssen
|
* Jelmer Hinssen
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace InfD4p\Application;
|
namespace Inforbank\Application;
|
||||||
|
|
||||||
use \Slim\App;
|
use \Slim\App;
|
||||||
|
|
||||||
|
@ -12,12 +12,12 @@
|
|||||||
* Jelmer Hinssen
|
* Jelmer Hinssen
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace InfD4p\Application;
|
namespace Inforbank\Application;
|
||||||
|
|
||||||
use \Slim\App;
|
use \Slim\App;
|
||||||
|
|
||||||
class Main {
|
class Main
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* Constructor function
|
* Constructor function
|
||||||
* @param App $app App Dependency Injection
|
* @param App $app App Dependency Injection
|
||||||
@ -29,7 +29,9 @@ class Main {
|
|||||||
* Hier wordt onze applicatie gestart. De functie hieronder wordt aangeroepen bij het starten van de app. Hier kun je dus routes toevoegen.
|
* 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) {
|
public function __construct(App $app)
|
||||||
|
{
|
||||||
|
// Add the default view routes
|
||||||
$app->get('/[{name}]', function ($request, $response, $args) {
|
$app->get('/[{name}]', function ($request, $response, $args) {
|
||||||
// Render index view
|
// Render index view
|
||||||
return $this->renderer->render($response, 'index.phtml', $args);
|
return $this->renderer->render($response, 'index.phtml', $args);
|
||||||
|
@ -72,8 +72,11 @@ $container['renderer'] = function ($c) {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
new InfD4p\Application\Login($app);
|
new Inforbank\Application\Login($app);
|
||||||
new InfD4p\Application\Main($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.
|
* 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.
|
||||||
|
@ -4,26 +4,7 @@
|
|||||||
<meta charset="utf-8"/>
|
<meta charset="utf-8"/>
|
||||||
<title>Slim 3</title>
|
<title>Slim 3</title>
|
||||||
<link href='//fonts.googleapis.com/css?family=Lato:300' rel='stylesheet' type='text/css'>
|
<link href='//fonts.googleapis.com/css?family=Lato:300' rel='stylesheet' type='text/css'>
|
||||||
<style>
|
<link href='assets/css/demo.css' rel='stylesheet' type='text/css'>
|
||||||
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 {
|
|
||||||
color: #719e40;
|
|
||||||
letter-spacing: -3px;
|
|
||||||
font-family: 'Lato', sans-serif;
|
|
||||||
font-size: 100px;
|
|
||||||
font-weight: 200;
|
|
||||||
margin-bottom: 0;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Slim</h1>
|
<h1>Slim</h1>
|
||||||
|
Reference in New Issue
Block a user