1
0
mirror of https://github.com/flarum/core.git synced 2025-10-18 18:26:07 +02:00

Improve auth API tests

This commit is contained in:
Toby Zerner
2015-01-23 15:24:38 +10:30
parent 1f23cbaf20
commit b57a8d3bc2
3 changed files with 23 additions and 12 deletions

View File

@@ -16,17 +16,20 @@ class Login extends Base
*/
protected function run()
{
$identifier = $this->input('identifier');
$identification = $this->input('identification');
$password = $this->input('password');
$field = filter_var($identifier, FILTER_VALIDATE_EMAIL) ? 'email' : 'username';
$credentials = [$field => $identifier, 'password' => $password];
$field = filter_var($identification, FILTER_VALIDATE_EMAIL) ? 'email' : 'username';
$credentials = [$field => $identification, 'password' => $password];
if (! Auth::attempt($credentials)) {
if (! Auth::attempt($credentials, true)) {
return $this->respondWithError('invalidLogin', 401);
}
$token = Auth::user()->getRememberToken();
$user = Auth::user();
return Response::json(compact('token'));
return Response::json([
'token' => $user->getRememberToken(),
'userId' => $user->id
]);
}
}