mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 01:36:00 -04:00
6f1b88a6a6
Email confirmation middleware caused more mess than good, As caused priority issues and it depended on auth actions. Instead its now a trai used on auth middlewares. Also used 'EncryptCookies' middleware on API instead of custom decryption in custom middleware since we'd need to do replicate all the same actions anyway. Shouldn't have too much effect since it only actions over cookies that exist, of which none should be there for most API requests. Also split out some large guard functions to be a little more readable and appease codeclimate.
32 lines
657 B
PHP
32 lines
657 B
PHP
<?php
|
|
|
|
namespace BookStack\Http\Middleware;
|
|
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
|
|
class Authenticate
|
|
{
|
|
use ChecksForEmailConfirmation;
|
|
|
|
/**
|
|
* Handle an incoming request.
|
|
*/
|
|
public function handle(Request $request, Closure $next)
|
|
{
|
|
if ($this->awaitingEmailConfirmation()) {
|
|
return $this->emailConfirmationErrorResponse($request);
|
|
}
|
|
|
|
if (!hasAppAccess()) {
|
|
if ($request->ajax()) {
|
|
return response('Unauthorized.', 401);
|
|
} else {
|
|
return redirect()->guest(url('/login'));
|
|
}
|
|
}
|
|
|
|
return $next($request);
|
|
}
|
|
}
|