mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Implement API throttling, and ensure output is JSON
This commit is contained in:
parent
72dee9bfb6
commit
5b8f56593e
@ -3,9 +3,10 @@
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException as ModelNotFoundException;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Illuminate\Http\Exceptions\ThrottleRequestsException;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
@ -56,7 +57,11 @@ class Handler extends ExceptionHandler
|
||||
|
||||
if ($exception instanceof ModelNotFoundException)
|
||||
{
|
||||
return response()->json(['error'=>'Record not found'],400);
|
||||
return response()->json(['message'=>'Record not found'],400);
|
||||
}
|
||||
else if($exception instanceof ThrottleRequestsException)
|
||||
{
|
||||
return response()->json(['message'=>'Too many requests'],429);
|
||||
}
|
||||
|
||||
return parent::render($request, $exception);
|
||||
|
@ -67,10 +67,20 @@ class LoginController extends BaseController
|
||||
{
|
||||
$this->validateLogin($request);
|
||||
|
||||
if ($this->hasTooManyLoginAttempts($request)) {
|
||||
$this->fireLockoutEvent($request);
|
||||
|
||||
return response()->json(['message' => 'Too many login attempts, you are being throttled']);
|
||||
}
|
||||
|
||||
if ($this->attemptLogin($request))
|
||||
return $this->itemResponse($this->guard()->user());
|
||||
else
|
||||
else {
|
||||
|
||||
$this->incrementLoginAttempts($request);
|
||||
|
||||
return response()->json(['message' => ctrans('texts.invalid_credentials')]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user