FIX : Connection admin

php
Renaud BEURET 1 year ago
parent c275e41df0
commit 2d6e393e3f

@ -11,24 +11,12 @@ use model\Scientifique;
//gerer la connexion des admins
class AdminController {
//public function __construct(array $params)
//{
//
// //verifier si l'utilisateur est connecté et admin
// if (isset($_SESSION["isAdmin"])) {
// if ($_SESSION["isAdmin"] == true) {
// } else if (isset($_SESSION["isLogged"])) {
// //verifier si l'utilisateur est connecté mais pas admin
// if ($_SESSION["isLogged"] == true) {
// exit(0);
// }
// } else {
// //renvoyer a la page de connexion pour les non connectés
// echo '<meta http-equiv="refresh" content="0; url=login">';
// }
// }
//}
public function defaultAction(array $params) {
global $twig;
echo $twig->render('admin/accueil.html');
}
public function notLogged(array $params) {
global $twig;
//dire acces interdit aux non admins
@ -78,7 +66,7 @@ class AdminController {
echo $twig->render('admin/ajouterScientifiques.html',['sexe' => $sexe->getAll(), 'themes' => $theme->getAll(), 'difficultes' => $diff->getAll(), 'scientifique' => $scient]);
}
public function listeScientifique() {
public function listeScientifiques(array $params) {
global $twig;
$ms = new MdlScientifique();

@ -7,8 +7,7 @@ use PDOStatement;
class AdminGateway
{
private PDO $con;
private PDOStatement $stmt;
private Connection $con;
public function __construct(Connection $con)
{
$this->con=$con;

@ -0,0 +1,25 @@
<?php
namespace model;
class UtilisateurConnecteGateway extends JoueurGateway {
function __construct(Connection $con) {
$this->con = $con;
}
public function login(string $email, string $password): bool
{
$sql = "SELECT * FROM Utilisateur WHERE email=:email";
$this->con->executeQuery($sql, array(
':email' => array($email, \PDO::PARAM_STR)
));
$result = $this->con->getOneResult();
if (!empty($result)) {
return password_verify($password,$result['password']);
}
return false;
}
}

@ -10,15 +10,20 @@ class MdlAdmin extends MdlBase{
$this->gw = new AdminGateway($this->con);
}
public function login(string $username, string $password): bool{
return $this->gw->login($username, $password);
if ($this->gw->login($username, $password)) {
$_SESSION['pseudo'] = $username;
$_SESSION['admin'] = true;
return true;
}
return false;
}
public static function isAdmin(): bool
{
if(!isset($_SESSION['admin'])
|| !$_SESSION['admin']
|| !isset($_SESSION['email'])
|| $_SESSION['email'] == null) {
|| !isset($_SESSION['pseudo'])
|| $_SESSION['pseudo'] == null) {
return false;
}

@ -7,7 +7,7 @@ class MdlUser extends MdlBase{
public function __construct(){
parent::__construct();
$this->gw = new JoueurGateway($this->con);
$this->gw = new UtilisateurConnecteGateway($this->con);
}
public function login(string $username, string $password): bool{
return $this->gw->login($username, $password);

Loading…
Cancel
Save