feature: 登录校验

This commit is contained in:
zhuyu 2025-06-04 14:19:36 +08:00
parent 318ced06a7
commit 6b2ef44d68

View File

@ -47,6 +47,13 @@ class Auth extends \fast\Auth
$this->setError('Admin is forbidden');
return false;
}
//ip白名单校验
if (!$this->allowIpCheck($admin)) {
$this->setError('登录失败您的IP地址不在公司允许范围内');
return false;
}
if (Config::get('fastadmin.login_failure_retry') && $admin->loginfailure >= 10 && time() - $admin->updatetime < 86400) {
$this->setError('Please try again after 1 day');
return false;
@ -68,6 +75,29 @@ class Auth extends \fast\Auth
return true;
}
public function allowIpCheck($admin){
if (in_array('*', $this->getRuleIds($admin->id))) {
return true;
}
$allowIpCheck = Config::get('site.allowip_check');
if ($allowIpCheck != 1) {
return true;
}
$allowIp = Config::get('site.allowip');
$allowIp = explode("\r\n", $allowIp);
if (empty($allowIp)) {
return false;
}
$ip = request()->ip();
if (!in_array($ip, $allowIp)) {
return false;
}
return true;
}
/**
* 退出登录
*/