connection back

php
Anthony RICHARD 1 year ago
parent 1cc1128b00
commit 60f323aea7

@ -147,13 +147,12 @@ class UserGateway extends AbsGateway
} }
} }
public function findUserByLoginPassword(string $login, string $password) : User{ public function login(string $login) : array{
try { try {
$query = "SELECT * FROM User_ WHERE email=:email AND password=:password"; $query = "SELECT password FROM User_ WHERE email=:email";
$args = array(':email' => array($login, PDO::PARAM_STR), ':password' => array($password, PDO::PARAM_STR)); $args = array(':email' => array($login, PDO::PARAM_STR));
$this->con->executeQuery($query, $args); $this->con->executeQuery($query, $args);
$results = $this->con->getResults(); return $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']));
} }
catch(PDOException $e ){ catch(PDOException $e ){
throw new Exception($e->getMessage()); throw new Exception($e->getMessage());

@ -20,15 +20,16 @@ abstract class AbsModel
$cleanedLogin = strip_tags($login); $cleanedLogin = strip_tags($login);
$cleanedPassword = strip_tags($password); $cleanedPassword = strip_tags($password);
$gtw = new UserGateway(); $gtw = new UserGateway();
$student = $gtw->findUserByLoginPassword($cleanedLogin, $cleanedPassword);
if ($student) { if (password_verify($cleanedPassword, $gtw->login($cleanedLogin)[0][0])) {
session_start(); $user = $gtw->findUserByEmail($cleanedLogin);
$_SESSION['role'] = $this->role;
$_SESSION['login'] = $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(){ public function deconnection(){

Loading…
Cancel
Save