From 082c1ccb268a3b4dd534cd32113c4c470952b40c Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 12 Dec 2020 21:04:59 -0700 Subject: [PATCH] Add hCaptcha --- app/Http/Controllers/Auth/LoginController.php | 4 ++ .../Controllers/Auth/RegisterController.php | 4 ++ composer.json | 5 +- composer.lock | 72 ++++++++++++++++++- config/captcha.php | 15 ++++ resources/views/auth/login.blade.php | 10 ++- resources/views/auth/register.blade.php | 6 ++ resources/views/site/index.blade.php | 6 +- 8 files changed, 115 insertions(+), 7 deletions(-) create mode 100644 config/captcha.php diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index c47bf9ab7..1977a1e3c 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -53,6 +53,10 @@ class LoginController extends Controller 'password' => 'required|string|min:6', ]; + if(config('captcha.enabled')) { + $rules['h-captcha-response'] = 'required|captcha'; + } + $this->validate($request, $rules); } diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index 046684329..c8adf28d6 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -118,6 +118,10 @@ class RegisterController extends Controller 'password' => 'required|string|min:'.config('pixelfed.min_password_length').'|confirmed', ]; + if(config('captcha.enabled')) { + $rules['h-captcha-response'] = 'required|captcha'; + } + return Validator::make($data, $rules); } diff --git a/composer.json b/composer.json index 5a490057e..08cb347ef 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,7 @@ "ext-openssl": "*", "beyondcode/laravel-self-diagnosis": "^1.0.2", "brick/math": "^0.8", + "buzz/laravel-h-captcha": "1.0.2", "doctrine/dbal": "^2.7", "fideloper/proxy": "^4.0", "fruitcake/laravel-cors": "^2.0", @@ -39,8 +40,8 @@ "predis/predis": "^1.1", "spatie/laravel-backup": "^6.0.0", "spatie/laravel-image-optimizer": "^1.1", - "symfony/http-kernel": "5.1.5", - "stevebauman/purify": "3.0.*" + "stevebauman/purify": "3.0.*", + "symfony/http-kernel": "5.1.5" }, "require-dev": { "facade/ignition": "^2.0", diff --git a/composer.lock b/composer.lock index c0d8469a5..3b0e24b50 100644 --- a/composer.lock +++ b/composer.lock @@ -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": "2fa0012197581d98d4c04d1b83448d34", + "content-hash": "d1c65fe7e4f498b01260f09a3eb04015", "packages": [ { "name": "alchemy/binary-driver", @@ -319,6 +319,74 @@ ], "time": "2020-08-18T23:41:20+00:00" }, + { + "name": "buzz/laravel-h-captcha", + "version": "v1.0.2", + "source": { + "type": "git", + "url": "https://github.com/thinhbuzz/laravel-h-captcha.git", + "reference": "41a063bea0e204ae5b8afbafce981d4675dd8af7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thinhbuzz/laravel-h-captcha/zipball/41a063bea0e204ae5b8afbafce981d4675dd8af7", + "reference": "41a063bea0e204ae5b8afbafce981d4675dd8af7", + "shasum": "" + }, + "require": { + "guzzlehttp/guzzle": "6.*|7.*", + "illuminate/support": "5.*|6.*|7.*|8.*", + "php": ">=5.4.0" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Buzz\\LaravelHCaptcha\\CaptchaServiceProvider" + ], + "aliases": { + "Captcha": "Buzz\\LaravelHCaptcha\\CaptchaFacade" + } + } + }, + "autoload": { + "psr-4": { + "Buzz\\LaravelHCaptcha\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "ThinhBuzz", + "email": "mr.thinhbuzz@gmail.com", + "homepage": "https://www.facebook.com/thinh.buzz" + } + ], + "description": "hCaptcha for Laravel 5, Laravel 6, Laravel 7 and Laravel 8", + "homepage": "https://github.com/thinhbuzz/laravel-h-captcha", + "keywords": [ + "captcha", + "h captcha", + "h-captcha", + "hcaptcha", + "laravel", + "laravel 5", + "laravel 6", + "laravel 7", + "laravel 8", + "laravel5", + "laravel6", + "laravel7" + ], + "support": { + "issues": "https://github.com/thinhbuzz/laravel-h-captcha/issues", + "source": "https://github.com/thinhbuzz/laravel-h-captcha/tree/v1.0.2" + }, + "time": "2020-09-14T15:04:45+00:00" + }, { "name": "cakephp/chronos", "version": "2.0.6", @@ -10132,5 +10200,5 @@ "ext-openssl": "*" }, "platform-dev": [], - "plugin-api-version": "1.1.0" + "plugin-api-version": "2.0.0" } diff --git a/config/captcha.php b/config/captcha.php new file mode 100644 index 000000000..baeeae2d2 --- /dev/null +++ b/config/captcha.php @@ -0,0 +1,15 @@ + env('CAPTCHA_ENABLED', false), + 'secret' => env('CAPTCHA_SECRET', 'default_secret'), + 'sitekey' => env('CAPTCHA_SITEKEY', 'default_sitekey'), + 'http_client' => \Buzz\LaravelHCaptcha\HttpClient::class, + 'options' => [ + 'multiple' => false, + 'lang' => app()->getLocale(), + ], + 'attributes' => [ + 'theme' => 'light' + ], +]; \ No newline at end of file diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index a0e23291f..9e6fe009d 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -4,8 +4,8 @@
-
-
{{ __('Login') }}
+
+
{{ __('Login') }}
@@ -50,6 +50,12 @@
+ @if(config('captcha.enabled')) +
+ {!! app('captcha')->display() !!} +
+ @endif +
+ @if(config('captcha.enabled')) +
+ {!! app('captcha')->display() !!} +
+ @endif +

By signing up, you agree to our Terms of Use and Privacy Policy.

diff --git a/resources/views/site/index.blade.php b/resources/views/site/index.blade.php index 4583ae939..e1c454d20 100644 --- a/resources/views/site/index.blade.php +++ b/resources/views/site/index.blade.php @@ -108,7 +108,11 @@
- + @if(config('captcha.enabled')) +
+ {!! app('captcha')->display() !!} +
+ @endif