Skip to content

Commit d3b6b93

Browse files
feat: Update login attempts retrieval to use user data if available
1 parent 6c7a639 commit d3b6b93

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

app/Http/Controllers/UserController.php

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

414-
$login_attempts = intval(Request::input('login_attempts'));
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+
}
420+
415421
// Build the validation constraint set.
416422
$rules = [
417423
'username' => 'required|email',

resources/js/login/login.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ const PasswordInputForm = ({
183183
<input type="hidden" value={userNameValue} id="username" name="username"/>
184184
<input type="hidden" value={csrfToken} id="_token" name="_token"/>
185185
<input type="hidden" value="password" id="flow" name="flow"/>
186+
<input type="hidden" value={loginAttempts ?? 0} name="login_attempts"/>
186187
{shouldShowCaptcha() && captchaPublicKey &&
187188
<Turnstile
188189
className={styles.turnstile}
@@ -214,7 +215,8 @@ const OTPInputForm = ({
214215
shouldShowCaptcha,
215216
captchaPublicKey,
216217
onChangeCaptchaProvider,
217-
onReset
218+
onReset,
219+
loginAttempts
218220
}) => {
219221
return (
220222
<>
@@ -263,6 +265,7 @@ const OTPInputForm = ({
263265
<input type="hidden" value="otp" id="flow" name="flow"/>
264266
<input type="hidden" value={otpCode} id="password" name="password"/>
265267
<input type="hidden" value="email" id="connection" name="connection"/>
268+
<input type="hidden" value={loginAttempts ?? 0} name="login_attempts"/>
266269
{shouldShowCaptcha() && captchaPublicKey &&
267270
<Turnstile
268271
className={styles.turnstile}
@@ -725,6 +728,15 @@ class LoginPage extends React.Component {
725728
});
726729
};
727730

731+
componentDidUpdate(prevProps, prevState) {
732+
if (this.state.user_verified && this.existingUserCanContinue() && prevState.authFlow !== this.state.authFlow) {
733+
this.setState({
734+
...this.state,
735+
captcha_value: '',
736+
});
737+
}
738+
}
739+
728740
render() {
729741
return (
730742
<Container component="main" maxWidth="xs" className={styles.main_container}>
@@ -861,6 +873,7 @@ class LoginPage extends React.Component {
861873
captchaPublicKey={this.props.captchaPublicKey}
862874
onChangeCaptchaProvider={this.onChangeCaptchaProvider}
863875
onReset={this.handleDelete}
876+
loginAttempts={this.props?.loginAttempts}
864877
/>
865878
<OTPHelpLinks emitOtpAction={this.handleEmitOtpAction}/>
866879
</>

0 commit comments

Comments
 (0)