From b3876468b28c5386c6eb2bc0401e7824437f4472 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Sun, 12 Aug 2018 16:00:21 +0800 Subject: [PATCH] Fix validating captcha --- app/Http/Controllers/AuthController.php | 5 +++-- tests/AuthControllerTest.php | 10 +--------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index d1fc8622..517c529e 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -140,8 +140,9 @@ class AuthController extends Controller public function handleForgot(Request $request, UserRepository $users) { - if (! $this->checkCaptcha($request)) - return json(trans('auth.validation.captcha'), 1); + $this->validate($request, [ + 'captcha' => 'required'.(app()->environment('testing') ? '' : '|captcha') + ]); if (config('mail.driver') == "") return json(trans('auth.forgot.close'), 1); diff --git a/tests/AuthControllerTest.php b/tests/AuthControllerTest.php index 2b4c8c15..56ce4934 100644 --- a/tests/AuthControllerTest.php +++ b/tests/AuthControllerTest.php @@ -372,17 +372,9 @@ class AuthControllerTest extends TestCase { Mail::fake(); - // Should return a warning if `captcha` is wrong - $this->withSession(['phrase' => 'a'])->postJson('/auth/forgot', [ - 'captcha' => 'b' - ])->assertJson([ - 'errno' => 1, - 'msg' => trans('auth.validation.captcha') - ]); - // Should be forbidden if "forgot password" is closed config(['mail.driver' => '']); - $this->withSession(['phrase' => 'a'])->postJson('/auth/forgot', [ + $this->postJson('/auth/forgot', [ 'captcha' => 'a' ])->assertJson([ 'errno' => 1,