php
Anthony RICHARD 2 years ago
parent a63a94e6ba
commit c38194573b

@ -55,12 +55,12 @@ class FrontController
case 'disconnect': case 'disconnect':
$this->disconnect(); $this->disconnect();
break; break;
case 'quiz': case 'quiz':
$this->quiz(); $this->quiz();
break; break;
default : default :
if ($id != null && !$this->checkIdExist($id)) throw new Exception("identifiant invalide");
if ($target == null) throw new Exception("pas de target"); if ($target == null) throw new Exception("pas de target");
if (isset($_SESSION['login']) && isset($_SESSION['roles'])) { if (isset($_SESSION['login']) && isset($_SESSION['roles'])) {
@ -112,16 +112,15 @@ class FrontController
$model = new MdlStudent(); $model = new MdlStudent();
$login = strip_tags($_POST['logemail']); $login = strip_tags($_POST['logemail']);
$password = strip_tags($_POST['logpass']); $password = strip_tags($_POST['logpass']);
if (!$this->checkLoginExist($login)) throw new Exception(("login invalide"));
$user = $model->connection($login, $password); $user = $model->connection($login, $password);
if ($user == null) throw new Exception("mot de passe invalide"); if ($user == null) throw new Exception("mot de passe invalide");
$this->home(); $this->home();
} }
public function checkIdExist(int $id):bool public function checkLoginExist(string $login): bool {
{
$mdl = new MdlStudent(); $mdl = new MdlStudent();
$res = $mdl->checkIdExist($id); return $mdl->checkLoginExist($login);
return $res;
} }
public function disconnect(): void { public function disconnect(): void {
@ -133,6 +132,4 @@ class FrontController
$ctrl = new StudentController(); $ctrl = new StudentController();
$ctrl->quiz(); $ctrl->quiz();
} }
} }

@ -125,6 +125,7 @@ class UserGateway extends AbsGateway
$args = array(':id' => array($id, PDO::PARAM_INT)); $args = array(':id' => array($id, PDO::PARAM_INT));
$this->con->executeQuery($query, $args); $this->con->executeQuery($query, $args);
$results = $this->con->getResults(); $results = $this->con->getResults();
if (empty($results)) return null;
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 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 ){
@ -159,12 +160,13 @@ class UserGateway extends AbsGateway
} }
} }
public function findUserByEmail(string $email) : User{ public function findUserByEmail(string $email){
try { try {
$query = "SELECT * FROM User_ WHERE email=:email"; $query = "SELECT * FROM User_ WHERE email=:email";
$args = array(':email' => array($email, PDO::PARAM_STR)); $args = array(':email' => array($email, PDO::PARAM_STR));
$this->con->executeQuery($query, $args); $this->con->executeQuery($query, $args);
$results = $this->con->getResults(); $results = $this->con->getResults();
if (empty($results)) return null;
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 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 ){
@ -296,17 +298,4 @@ class UserGateway extends AbsGateway
throw new Exception($e->getMessage()); throw new Exception($e->getMessage());
} }
} }
public function checkIdExist(int $id): bool {
$query = "SELECT COUNT(*) AS count FROM User_ WHERE id = :id";
$args = array(':id' => array($id, PDO::PARAM_INT));
$this->con->executeQuery($query, $args);
$results = $this->con->getResults();
if (is_array($results) && count($results) > 0) {
$count = $results[0]['count'];
return ($count > 0);
}
return false;
}
} }

@ -40,5 +40,10 @@ abstract class AbsModel
$_SESSION = array(); $_SESSION = array();
} }
public function checkLoginExist(string $login) {
$gtw = new UserGateway();
return $gtw->findUserByEmail($login) != null;
}
public abstract function is(string $login, array $roles); public abstract function is(string $login, array $roles);
} }

@ -13,10 +13,6 @@ class MdlStudent extends AbsModel
{ {
parent::__construct("student"); parent::__construct("student");
} }
public function checkIdExist(int $id):bool {
$gtw = new UserGateway();
return $gtw->checkIdExist($id);
}
public function getAll():array{ public function getAll():array{
$gtw = new VocabularyListGateway(); $gtw = new VocabularyListGateway();

Loading…
Cancel
Save