1
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

77 lines
1.5 KiB
PHP

<?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
{
/**
* Login user
* @param $rekeningnr
* @param $passcode
* @return boolean
*/
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;
}
/**
* Return current user id
* @return any
*/
public function getUserID()
{
return $_SESSION['userid'];
}
/**
* Return if the current user is authenticated
* @return boolean
*/
public function isUserAuthenticated()
{
return $this->getUserID() !== null;
}
/**
* Delete user session data
*/
public function logout()
{
unset($_SESSION['userid']);
}
}