Skip to content

Commit 1865afa

Browse files
committed
Add missing captcha to login/register
Add password rules to login request
1 parent 5249714 commit 1865afa

File tree

6 files changed

+47
-1
lines changed

6 files changed

+47
-1
lines changed

app/Domains/Auth/Http/Controllers/Frontend/Auth/LoginController.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Foundation\Auth\AuthenticatesUsers;
99
use Illuminate\Http\Exceptions\HttpResponseException;
1010
use Illuminate\Http\Request;
11+
use LangleyFoxall\LaravelNISTPasswordRules\PasswordRules;
1112

1213
/**
1314
* Class LoginController.
@@ -54,6 +55,25 @@ public function showLoginForm()
5455
return view('frontend.auth.login');
5556
}
5657

58+
/**
59+
* Validate the user login request.
60+
*
61+
* @param \Illuminate\Http\Request $request
62+
* @return void
63+
*
64+
* @throws \Illuminate\Validation\ValidationException
65+
*/
66+
protected function validateLogin(Request $request)
67+
{
68+
$request->validate([
69+
$this->username() => 'required|string',
70+
'password' => PasswordRules::login(),
71+
'g-recaptcha-response' => ['required_if:captcha_status,true', 'captcha'],
72+
], [
73+
'g-recaptcha-response.required_if' => __('validation.required', ['attribute' => 'captcha']),
74+
]);
75+
}
76+
5777
/**
5878
* Overidden for 2FA
5979
* https://github.com/DarkGhostHunter/Laraguard#protecting-the-login.

app/Domains/Auth/Http/Controllers/Frontend/Auth/RegisterController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ protected function validator(array $data)
7676
'name' => ['required', 'string', 'max:255'],
7777
'email' => ['required', 'string', 'email', 'max:255', Rule::unique('users')],
7878
'password' => PasswordRules::register($data['email'] ?? null),
79+
'g-recaptcha-response' => ['required_if:captcha_status,true', 'captcha'],
80+
], [
81+
'g-recaptcha-response.required_if' => __('validation.required', ['attribute' => 'captcha']),
7982
]);
8083
}
8184

config/boilerplate.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
| Configurations related to the boilerplate's access/authorization options
1515
*/
1616
'access' => [
17+
'captcha' => [
18+
'registration' => env('REGISTRATION_CAPTCHA_STATUS', false),
19+
'login' => env('LOGIN_CAPTCHA_STATUS', false),
20+
],
21+
1722
'middleware' => [
1823
'confirm' => 'password.confirm:frontend.auth.password.confirm',
1924
'verified' => 'verified:frontend.auth.verification.notice',

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
<server name="DB_DATABASE" value=":memory:"/>
3636
<server name="ENABLE_REGISTRATION" value="true"/>
3737
<server name="LOGIN_CAPTCHA_STATUS" value="false"/>
38+
<server name="REGISTRATION_CAPTCHA_STATUS" value="false"/>
3839
<server name="MAIL_MAILER" value="array"/>
3940
<server name="QUEUE_CONNECTION" value="sync"/>
40-
<server name="REGISTRATION_CAPTCHA_STATUS" value="false"/>
4141
<server name="SESSION_DRIVER" value="array"/>
4242
<server name="TELESCOPE_ENABLED" value="false"/>
4343
</php>

resources/views/frontend/auth/login.blade.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@
4040
</div>
4141
</div><!--form-group-->
4242

43+
@if(config('boilerplate.access.captcha.login'))
44+
<div class="row">
45+
<div class="col">
46+
@captcha
47+
<input type="hidden" name="captcha_status" value="true" />
48+
</div><!--col-->
49+
</div><!--row-->
50+
@endif
51+
4352
<div class="form-group row mb-0">
4453
<div class="col-md-8 offset-md-4">
4554
<button class="btn btn-primary" type="submit">@lang('Login')</button>

resources/views/frontend/auth/register.blade.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@
4444
</div>
4545
</div><!--form-group-->
4646

47+
@if(config('boilerplate.access.captcha.registration'))
48+
<div class="row">
49+
<div class="col">
50+
@captcha
51+
<input type="hidden" name="captcha_status" value="true" />
52+
</div><!--col-->
53+
</div><!--row-->
54+
@endif
55+
4756
<div class="form-group row mb-0">
4857
<div class="col-md-6 offset-md-4">
4958
<button class="btn btn-primary" type="submit">@lang('Register')</button>

0 commit comments

Comments
 (0)