You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ScienceQuest/project/src/model/gateways/UtilisateurConnecteGateway.php

35 lines
1.0 KiB

<?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;
}
public function register(string $email, string $password, int $idjoueur): bool
{
$sql = "INSERT INTO Utilisateur(email, password,idjoueur) VALUES (:email,:password,:idjoueur);";
return $this->con->executeQuery($sql, [
':email' => array($email, \PDO::PARAM_STR),
':password' => array(password_hash($password, PASSWORD_BCRYPT), \PDO::PARAM_STR),
':idjoueur' => array($idjoueur, \PDO::PARAM_INT)
]
);
}
}