From 8bd60624a0f8083a2d3bd35de3070686f25fcd3b Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Sat, 21 Jul 2018 08:17:16 +0800 Subject: [PATCH] Fix validating captcha --- app/Http/Controllers/AuthController.php | 3 +-- tests/AuthControllerTest.php | 22 +++++++++------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index 24d6f99a..5e3fd56f 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -40,8 +40,7 @@ class AuthController extends Controller $user = $users->get($identification, $authType); if (session('login_fails', 0) > 3) { - if (strtolower($request->input('captcha')) != strtolower(session('phrase'))) - return json(trans('auth.validation.captcha'), 1); + $this->validate($request, ['captcha' => 'required|captcha']); } if (! $user) { diff --git a/tests/AuthControllerTest.php b/tests/AuthControllerTest.php index c09c5aec..8cba7e30 100644 --- a/tests/AuthControllerTest.php +++ b/tests/AuthControllerTest.php @@ -93,19 +93,15 @@ class AuthControllerTest extends TestCase $this->flushSession(); // Should check captcha if there are too many fails - $this->withSession( - [ - 'login_fails' => 4 - ] - )->postJson( - '/auth/login', [ - 'identification' => $user->email, - 'password' => '12345678', - 'captcha' => 'b' - ])->assertJson([ - 'errno' => 1, - 'msg' => trans('auth.validation.captcha') - ]); + $this->withSession(['login_fails' => 4]) + ->postJson( + '/auth/login', [ + 'identification' => $user->email, + 'password' => '12345678', + ])->assertJson([ + 'errno' => 1, + 'msg' => trans('validation.required', ['attribute' => 'captcha']) + ]); $this->flushSession();