1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2024-10-31 08:02:42 +01:00
BookStack/app/Http/Middleware/Authenticate.php

47 lines
1.1 KiB
PHP
Raw Normal View History

2015-07-12 21:01:42 +02:00
<?php
namespace BookStack\Http\Middleware;
2015-07-12 21:01:42 +02:00
use Closure;
use Illuminate\Http\Request;
2015-07-12 21:01:42 +02:00
class Authenticate
{
/**
* Handle an incoming request.
*/
public function handle(Request $request, Closure $next)
2015-07-12 21:01:42 +02:00
{
if (!hasAppAccess()) {
2015-07-12 21:01:42 +02:00
if ($request->ajax()) {
return response('Unauthorized.', 401);
}
return redirect()->guest(url('/login'));
2015-07-12 21:01:42 +02:00
}
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' => [
2021-06-26 17:23:15 +02:00
'code' => 401,
'message' => trans('errors.email_confirmation_awaiting'),
],
], 401);
}
if (session()->get('sent-email-confirmation') === true) {
return redirect('/register/confirm');
}
return redirect('/register/confirm/awaiting');
}
2015-07-12 21:01:42 +02:00
}