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);
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) {

View File

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