feat: tg/ws/security/
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Admin;
|
||||
use App\Models\SystemLog;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
@@ -43,6 +44,9 @@ class AdminUserController extends Controller
|
||||
'status' => (int) $a->status,
|
||||
'google_auth_open' => (int) $a->google_auth_open,
|
||||
'last_ip' => $a->last_ip,
|
||||
'login_attempts' => (int) $a->login_attempts,
|
||||
'locked_at' => optional($a->locked_at)->format('Y-m-d H:i:s'),
|
||||
'is_locked' => $a->isLocked(),
|
||||
'created_at' => optional($a->created_at)->format('Y-m-d H:i:s'),
|
||||
'updated_at' => optional($a->updated_at)->format('Y-m-d H:i:s'),
|
||||
'is_self' => $a->id === $selfId,
|
||||
@@ -121,6 +125,35 @@ class AdminUserController extends Controller
|
||||
return response()->json(['code' => 0, 'msg' => 'ok']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlock an admin account that was locked due to too many failed
|
||||
* password attempts. Only super admins can unlock.
|
||||
*/
|
||||
public function unlock(Admin $adminUser)
|
||||
{
|
||||
/** @var Admin $actor */
|
||||
$actor = auth('admin')->user();
|
||||
if (! $actor instanceof Admin || ! $actor->isSuper()) {
|
||||
return response()->json(['code' => 1, 'msg' => '需要超级管理员权限'], 403);
|
||||
}
|
||||
|
||||
if (! $adminUser->isLocked()) {
|
||||
return response()->json(['code' => 1, 'msg' => '该账号未被封禁']);
|
||||
}
|
||||
|
||||
$adminUser->clearLoginAttempts();
|
||||
|
||||
SystemLog::record(
|
||||
$actor,
|
||||
'admin',
|
||||
SystemLog::ACTION_ADMIN_UNLOCKED,
|
||||
'超级管理员「'.$actor->username.'」解除管理员「'.$adminUser->username.'」的封禁状态',
|
||||
request(),
|
||||
);
|
||||
|
||||
return response()->json(['code' => 0, 'msg' => '已解除封禁']);
|
||||
}
|
||||
|
||||
private function superCount(): int
|
||||
{
|
||||
return (int) Admin::query()->where('is_super', 1)->count();
|
||||
|
||||
Reference in New Issue
Block a user