mirror of
https://github.com/renbaoshuo/S2OJ.git
synced 2024-11-22 08:58:42 +00:00
feat(login): not sending email if device is in history
This commit is contained in:
parent
ebeed712bf
commit
a6e0a20cf2
@ -41,11 +41,21 @@ function handleLoginPost() {
|
|||||||
return 'account:' . $account_status;
|
return 'account:' . $account_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Login
|
||||||
Auth::login($user['username']);
|
Auth::login($user['username']);
|
||||||
|
|
||||||
|
// Check visit history
|
||||||
$remote_addr = UOJContext::remoteAddr();
|
$remote_addr = UOJContext::remoteAddr();
|
||||||
$http_x_forwarded_for = UOJContext::httpXForwardedFor();
|
$http_x_forwarded_for = UOJContext::httpXForwardedFor();
|
||||||
$user_agent = UOJContext::httpUserAgent();
|
$user_agent = UOJContext::httpUserAgent();
|
||||||
|
$matched_history = UOJUser::getMatchedVisitHistory($user, [
|
||||||
|
'addr' => $remote_addr,
|
||||||
|
'forwarded_addr' => $http_x_forwarded_for,
|
||||||
|
'ua' => $user_agent,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// If not matched, send email
|
||||||
|
if ($matched_history == null) {
|
||||||
sendEmail($user['username'], '新登录', <<<EOD
|
sendEmail($user['username'], '新登录', <<<EOD
|
||||||
<p>您收到这封邮件是因为有人通过以下方式登录了您的帐户:</p>
|
<p>您收到这封邮件是因为有人通过以下方式登录了您的帐户:</p>
|
||||||
|
|
||||||
@ -57,6 +67,7 @@ function handleLoginPost() {
|
|||||||
|
|
||||||
<p>如果这是您进行的登录操作,请忽略此邮件。如果您没有进行过登录操作,请立即重置您账号的密码。</p>
|
<p>如果这是您进行的登录操作,请忽略此邮件。如果您没有进行过登录操作,请立即重置您账号的密码。</p>
|
||||||
EOD);
|
EOD);
|
||||||
|
}
|
||||||
|
|
||||||
return "ok";
|
return "ok";
|
||||||
}
|
}
|
||||||
|
@ -276,7 +276,7 @@ class UOJUser {
|
|||||||
], $user['username']);
|
], $user['username']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getUpdatedExtraVisitHistory($history, $cur) {
|
public static function getUpdatedExtraVisitHistory($history, $cur = null) {
|
||||||
$new_h = [];
|
$new_h = [];
|
||||||
$oldest = clone UOJTime::$time_now;
|
$oldest = clone UOJTime::$time_now;
|
||||||
$oldest->modify('-1 month');
|
$oldest->modify('-1 month');
|
||||||
@ -386,13 +386,30 @@ class UOJUser {
|
|||||||
return $cur;
|
return $cur;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getMatchedVisitHistory($user, $info) {
|
||||||
|
$extra = UOJUser::getExtra($user);
|
||||||
|
$new_h = UOJUser::getUpdatedExtraVisitHistory($extra['history']);
|
||||||
|
|
||||||
|
foreach ($new_h as $history) {
|
||||||
|
if (
|
||||||
|
$history['addr'] == $info['addr'] &&
|
||||||
|
$history['forwarded_addr'] == $info['forwarded_addr'] &&
|
||||||
|
$history['ua'] == substr($info['ua'], 0, UOJUser::MAX_UA_LEN)
|
||||||
|
) {
|
||||||
|
return $history;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static function updateVisitHistory($user, $info) {
|
public static function updateVisitHistory($user, $info) {
|
||||||
$extra = UOJUser::getExtra($user);
|
$extra = UOJUser::getExtra($user);
|
||||||
$cur = [
|
$cur = [
|
||||||
'addr' => $info['remote_addr'],
|
'addr' => $info['remote_addr'],
|
||||||
'forwarded_addr' => $info['http_x_forwarded_for'],
|
'forwarded_addr' => $info['http_x_forwarded_for'],
|
||||||
'ua' => substr($info['http_user_agent'], 0, UOJUser::MAX_UA_LEN),
|
'ua' => substr($info['http_user_agent'], 0, UOJUser::MAX_UA_LEN),
|
||||||
'last' => UOJTime::$time_now_str
|
'last' => UOJTime::$time_now_str,
|
||||||
];
|
];
|
||||||
|
|
||||||
$extra['history'] = UOJUser::getUpdatedExtraVisitHistory($extra['history'], $cur);
|
$extra['history'] = UOJUser::getUpdatedExtraVisitHistory($extra['history'], $cur);
|
||||||
|
Loading…
Reference in New Issue
Block a user