From 5c1c7dce42f7ddc2f6cdec25e4868908e3ade617 Mon Sep 17 00:00:00 2001 From: grandeljay Date: Fri, 24 Nov 2023 16:06:51 +0100 Subject: [PATCH] chore: remove persistent cookie --- index.php | 29 ------------------- src/classes/wishthis/User.php | 54 ----------------------------------- 2 files changed, 83 deletions(-) diff --git a/index.php b/index.php index e2bcf022..2ecfd545 100644 --- a/index.php +++ b/index.php @@ -11,7 +11,6 @@ namespace wishthis; define('VERSION', '1.1.1'); define('ROOT', __DIR__); define('DEFAULT_LOCALE', 'en_GB'); -define('COOKIE_PERSISTENT', 'wishthis_persistent'); /** * Include @@ -83,34 +82,6 @@ if ( $options = new Options($database); } -/** - * Persistent (stay logged in) - */ -if (isset($_COOKIE[COOKIE_PERSISTENT]) && $database && !$user->isLoggedIn()) { - $sessions = $database - ->query( - 'SELECT * - FROM `sessions` - WHERE `session` = :session;', - array( - 'session' => $_COOKIE[COOKIE_PERSISTENT], - ) - ) - ->fetchAll(); - - if (false !== $sessions) { - foreach ($sessions as $session) { - $expires = strtotime($session['expires']); - - if (time() < $expires) { - $user = User::getFromID($session['user']); - - break; - } - } - } -} - /** * Language */ diff --git a/src/classes/wishthis/User.php b/src/classes/wishthis/User.php index c4790e7e..60298c53 100644 --- a/src/classes/wishthis/User.php +++ b/src/classes/wishthis/User.php @@ -386,68 +386,14 @@ class User $login_was_successful = true; } - /** - * Make the session persist - */ - if ($user_login_is_persistent) { - /** Cookie options */ - $sessionLifetime = 2592000 * 4; // 4 Months - $sessionExpires = time() + $sessionLifetime; - $sessionIsDev = defined('ENV_IS_DEV') && ENV_IS_DEV || '127.0.0.1' === $_SERVER['REMOTE_ADDR']; - $sessionOptions = array( - 'domain' => getCookieDomain(), - 'expires' => $sessionExpires, - 'httponly' => true, - 'path' => '/', - 'samesite' => 'None', - 'secure' => !$sessionIsDev, - ); - - /** Set cookie */ - setcookie(COOKIE_PERSISTENT, session_id(), $sessionOptions); - - $database->query( - 'INSERT INTO `sessions` ( - `user`, - `session`, - `expires` - ) VALUES ( - :user_id, - :session_id, - :session_expires - );', - array( - 'user_id' => $this->id, - 'session_id' => session_id(), - 'session_expires' => date('Y-m-d H:i:s', $sessionExpires), - ) - ); - } - return $login_was_successful; } public function logOut(): void { /** Destroy session */ - if (isset($_COOKIE[COOKIE_PERSISTENT])) { - global $database; - - $database - ->query( - 'DELETE FROM `sessions` - WHERE `session` = :session;', - array( - 'session' => $_COOKIE[COOKIE_PERSISTENT], - ) - ); - } - session_destroy(); unset($_SESSION); - - /** Delete cookie */ - setcookie(COOKIE_PERSISTENT, '', time() - 3600, '/', getCookieDomain()); } public function delete(): void