diff --git a/controllers/user_controller.php b/controllers/user_controller.php index 5bcf302..7df04e2 100644 --- a/controllers/user_controller.php +++ b/controllers/user_controller.php @@ -42,7 +42,7 @@ class UserCtrl extends MotherCtrl { $token_hash = hash('sha256', $token); $objUserModel->remember($_SESSION['user']['user_id'],$token_hash); - setcookie('remember_me', $token, time() + (24*60*60), "/", "", false, true); + setcookie('remember_me', $token, time() + (15*24*60*60), "/", "", true, true); } header("Location:index.php"); diff --git a/models/user_model.php b/models/user_model.php index 752ce19..9c6c7ce 100644 --- a/models/user_model.php +++ b/models/user_model.php @@ -76,19 +76,20 @@ $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)) + //pour faire que le cookies soit valable 15 jours + date('Y-m-d H:i:s', time() + (15*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]); + $strRq = $this->_db->prepare("SELECT token_user_id FROM tokens WHERE token_hash = :hash AND token_expire_at > NOW()"); + $strRq->execute(['hash' => $hash]); + return $strRq->fetch(); } public function deleteToken(string $hash){ - $stmt = $this->_db->prepare("DELETE FROM tokens WHERE token_hash = :hash"); - $stmt->execute(['hash' => $hash]); + $strRq = $this->_db->prepare("DELETE FROM tokens WHERE token_hash = :hash"); + return $strRq->execute(['hash' => $hash]); } public function update(object $objUser):bool{