Skip to content

Commit ec57955

Browse files
chore: rollback checking the login_attempts from the server
1 parent 7d73f50 commit ec57955

2 files changed

Lines changed: 16 additions & 30 deletions

File tree

app/Http/Controllers/UserController.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -411,13 +411,8 @@ public function postLogin()
411411
if (isset($data['password']))
412412
$data['password'] = trim($data['password']);
413413

414-
if (isset($data['username'])) {
415-
$user = $this->auth_service->getUserByUsername($data['username']);
416-
if (!is_null($user)) {
417-
$login_attempts = $user->getLoginFailedAttempt();
418-
}
419-
}
420414

415+
$login_attempts = intval(Request::input('login_attempts'));
421416
// Build the validation constraint set.
422417
$rules = [
423418
'username' => 'required|email',

tests/UserLoginTurnstileTest.php

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ public function testMissingTurnstileResponseFailsValidationWhenAtThreshold(): vo
106106
$user = $this->getTestUser();
107107
$this->setLoginAttempts($user, self::CAPTCHA_THRESHOLD);
108108

109-
$this->postLogin(); // no cf-turnstile-response
109+
$this->postLogin([
110+
"login_attempts" => self::CAPTCHA_THRESHOLD,
111+
]); // no cf-turnstile-response
110112

111113
$this->assertTrue(
112114
$this->sessionHasValidationError('cf-turnstile-response'),
@@ -138,34 +140,17 @@ public function testLoginAtThresholdWithValidTokenPassesValidation(): void
138140

139141
$this->fakeTurnstilePass();
140142

141-
$this->postLogin(['cf-turnstile-response' => 'dummy-token-accepted-by-mock']);
143+
$this->postLogin([
144+
'cf-turnstile-response' => 'dummy-token-accepted-by-mock',
145+
'login_attempts' => 1
146+
]);
142147

143148
$this->assertFalse(
144149
$this->sessionHasValidationError('cf-turnstile-response'),
145150
'A valid Turnstile token must clear the captcha validation rule'
146151
);
147152
}
148153

149-
// -------------------------------------------------------------------------
150-
// 3. Server-side login-attempt lookup: user exists vs. does not exist
151-
// -------------------------------------------------------------------------
152-
153-
public function testLoginAttemptsLoadedFromExistingUserRecord(): void
154-
{
155-
$user = $this->getTestUser();
156-
$this->setLoginAttempts($user, self::CAPTCHA_THRESHOLD);
157-
158-
// Omit cf-turnstile-response. If the controller had NOT read the DB value it
159-
// would see login_attempts = 0 and skip the captcha rule. The error proves
160-
// the persisted attempt count was used.
161-
$this->postLogin();
162-
163-
$this->assertTrue(
164-
$this->sessionHasValidationError('cf-turnstile-response'),
165-
'Expected captcha required error, which proves login_failed_attempt was read from DB'
166-
);
167-
}
168-
169154
public function testLoginAttemptsDefaultToZeroForUnknownUsername(): void
170155
{
171156
// No user with this email → auth_service->getUserByUsername() returns null
@@ -216,7 +201,10 @@ public function testExpiredTurnstileTokenFailsValidation(): void
216201
// Cloudflare API returns success=false (expired / already-used token)
217202
$this->fakeTurnstileFail();
218203

219-
$this->postLogin(['cf-turnstile-response' => 'expired-or-invalid-token']);
204+
$this->postLogin([
205+
'cf-turnstile-response' => 'expired-or-invalid-token',
206+
'login_attempts' => self::CAPTCHA_THRESHOLD
207+
]);
220208

221209
$this->assertTrue(
222210
$this->sessionHasValidationError('cf-turnstile-response'),
@@ -230,7 +218,10 @@ public function testUnsolvedCaptchaEmptyTokenFailsValidation(): void
230218
$this->setLoginAttempts($user, self::CAPTCHA_THRESHOLD);
231219

232220
// Empty string triggers the 'required' rule before any Cloudflare call
233-
$this->postLogin(['cf-turnstile-response' => '']);
221+
$this->postLogin([
222+
'cf-turnstile-response' => '',
223+
'login_attempts' => self::CAPTCHA_THRESHOLD
224+
]);
234225

235226
$this->assertTrue(
236227
$this->sessionHasValidationError('cf-turnstile-response'),

0 commit comments

Comments
 (0)