在环境文件中增加谷歌验证器开关

This commit is contained in:
2026-07-21 15:15:11 +08:00
parent e40de47b8b
commit a0056ff15b
11 changed files with 51 additions and 2 deletions

View File

@@ -51,6 +51,7 @@ class Index extends Backend
'upload' => keys_to_camel_case(get_upload_config($request), ['max_size', 'save_name', 'allowed_suffixes', 'allowed_mime_types', 'forbidden_suffixes']),
'cdnUrl' => full_url(),
'cdnUrlParams' => config('buildadmin.cdn_url_params'),
'totpEnable' => AdminTotp::isEnabled(),
],
]);
}
@@ -109,6 +110,13 @@ class Index extends Backend
return $this->error($msg ?: __('Incorrect user name or password!'));
}
if (!AdminTotp::isEnabled()) {
if (!$this->auth->finalizeLogin((bool) $keep)) {
return $this->error($this->auth->getError() ?: __('Login failed'));
}
return $this->buildLoginSuccessResponse((bool) $keep);
}
if ($this->auth->hasTotpBound()) {
$tempToken = AdminTotp::createPendingToken($this->auth->id, AdminTotp::TOKEN_TYPE_VERIFY);
return $this->success(__('Please enter Google Authenticator code'), [
@@ -127,7 +135,8 @@ class Index extends Backend
}
return $this->success('', [
'captcha' => $captchaSwitch
'captcha' => $captchaSwitch,
'totpEnable' => AdminTotp::isEnabled(),
]);
}
@@ -136,6 +145,10 @@ class Index extends Backend
$response = $this->initializeBackend($request);
if ($response !== null) return $response;
if (!AdminTotp::isEnabled()) {
return $this->error(__('Google Authenticator is disabled'));
}
if ($request->method() !== 'POST') {
return $this->error(__('Method not allowed'), [], 0, ['statusCode' => 405]);
}
@@ -169,6 +182,10 @@ class Index extends Backend
$response = $this->initializeBackend($request);
if ($response !== null) return $response;
if (!AdminTotp::isEnabled()) {
return $this->error(__('Google Authenticator is disabled'));
}
if ($request->method() !== 'POST') {
return $this->error(__('Method not allowed'), [], 0, ['statusCode' => 405]);
}
@@ -223,6 +240,10 @@ class Index extends Backend
$response = $this->initializeBackend($request);
if ($response !== null) return $response;
if (!AdminTotp::isEnabled()) {
return $this->error(__('Google Authenticator is disabled'));
}
if ($request->method() !== 'POST') {
return $this->error(__('Method not allowed'), [], 0, ['statusCode' => 405]);
}

View File

@@ -231,6 +231,10 @@ class Admin extends Backend
$response = $this->initializeBackend($request);
if ($response !== null) return $response;
if (!\app\common\library\AdminTotp::isEnabled()) {
return $this->error(__('Google Authenticator is disabled'));
}
if ($request->method() !== 'POST') {
return $this->error(__('Method not allowed'), [], 0, ['statusCode' => 405]);
}

View File

@@ -120,6 +120,7 @@ return [
'Google Authenticator not bound' => 'Google Authenticator not bound',
'Reset Google Authenticator' => 'Reset Google Authenticator',
'Google Authenticator reset successfully' => 'Google Authenticator reset. The admin must re-bind on next login',
'Google Authenticator is disabled' => 'Google Authenticator is disabled',
'Cannot reset your own authenticator, please modify in database' => 'Cannot reset your own authenticator. Super admin recovery requires database change',
'Login failed' => 'Login failed',
];

View File

@@ -139,6 +139,7 @@ return [
'Google Authenticator not bound' => '谷歌验证器未绑定',
'Reset Google Authenticator' => '重置谷歌验证器',
'Google Authenticator reset successfully' => '谷歌验证器已重置,该管理员下次登录需重新绑定',
'Google Authenticator is disabled' => '谷歌验证器功能已关闭',
'Cannot reset your own authenticator, please modify in database' => '不能重置自己的验证器,超管丢失验证器请在数据库中修改',
'Login failed' => '登录失败',
];