mirror of
https://github.com/renbaoshuo/S2OJ.git
synced 2024-11-25 12:18:41 +00:00
feat: refresh session after logout
This commit is contained in:
parent
886fb1a2fa
commit
78d8418c27
@ -2,10 +2,10 @@ Options -Indexes
|
|||||||
|
|
||||||
php_value session.save_path /var/lib/php/uoj_sessions
|
php_value session.save_path /var/lib/php/uoj_sessions
|
||||||
php_value session.gc_maxlifetime 172800
|
php_value session.gc_maxlifetime 172800
|
||||||
php_value session.cookie_lifetime 31536000
|
php_value session.cookie_lifetime 604800
|
||||||
|
|
||||||
php_value post_max_size 1000M
|
php_value post_max_size 1024M
|
||||||
php_value upload_max_filesize 1000M
|
php_value upload_max_filesize 1024M
|
||||||
|
|
||||||
php_value session.gc_probability 1
|
php_value session.gc_probability 1
|
||||||
php_value session.gc_divisor 1000
|
php_value session.gc_divisor 1000
|
||||||
|
@ -42,7 +42,7 @@ function handleLoginPost() {
|
|||||||
return 'account:' . $account_status;
|
return 'account:' . $account_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
Auth::login($user['username']);
|
Auth::login($user['username'], false);
|
||||||
return "ok";
|
return "ok";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,13 +16,13 @@ class Auth {
|
|||||||
global $myUser;
|
global $myUser;
|
||||||
return $myUser;
|
return $myUser;
|
||||||
}
|
}
|
||||||
public static function property($name) {
|
public static function property($name) {
|
||||||
global $myUser;
|
global $myUser;
|
||||||
if (!$myUser) {
|
if (!$myUser) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return $myUser[$name];
|
return $myUser[$name];
|
||||||
}
|
}
|
||||||
public static function login($username, $remember = true) {
|
public static function login($username, $remember = true) {
|
||||||
if (!validateUsername($username)) {
|
if (!validateUsername($username)) {
|
||||||
return;
|
return;
|
||||||
@ -30,16 +30,17 @@ class Auth {
|
|||||||
$_SESSION['username'] = $username;
|
$_SESSION['username'] = $username;
|
||||||
if ($remember) {
|
if ($remember) {
|
||||||
$remember_token = DB::selectSingle([
|
$remember_token = DB::selectSingle([
|
||||||
"select remember_token from user_info",
|
"select remember_token from user_info",
|
||||||
"where", ["username" => $username]
|
"where", ["username" => $username]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($remember_token == '') {
|
if ($remember_token == '') {
|
||||||
$remember_token = uojRandString(60);
|
$remember_token = uojRandString(60);
|
||||||
DB::update([
|
DB::update([
|
||||||
"update user_info",
|
"update user_info",
|
||||||
"set", ["remember_token" => $remember_token],
|
"set", ["remember_token" => $remember_token],
|
||||||
"where", ["username" => $username]
|
"where", ["username" => $username]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$_SESSION['last_login'] = time();
|
$_SESSION['last_login'] = time();
|
||||||
@ -54,26 +55,26 @@ class Auth {
|
|||||||
"where", ["username" => $username]
|
"where", ["username" => $username]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function logout() {
|
public static function logout() {
|
||||||
unset($_SESSION['username']);
|
session_unset();
|
||||||
unset($_SESSION['last_login']);
|
Cookie::safeUnset(session_name(), '/');
|
||||||
unset($_SESSION['last_visited']);
|
|
||||||
Cookie::safeUnset('uoj_username', '/');
|
Cookie::safeUnset('uoj_username', '/');
|
||||||
Cookie::safeUnset('uoj_remember_token', '/');
|
Cookie::safeUnset('uoj_remember_token', '/');
|
||||||
DB::update([
|
DB::update([
|
||||||
"update user_info",
|
"update user_info",
|
||||||
"set", ["remember_token" => ''],
|
"set", ["remember_token" => ''],
|
||||||
"where", ["username" => Auth::id()]
|
"where", ["username" => Auth::id()]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function initMyUser() {
|
private static function initMyUser() {
|
||||||
global $myUser;
|
global $myUser;
|
||||||
$myUser = null;
|
$myUser = null;
|
||||||
|
|
||||||
Cookie::safeCheck('uoj_username', '/');
|
Cookie::safeCheck('uoj_username', '/');
|
||||||
Cookie::safeCheck('uoj_remember_token', '/');
|
Cookie::safeCheck('uoj_remember_token', '/');
|
||||||
|
|
||||||
if (isset($_SESSION['username'])) {
|
if (isset($_SESSION['username'])) {
|
||||||
if (!validateUsername($_SESSION['username'])) {
|
if (!validateUsername($_SESSION['username'])) {
|
||||||
return;
|
return;
|
||||||
@ -97,7 +98,7 @@ class Auth {
|
|||||||
}
|
}
|
||||||
public static function init() {
|
public static function init() {
|
||||||
global $myUser;
|
global $myUser;
|
||||||
|
|
||||||
Auth::initMyUser();
|
Auth::initMyUser();
|
||||||
if ($myUser && UOJUser::getAccountStatus($myUser) != 'ok') {
|
if ($myUser && UOJUser::getAccountStatus($myUser) != 'ok') {
|
||||||
$myUser = null;
|
$myUser = null;
|
||||||
@ -108,9 +109,9 @@ class Auth {
|
|||||||
}
|
}
|
||||||
$myUser = UOJUser::updateVisitHistory($myUser, [
|
$myUser = UOJUser::updateVisitHistory($myUser, [
|
||||||
'remote_addr' => UOJContext::remoteAddr(),
|
'remote_addr' => UOJContext::remoteAddr(),
|
||||||
'http_x_forwarded_for' => UOJContext::httpXForwardedFor(),
|
'http_x_forwarded_for' => UOJContext::httpXForwardedFor(),
|
||||||
'http_user_agent' => UOJContext::httpUserAgent()
|
'http_user_agent' => UOJContext::httpUserAgent()
|
||||||
]);
|
]);
|
||||||
$_SESSION['last_visited'] = time();
|
$_SESSION['last_visited'] = time();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user