X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/fc50a1400d97933e350e32ee32976fddfc0df840..refs/pull/2023/head:/app/Http/Middleware/Authenticate.php diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php index 563fb1e9d..9a8affa88 100644 --- a/app/Http/Middleware/Authenticate.php +++ b/app/Http/Middleware/Authenticate.php @@ -1,46 +1,49 @@ auth = $auth; - } + use ChecksForEmailConfirmation; /** * Handle an incoming request. - * - * @param \Illuminate\Http\Request $request - * @param \Closure $next - * @return mixed */ - public function handle($request, Closure $next) + public function handle(Request $request, Closure $next) { - if ($this->auth->guest()) { + if ($this->awaitingEmailConfirmation()) { + return $this->emailConfirmationErrorResponse($request); + } + + if (!hasAppAccess()) { if ($request->ajax()) { return response('Unauthorized.', 401); } else { - return redirect()->guest('/login'); + return redirect()->guest(url('/login')); } } return $next($request); } + + /** + * Provide an error response for when the current user's email is not confirmed + * in a system which requires it. + */ + protected function emailConfirmationErrorResponse(Request $request) + { + if ($request->wantsJson()) { + return response()->json([ + 'error' => [ + 'code' => 401, + 'message' => trans('errors.email_confirmation_awaiting') + ] + ], 401); + } + + return redirect('/register/confirm/awaiting'); + } }