Added static object linking & authorization methods
This commit is contained in:
49
src/Application/Auth/Authorization.php
Normal file
49
src/Application/Auth/Authorization.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?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['user'] = $klant;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getUser()
|
||||
{
|
||||
return $_SESSION['user'];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user