2015-07-12 15:01:42 -04:00
|
|
|
<?php
|
|
|
|
|
2015-09-10 14:31:09 -04:00
|
|
|
namespace BookStack\Http\Middleware;
|
2015-07-12 15:01:42 -04:00
|
|
|
|
|
|
|
use Closure;
|
2019-12-30 10:46:12 -05:00
|
|
|
use Illuminate\Http\Request;
|
2015-07-12 15:01:42 -04:00
|
|
|
|
|
|
|
class Authenticate
|
|
|
|
{
|
2019-12-30 10:46:12 -05:00
|
|
|
use ChecksForEmailConfirmation;
|
|
|
|
|
2015-07-12 15:01:42 -04:00
|
|
|
/**
|
|
|
|
* Handle an incoming request.
|
|
|
|
*/
|
2019-12-29 21:16:07 -05:00
|
|
|
public function handle(Request $request, Closure $next)
|
2015-07-12 15:01:42 -04:00
|
|
|
{
|
2019-12-30 10:46:12 -05:00
|
|
|
if ($this->awaitingEmailConfirmation()) {
|
|
|
|
return $this->emailConfirmationErrorResponse($request);
|
|
|
|
}
|
|
|
|
|
2019-02-03 12:34:15 -05:00
|
|
|
if (!hasAppAccess()) {
|
2015-07-12 15:01:42 -04:00
|
|
|
if ($request->ajax()) {
|
|
|
|
return response('Unauthorized.', 401);
|
|
|
|
} else {
|
2019-08-04 09:26:39 -04:00
|
|
|
return redirect()->guest(url('/login'));
|
2015-07-12 15:01:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|