chore: remove persistent cookie

This commit is contained in:
grandeljay 2023-11-24 16:06:51 +01:00
parent aae51fa752
commit 5c1c7dce42
2 changed files with 0 additions and 83 deletions

View file

@ -11,7 +11,6 @@ namespace wishthis;
define('VERSION', '1.1.1'); define('VERSION', '1.1.1');
define('ROOT', __DIR__); define('ROOT', __DIR__);
define('DEFAULT_LOCALE', 'en_GB'); define('DEFAULT_LOCALE', 'en_GB');
define('COOKIE_PERSISTENT', 'wishthis_persistent');
/** /**
* Include * Include
@ -83,34 +82,6 @@ if (
$options = new Options($database); $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 * Language
*/ */

View file

@ -386,68 +386,14 @@ class User
$login_was_successful = true; $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; return $login_was_successful;
} }
public function logOut(): void public function logOut(): void
{ {
/** Destroy session */ /** Destroy session */
if (isset($_COOKIE[COOKIE_PERSISTENT])) {
global $database;
$database
->query(
'DELETE FROM `sessions`
WHERE `session` = :session;',
array(
'session' => $_COOKIE[COOKIE_PERSISTENT],
)
);
}
session_destroy(); session_destroy();
unset($_SESSION); unset($_SESSION);
/** Delete cookie */
setcookie(COOKIE_PERSISTENT, '', time() - 3600, '/', getCookieDomain());
} }
public function delete(): void public function delete(): void