1.增加谷歌验证器
This commit is contained in:
@@ -8,6 +8,8 @@ use Throwable;
|
||||
use support\think\Db;
|
||||
use support\validation\Validator;
|
||||
use support\validation\ValidationException;
|
||||
use app\common\facade\Token;
|
||||
use app\admin\model\AdminLog;
|
||||
use app\common\controller\Backend;
|
||||
use app\admin\model\Admin as AdminModel;
|
||||
use support\Response;
|
||||
@@ -17,7 +19,7 @@ class Admin extends Backend
|
||||
{
|
||||
protected ?object $model = null;
|
||||
|
||||
protected array|string $preExcludeFields = ['create_time', 'update_time', 'password', 'salt', 'login_failure', 'last_login_time', 'last_login_ip', 'channel_id'];
|
||||
protected array|string $preExcludeFields = ['create_time', 'update_time', 'password', 'salt', 'login_failure', 'last_login_time', 'last_login_ip', 'channel_id', 'totp_secret', 'totp_bind_time'];
|
||||
|
||||
protected array|string $quickSearchField = ['username', 'nickname'];
|
||||
|
||||
@@ -224,6 +226,50 @@ class Admin extends Backend
|
||||
]);
|
||||
}
|
||||
|
||||
public function resetTotp(Request $request): Response
|
||||
{
|
||||
$response = $this->initializeBackend($request);
|
||||
if ($response !== null) return $response;
|
||||
|
||||
if ($request->method() !== 'POST') {
|
||||
return $this->error(__('Method not allowed'), [], 0, ['statusCode' => 405]);
|
||||
}
|
||||
|
||||
if (!$this->auth->isSuperAdmin()) {
|
||||
return $this->error(__('You have no permission'));
|
||||
}
|
||||
|
||||
$id = (int) ($request->post('id') ?? 0);
|
||||
if ($id <= 0) {
|
||||
return $this->error(__('Parameter error'));
|
||||
}
|
||||
if ($id === $this->auth->id) {
|
||||
return $this->error(__('Cannot reset your own authenticator, please modify in database'));
|
||||
}
|
||||
|
||||
$row = $this->model->find($id);
|
||||
if (!$row) {
|
||||
return $this->error(__('Record not found'));
|
||||
}
|
||||
|
||||
$dataLimitAdminIds = $this->getDataLimitAdminIds();
|
||||
if ($dataLimitAdminIds && !in_array($row[$this->dataLimitField], $dataLimitAdminIds)) {
|
||||
return $this->error(__('You have no permission'));
|
||||
}
|
||||
|
||||
AdminLog::instance($request)->setTitle(__('Reset Google Authenticator'));
|
||||
|
||||
$row->save([
|
||||
'totp_secret' => '',
|
||||
'totp_bind_time' => null,
|
||||
]);
|
||||
|
||||
Token::clear(\app\admin\library\Auth::TOKEN_TYPE, $id);
|
||||
Token::clear(\app\admin\library\Auth::TOKEN_TYPE . '-refresh', $id);
|
||||
|
||||
return $this->success(__('Google Authenticator reset successfully'));
|
||||
}
|
||||
|
||||
public function del(Request $request): Response
|
||||
{
|
||||
$response = $this->initializeBackend($request);
|
||||
|
||||
Reference in New Issue
Block a user