Added the ability to enable captcha when logging in.

This commit is contained in:
2024-04-25 23:45:07 +05:00
parent e059f09e2f
commit 20ed4860da
10 changed files with 112 additions and 30 deletions

View File

@@ -6,6 +6,12 @@ APP_URL=http://localhost
APP_FORCE_HTTPS=false
APP_CAPTCHA=false
CAPTCHA_API_DOMAIN=http://your-domain-captcha-or-IP:8081
CAPTCHA_PRIVATE_TOKEN=
CAPTCHA_STATIC_PATH=http://your-domain-captcha-or-IP:8081/captcha
CAPTCHA_PUBLIC_TOKEN=
APP_DEMO_MODE=false
APP_DEMO_EMAIL=
APP_DEMO_PASSWORD=

View File

@@ -19,7 +19,9 @@ final class AuthController extends Controller
public function login(): View
{
return view('public/login');
return view('public/login', [
'captcha' => config('app.captcha', false)
]);
}
public function authorization(AuthorizationRequest $request): RedirectResponse

View File

@@ -13,11 +13,17 @@ final class AuthorizationRequest extends FormRequest implements FormRequestDto
*/
public function rules(): array
{
return [
$rules = [
'email' => ['required', 'email', 'max:255'],
'password' => ['required', 'min:3'],
'remember' => ['nullable', 'boolean'],
];
if (config('app.captcha', false)) {
$rules['captcha-verified'] = ['captcha'];
}
return $rules;
}
public function getDto(): Authorization

View File

@@ -7,6 +7,7 @@
"require": {
"php": "^8.3",
"guzzlehttp/guzzle": "^7.2",
"kor-elf/captcha-rule-for-laravel": "^1.0",
"laravel/framework": "^11.0",
"laravel/sanctum": "^4.0",
"laravel/tinker": "^2.8"

View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "680bb583053c6714b7b932ef1d099191",
"content-hash": "94e26ab4b33fa6f72cca1475dace5690",
"packages": [
{
"name": "brick/math",
@@ -1045,6 +1045,56 @@
],
"time": "2023-12-03T19:50:20+00:00"
},
{
"name": "kor-elf/captcha-rule-for-laravel",
"version": "1.0.1",
"source": {
"type": "git",
"url": "https://git.kor-elf.net/kor-elf/captcha-rule-for-laravel",
"reference": "b2c9242d51059bcd4275da6544134d8f28f08750"
},
"require": {
"guzzlehttp/guzzle": "^7.0.1",
"illuminate/support": "^10.0|^11.0",
"php": "^8.2"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"korElf\\CaptchaRuleForLaravel\\CaptchaProvider"
]
}
},
"autoload": {
"files": [
"src/helpers.php"
],
"psr-4": {
"korElf\\CaptchaRuleForLaravel\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Leonid Nikitin",
"email": "i@kor-elf.net",
"homepage": "https://git.kor-elf.net/kor-elf",
"role": "Developer"
}
],
"description": "Validation Rule Captcha for Laravel",
"homepage": "https://git.kor-elf.net/kor-elf/captcha-rule-for-laravel",
"keywords": [
"captcha",
"laravel",
"validation"
],
"time": "2024-04-02T17:36:12+00:00"
},
{
"name": "laravel/framework",
"version": "v11.5.0",

View File

@@ -42,6 +42,15 @@ return [
'demo_email' => env('APP_DEMO_EMAIL', false),
'demo_password' => env('APP_DEMO_PASSWORD', false),
/*
|--------------------------------------------------------------------------
| Сaptcha
|--------------------------------------------------------------------------
|
| Enables or disables captcha.
*/
'captcha' => (bool) env('APP_CAPTCHA', false),
/*
|--------------------------------------------------------------------------
| Application Debug Mode

View File

@@ -142,6 +142,7 @@ return [
'url' => 'The :attribute format is invalid.',
'uuid' => 'The :attribute must be a valid UUID.',
'no_type' => 'The :attribute can only use: :type.',
'captcha' => 'Failed to pass human verification.',
'attributes' => [
'address' => 'address',
'age' => 'age',

View File

@@ -142,6 +142,7 @@ return [
'url' => 'Значение поля :attribute имеет ошибочный формат URL.',
'uuid' => 'Значение поля :attribute должно быть корректным UUID.',
'no_type' => 'Значение поля :attribute может использовать только: :type.',
'captcha' => 'Не удалось пройти проверку человеком.',
'attributes' => [
'address' => 'адрес',
'age' => 'возраст',

View File

@@ -50,6 +50,11 @@
</label>
</div>
</div>
@if($captcha)
<div class="form-group mb-4">
@captcha
</div>
@endif
</div>
<div class="d-grid">
<button type="submit" class="btn btn-gray-800">{{ __('Sign in') }}</button>