feat(auth): lock admin login per account as well as per IP

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
baodev0
2026-10-22 22:40:44 +07:00
co-authored by Claude Opus 5.5
parent 7f41c27958
commit fc765ad007
5 changed files with 138 additions and 34 deletions
@@ -21,7 +21,9 @@ class AdminLoginBlockController extends Controller
->get()
->map(fn (AdminLoginBlock $block) => [
'id' => $block->id,
'ip' => $block->ip,
'kind' => $block->kind,
'identifier' => $block->identifier,
'last_ip' => $block->last_ip,
'failed_attempts' => $block->failed_attempts,
'last_username' => $block->last_username,
'user_agent' => $block->user_agent,
@@ -47,9 +49,14 @@ class AdminLoginBlockController extends Controller
$this->activityLogger->log(
event: 'login_unblocked',
logName: 'auth',
description: sprintf('[admin] %s gỡ chặn đăng nhập cho IP %s (tài khoản thử gần nhất: %s)', $request->user('admin')?->username, $block->ip, $block->last_username ?? '—'),
description: sprintf('[admin] %s gỡ khoá đăng nhập %s %s', $request->user('admin')?->username, $this->label($block), $block->identifier),
);
return response()->json(['error' => false, 'message' => 'Đã gỡ chặn IP ' . $block->ip]);
return response()->json(['error' => false, 'message' => sprintf('Đã gỡ khoá %s %s', $this->label($block), $block->identifier)]);
}
private function label(AdminLoginBlock $block): string
{
return $block->kind === AdminLoginLockout::KIND_ACCOUNT ? 'tài khoản' : 'IP';
}
}