Add hCaptcha

This commit is contained in:
Daniel Supernault 2020-12-12 21:04:59 -07:00
parent f38136b499
commit 082c1ccb26
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
8 changed files with 115 additions and 7 deletions

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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",

72
composer.lock generated
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": "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"
}

15
config/captcha.php Normal file
View file

@ -0,0 +1,15 @@
<?php
return [
'enabled' => 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'
],
];

View file

@ -4,8 +4,8 @@
<div class="container mt-4">
<div class="row justify-content-center">
<div class="col-lg-5">
<div class="card">
<div class="card-header bg-white p-3 text-center font-weight-bold">{{ __('Login') }}</div>
<div class="">
<div class="card-header bg-transparent p-3 text-center font-weight-bold">{{ __('Login') }}</div>
<div class="card-body">
<form method="POST" action="{{ route('login') }}" class="px-5">
@ -50,6 +50,12 @@
</div>
</div>
@if(config('captcha.enabled'))
<div class="d-flex justify-content-center mb-3">
{!! app('captcha')->display() !!}
</div>
@endif
<div class="form-group row mb-0">
<div class="col-md-12">
<button type="submit" class="btn btn-primary btn-block py-0 font-weight-bold">

View file

@ -81,6 +81,12 @@
</div>
</div>
@if(config('captcha.enabled'))
<div class="d-flex justify-content-center my-3">
{!! app('captcha')->display() !!}
</div>
@endif
<p class="small">By signing up, you agree to our <a href="{{route('site.terms')}}" class="font-weight-bold text-dark">Terms of Use</a> and <a href="{{route('site.privacy')}}" class="font-weight-bold text-dark">Privacy Policy</a>.</p>
<div class="form-group row">

View file

@ -108,7 +108,11 @@
</div>
</div>
</div>
@if(config('captcha.enabled'))
<div class="d-flex justify-content-center mb-3">
{!! app('captcha')->display() !!}
</div>
@endif
<div class="form-group row mb-0">
<div class="col-md-12">
<button type="submit" class="btn btn-primary btn-block py-0 font-weight-bold text-uppercase">