Fix validating captcha

This commit is contained in:
Pig Fang 2018-07-21 08:17:16 +08:00
parent 201fe21e6d
commit 8bd60624a0
2 changed files with 10 additions and 15 deletions

View File

@ -40,8 +40,7 @@ class AuthController extends Controller
$user = $users->get($identification, $authType); $user = $users->get($identification, $authType);
if (session('login_fails', 0) > 3) { if (session('login_fails', 0) > 3) {
if (strtolower($request->input('captcha')) != strtolower(session('phrase'))) $this->validate($request, ['captcha' => 'required|captcha']);
return json(trans('auth.validation.captcha'), 1);
} }
if (! $user) { if (! $user) {

View File

@ -93,18 +93,14 @@ class AuthControllerTest extends TestCase
$this->flushSession(); $this->flushSession();
// Should check captcha if there are too many fails // Should check captcha if there are too many fails
$this->withSession( $this->withSession(['login_fails' => 4])
[ ->postJson(
'login_fails' => 4
]
)->postJson(
'/auth/login', [ '/auth/login', [
'identification' => $user->email, 'identification' => $user->email,
'password' => '12345678', 'password' => '12345678',
'captcha' => 'b'
])->assertJson([ ])->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans('auth.validation.captcha') 'msg' => trans('validation.required', ['attribute' => 'captcha'])
]); ]);
$this->flushSession(); $this->flushSession();