refactor(auth): simplify password reset attempt handling logic and improve code readability
This commit is contained in:
@@ -236,8 +236,7 @@ class PasswordLoginService
|
||||
CarbonImmutable $now,
|
||||
string $tenantCode,
|
||||
string $passwordResetChannel,
|
||||
): void
|
||||
{
|
||||
): void {
|
||||
$windowMinutes = max(1, (int) config('login-security.attempt_window_minutes'));
|
||||
$maxAttempts = max(1, (int) config('login-security.max_attempts'));
|
||||
$lockMinutes = max(1, (int) config('login-security.lock_minutes'));
|
||||
@@ -260,23 +259,23 @@ class PasswordLoginService
|
||||
|
||||
if ($attempts >= $maxAttempts && $previousAttempts < $maxAttempts) {
|
||||
try {
|
||||
match ($passwordResetChannel) {
|
||||
PasswordResetRequested::CHANNEL_ADMINAPP =>
|
||||
$this->resetPasswordAttemptService->createForAdminAppEmail(
|
||||
$user->email,
|
||||
ResetPasswordAttempt::REASON_ACCOUNT_LOCKED,
|
||||
),
|
||||
PasswordResetRequested::CHANNEL_SCANNER =>
|
||||
$this->resetPasswordAttemptService->createForScannerEmail(
|
||||
$user->email,
|
||||
ResetPasswordAttempt::REASON_ACCOUNT_LOCKED,
|
||||
),
|
||||
default => $this->resetPasswordAttemptService->createForEmail(
|
||||
if ($passwordResetChannel === PasswordResetRequested::CHANNEL_ADMINAPP) {
|
||||
$this->resetPasswordAttemptService->createForAdminAppEmail(
|
||||
$user->email,
|
||||
ResetPasswordAttempt::REASON_ACCOUNT_LOCKED,
|
||||
);
|
||||
} elseif ($passwordResetChannel === PasswordResetRequested::CHANNEL_SCANNER) {
|
||||
$this->resetPasswordAttemptService->createForScannerEmail(
|
||||
$user->email,
|
||||
ResetPasswordAttempt::REASON_ACCOUNT_LOCKED,
|
||||
);
|
||||
} else {
|
||||
$this->resetPasswordAttemptService->createForEmail(
|
||||
$user->email,
|
||||
$tenantCode,
|
||||
ResetPasswordAttempt::REASON_ACCOUNT_LOCKED,
|
||||
),
|
||||
};
|
||||
);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Failed to trigger reset password on account lock', [
|
||||
'user_id' => $user->id,
|
||||
|
||||
Reference in New Issue
Block a user