webman迁移-优化

This commit is contained in:
2026-03-18 15:10:40 +08:00
parent ea77c7b3a1
commit e2ae55319e
70 changed files with 1278 additions and 137 deletions

View File

@@ -47,7 +47,8 @@ class Auth extends \ba\Auth
public static function instance(array $options = []): Auth
{
$request = function_exists('request') ? request() : null;
$request = $options['request'] ?? (function_exists('request') ? request() : null);
unset($options['request']);
if ($request && !isset($request->userAuth)) {
$request->userAuth = new static($options);
}
@@ -158,7 +159,8 @@ class Auth extends \ba\Auth
$userLoginRetry = config('buildadmin.user_login_retry');
if ($userLoginRetry && $this->model->last_login_time) {
if ($this->model->login_failure > 0 && time() - strtotime($this->model->last_login_time) >= 86400) {
$lastLoginTs = is_numeric($this->model->last_login_time) ? (int)$this->model->last_login_time : strtotime($this->model->last_login_time);
if ($this->model->login_failure > 0 && $lastLoginTs > 0 && time() - $lastLoginTs >= 86400) {
$this->model->login_failure = 0;
$this->model->save();
$this->model = User::where($accountType, $username)->find();
@@ -181,8 +183,7 @@ class Auth extends \ba\Auth
}
if ($keep) $this->setRefreshToken($this->refreshTokenKeepTime);
$this->loginSuccessful();
return true;
return $this->loginSuccessful();
}
public function direct(int $userId): bool
@@ -201,21 +202,24 @@ class Auth extends \ba\Auth
if (!$this->model) return false;
$request = function_exists('request') ? request() : null;
$ip = $request ? $request->getRealIp() : '0.0.0.0';
if (!$this->token) {
$this->token = Random::uuid();
Token::set($this->token, self::TOKEN_TYPE, $this->model->id, $this->keepTime);
}
$this->model->startTrans();
try {
$this->model->login_failure = 0;
$this->model->last_login_time = date('Y-m-d H:i:s');
$this->model->last_login_time = time();
$this->model->last_login_ip = $ip;
$this->model->save();
$this->loginEd = true;
if (!$this->token) {
$this->token = Random::uuid();
Token::set($this->token, self::TOKEN_TYPE, $this->model->id, $this->keepTime);
}
$this->model->commit();
} catch (Throwable $e) {
$this->model->rollback();
if ($this->token) {
Token::delete($this->token);
$this->token = '';
}
$this->setError($e->getMessage());
return false;
}
@@ -230,7 +234,7 @@ class Auth extends \ba\Auth
$this->model->startTrans();
try {
$this->model->login_failure++;
$this->model->last_login_time = date('Y-m-d H:i:s');
$this->model->last_login_time = time();
$this->model->last_login_ip = $ip;
$this->model->save();
$this->model->commit();