1
0
This repository has been archived on 2017-06-06. You can view files and clone it, but cannot push or open issues or pull requests.
informaticaD4P-2017/src/Application/Login.php

63 lines
1.8 KiB
PHP
Raw Normal View History

2017-02-23 14:31:25 +00:00
<?php
/**
* Informatica Eindproject D4p
* 6in3, Stedelijk Gymnasium Nijmegen
* Docent: Hans de Wolf
*
* ==================
*
* Daniel Boutros,
* Christiaan Goossens,
* Jelmer Hinssen
*/
namespace Inforbank\Application;
2017-02-23 14:31:25 +00:00
use \Slim\App;
use Inforbank\Application\Helper\Redirect;
2017-03-31 17:03:10 +00:00
use Inforbank\Proxy;
2017-02-23 14:31:25 +00:00
class Login
{
public function __construct(App $app)
{
2017-02-23 14:31:25 +00:00
$app->get('/login', function ($request, $response, $args) {
2017-03-31 17:03:10 +00:00
$query = $request->getQueryParams();
$error = isset($query['error']);
2017-02-23 14:31:25 +00:00
// Render index view
2017-03-31 17:03:10 +00:00
return $this->renderer->render($response, 'login.phtml', array(
'base' => Proxy::$route->getBaseUrl() . "/",
'error' => $error
));
2017-02-23 14:31:25 +00:00
});
$app->post('/login', function ($request, $response, $args) {
2017-02-23 14:31:25 +00:00
// Render index view
$post = $request->getParsedBody();
2017-03-31 17:10:28 +00:00
$query = $request->getQueryParams();
$redirect = $query['redirect'];
try {
$resp = $this->auth->login($post['rekeningnr'], $post['pascode']);
2017-03-31 17:10:28 +00:00
if ($resp && $redirect !== "") {
return Redirect::create($request, $response, $redirect);
} elseif ($resp) {
return Redirect::create($request, $response, '/rekeningen');
} else {
2017-03-31 17:10:28 +00:00
return Redirect::create($request, $response, '/login?error&redirect='.$redirect);
}
} catch (\Exception $e) {
2017-03-31 17:10:28 +00:00
return Redirect::create($request, $response, '/login?error&redirect='.$redirect);
}
});
$app->get('/logout', function ($request, $response, $args) {
$this->auth->logout();
return Redirect::create($request, $response, '/login');
2017-02-23 14:31:25 +00:00
});
}
}