Patrick BRUGIERE 1 year ago
commit 9e2d054bd3

@ -16,6 +16,7 @@ class FrontController
$router->setBasePath($altorouterPath);
$router->map('GET', '/', 'AppController');
$router->map('GET|POST', '/[a:action]?', 'NULL');
$router->map( 'GET|POST', '/admin/[i:id]/[a:action]?', 'AdminController');
$router->map( 'GET|POST', '/teacher/[i:id]/[a:action]?', 'TeacherController');
$router->map( 'GET|POST', '/student/[i:id]/[a:action]?', 'StudentController');
@ -32,6 +33,10 @@ class FrontController
echo $twig->render('home.html');
break;
case 'login':
echo $twig->render('login.html');
break;
default :
$controller = '\\controller\\' . $controller;
$controller = new $controller;

@ -147,13 +147,12 @@ class UserGateway extends AbsGateway
}
}
public function findUserByLoginPassword(string $login, string $password) : User{
public function login(string $login) : array{
try {
$query = "SELECT * FROM User_ WHERE email=:email AND password=:password";
$args = array(':email' => array($login, PDO::PARAM_STR), ':password' => array($password, PDO::PARAM_STR));
$query = "SELECT password FROM User_ WHERE email=:email";
$args = array(':email' => array($login, PDO::PARAM_STR));
$this->con->executeQuery($query, $args);
$results = $this->con->getResults();
return new User($results[0]['id'], $results[0]['password'], $results[0]['email'], $results[0]['name'], $results[0]['surname'], $results[0]['nickname'], $results[0]['image'], $results[0]['extraTime'], $results[0]['groupID'], $this->getRoles($results[0]['id']));
return $this->con->getResults();
}
catch(PDOException $e ){
throw new Exception($e->getMessage());

@ -20,15 +20,16 @@ abstract class AbsModel
$cleanedLogin = strip_tags($login);
$cleanedPassword = strip_tags($password);
$gtw = new UserGateway();
$student = $gtw->findUserByLoginPassword($cleanedLogin, $cleanedPassword);
if ($student) {
session_start();
$_SESSION['role'] = $this->role;
if (password_verify($cleanedPassword, $gtw->login($cleanedLogin)[0][0])) {
$user = $gtw->findUserByEmail($cleanedLogin);
$_SESSION['login'] = $cleanedLogin;
return true;
$roles = array();
foreach ($roles as $role) $roles[] = $role;
$_SESSION['roles'] = $roles;
return $user;
}
else return false;
return null;
}
public function deconnection(){

@ -34,7 +34,7 @@
<ul class="navbar-nav ms-auto">
<li class="nav-item"><a class="nav-link" href="#game">Game</a></li>
<li class="nav-item"><a class="nav-link" href="#download">Download</a></li>
<li class="nav-item"><a class="nav-link" href="login.html">My account</a></li>
<li class="nav-item"><a class="nav-link" href="login">My account</a></li>
</ul>
</div>
</div>

@ -10,7 +10,7 @@
</head>
<body>
<div class="section">
<a href="home.html"><img src="assets/img/home.png"></a>
<a href="."><img src="assets/img/home.png"></a>
<div class="container">
<div class="row full-height justify-content-center">
<div class="col-12 text-center align-self-center py-5">

Loading…
Cancel
Save