3 namespace BookStack\Http\Middleware;
5 use BookStack\Auth\Access\EmailConfirmationService;
6 use BookStack\Auth\User;
10 * Check that the user's email address is confirmed.
12 * As of v21.08 this is technically not required but kept as a prevention
13 * to log out any users that may be logged in but in an "awaiting confirmation" state.
14 * We'll keep this for a while until it'd be very unlikely for a user to be upgrading from
15 * a pre-v21.08 version.
17 * Ideally we'd simply invalidate all existing sessions upon update but that has
18 * proven to be a lot more difficult than expected.
20 class CheckEmailConfirmed
22 protected $confirmationService;
24 public function __construct(EmailConfirmationService $confirmationService)
26 $this->confirmationService = $confirmationService;
30 * Handle an incoming request.
32 * @param \Illuminate\Http\Request $request
33 * @param \Closure $next
37 public function handle($request, Closure $next)
39 /** @var User $user */
40 $user = auth()->user();
41 if (auth()->check() && !$user->email_confirmed && $this->confirmationService->confirmationRequired()) {
44 return redirect()->to('/');
47 return $next($request);