diff --git a/.env.example b/.env.example index 06c004b..84e517d 100644 --- a/.env.example +++ b/.env.example @@ -36,5 +36,7 @@ PUSHER_APP_ID= PUSHER_APP_KEY= PUSHER_APP_SECRET= +# (Optional) reCAPTCHA Key +# https://www.google.com/recaptcha NOCAPTCHA_SECRET= -NOCAPTCHA_SITEKEY= \ No newline at end of file +NOCAPTCHA_SITEKEY= diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index d3052d1..0e79f03 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -47,12 +47,18 @@ class RegisterController extends Controller */ protected function validator(array $data) { - return Validator::make($data, [ + $rules = [ 'name' => 'required|string|regex:/^[a-zA-Z0-9_-]+$/u|max:15|unique:users', 'email' => 'required|string|email|max:255|unique:users', - 'password' => 'required|string|min:6|confirmed', - 'g-recaptcha-response' => 'required|captcha' - ], + 'password' => 'required|string|min:6|confirmed' + ]; + + // reCAPTCHAのキーが設定されている場合、判定を有効化 + if (!empty(config('captcha.secret'))) { + $rules['g-recaptcha-response'] = 'required|captcha'; + } + + return Validator::make($data, $rules, ['name.regex' => 'ユーザー名には半角英数字とアンダーバー、ハイフンのみ使用できます。'], ['name' => 'ユーザー名'] ); diff --git a/resources/views/auth/register.blade.php b/resources/views/auth/register.blade.php index 59b2fa9..ff9fc34 100644 --- a/resources/views/auth/register.blade.php +++ b/resources/views/auth/register.blade.php @@ -3,7 +3,9 @@ @section('title', '新規登録') @push('head') - {!! NoCaptcha::renderJs() !!} + @if (!empty(config('captcha.secret'))) + {!! NoCaptcha::renderJs() !!} + @endif @endpush @section('content') @@ -57,14 +59,16 @@ -
-
- {!! NoCaptcha::display() !!} + @if (!empty(config('captcha.secret'))) +
+
+ {!! NoCaptcha::display() !!} +
+ @if ($errors->has('g-recaptcha-response')) +
{{ $errors->first('g-recaptcha-response') }}
+ @endif
- @if ($errors->has('g-recaptcha-response')) -
{{ $errors->first('g-recaptcha-response') }}
- @endif -
+ @endif