ce souvenir lors de la connexion

This commit is contained in:
Yasder5 2026-02-24 19:42:05 +01:00
parent 42a41e5359
commit 0c6088d4da
5 changed files with 61 additions and 6 deletions

View file

@ -70,6 +70,27 @@
return $rqPrep->execute();
}
public function remember(int $userId, string $token):bool{
$strRq = "INSERT INTO tokens (token_user_id, token_hash, token_created_at, token_expire_at) VALUES (:id, :token, NOW(), :exp)";
$rqPrep = $this->_db->prepare($strRq);
$rqPrep->bindValue(":id", $userId, PDO::PARAM_INT);
$rqPrep->bindValue(":token", $token, PDO::PARAM_STR);
$rqPrep->bindValue(":exp",
//pour faire que le cookies soit valable 1 jours
date('Y-m-d H:i:s', time() + (24*60*60))
, PDO::PARAM_STR);
return $rqPrep->execute();
}
public function getTokenUser(string $hash){
$strRq = $this->_db->prepare("SELECT token_user_id FROM tokens WHERE token_hash = :hash AND expires_at > NOW()");
return $strRq->execute(['hash' => $hash]);
}
public function deleteToken(string $hash){
$stmt = $this->_db->prepare("DELETE FROM tokens WHERE token_hash = :hash");
$stmt->execute(['hash' => $hash]);
}
public function update(object $objUser):bool{
$strRq = "UPDATE users SET
user_name = :name,