BookStack/app/Http/Middleware/RedirectIfAuthenticated.php

43 lines
932 B
PHP
Raw Normal View History

<?php namespace BookStack\Http\Middleware;
2015-07-12 19:01:42 +00: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 19:40:36 +00:00
* @param Guard $auth
2015-07-12 19:01:42 +00:00
* @return void
*/
public function __construct(Guard $auth)
{
$this->auth = $auth;
}
/**
* Handle an incoming request.
*
2015-09-04 19:40:36 +00:00
* @param \Illuminate\Http\Request $request
* @param \Closure $next
2015-07-12 19:01:42 +00: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 19:40:36 +00:00
return redirect('/');
2015-07-12 19:01:42 +00:00
}
return $next($request);
}
}