diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 4ae65d51d82b..376ea4fb4dac 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -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); diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 569a5c76e8ac..4fceea2d97f8 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -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')]); + } }