BookStack/app/Http/Middleware/RedirectIfAuthenticated.php

43 lines
932 B
PHP
Raw Normal View History

<?php namespace BookStack\Http\Middleware;
2015-07-12 21:01:42 +02:00
use Closure;
use Illuminate\Contracts\Auth\Guard;
class RedirectIfAuthenticated
{
/**
* The Guard implementation.
*
* @var Guard
*/
protected $auth;
/**
* Create a new filter instance.
*
2015-09-04 21:40:36 +02:00
* @param Guard $auth
2015-07-12 21:01:42 +02:00
* @return void
*/
public function __construct(Guard $auth)
{
$this->auth = $auth;
}
/**
* Handle an incoming request.
*
2015-09-04 21:40:36 +02:00
* @param \Illuminate\Http\Request $request
* @param \Closure $next
2015-07-12 21:01:42 +02:00
* @return mixed
*/
public function handle($request, Closure $next)
{
$requireConfirmation = setting('registration-confirmation');
if ($this->auth->check() && (!$requireConfirmation || ($requireConfirmation && $this->auth->user()->email_confirmed))) {
2015-09-04 21:40:36 +02:00
return redirect('/');
2015-07-12 21:01:42 +02:00
}
return $next($request);
}
}