Skip to content

Commit

Permalink
Handle JSON request (#17369)
Browse files Browse the repository at this point in the history
  • Loading branch information
cretueusebiu authored and taylorotwell committed Jan 17, 2017
1 parent c52d031 commit a0bebba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/Illuminate/Foundation/Auth/AuthenticatesUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,15 @@ protected function authenticated(Request $request, $user)
*/
protected function sendFailedLoginResponse(Request $request)
{
$errors = [$this->username() => trans('auth.failed')];

if ($request->expectsJson()) {
return response()->json($errors, 422);
}

return redirect()->back()
->withInput($request->only($this->username(), 'remember'))
->withErrors([
$this->username() => trans('auth.failed'),
]);
->withErrors($errors);
}

/**
Expand Down
8 changes: 7 additions & 1 deletion src/Illuminate/Foundation/Auth/ThrottlesLogins.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,15 @@ protected function sendLockoutResponse(Request $request)

$message = Lang::get('auth.throttle', ['seconds' => $seconds]);

$errors = [$this->username() => $message];

if ($request->expectsJson()) {
return response()->json($errors, 423);
}

return redirect()->back()
->withInput($request->only($this->username(), 'remember'))
->withErrors([$this->username() => $message]);
->withErrors($errors);
}

/**
Expand Down

0 comments on commit a0bebba

Please sign in to comment.