2015-07-12 21:01:42 +02:00
|
|
|
<?php
|
|
|
|
|
2015-09-10 20:31:09 +02:00
|
|
|
namespace BookStack\Http\Middleware;
|
2015-07-12 21:01:42 +02:00
|
|
|
|
|
|
|
use Closure;
|
2019-12-30 16:46:12 +01:00
|
|
|
use Illuminate\Http\Request;
|
2015-07-12 21:01:42 +02:00
|
|
|
|
|
|
|
class Authenticate
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Handle an incoming request.
|
|
|
|
*/
|
2019-12-30 03:16:07 +01:00
|
|
|
public function handle(Request $request, Closure $next)
|
2015-07-12 21:01:42 +02:00
|
|
|
{
|
2019-02-03 18:34:15 +01:00
|
|
|
if (!hasAppAccess()) {
|
2015-07-12 21:01:42 +02:00
|
|
|
if ($request->ajax()) {
|
|
|
|
return response('Unauthorized.', 401);
|
|
|
|
}
|
2021-08-02 23:02:25 +02:00
|
|
|
return redirect()->guest(url('/login'));
|
2015-07-12 21:01:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
2020-01-01 17:33:47 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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'),
|
|
|
|
],
|
2020-01-01 17:33:47 +01:00
|
|
|
], 401);
|
|
|
|
}
|
|
|
|
|
2020-09-05 18:26:48 +02:00
|
|
|
if (session()->get('sent-email-confirmation') === true) {
|
|
|
|
return redirect('/register/confirm');
|
|
|
|
}
|
|
|
|
|
2020-01-01 17:33:47 +01:00
|
|
|
return redirect('/register/confirm/awaiting');
|
|
|
|
}
|
2015-07-12 21:01:42 +02:00
|
|
|
}
|