invoiceninja/app/Http/Middleware/RedirectIfAuthenticated.php

62 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2017-01-30 21:40:43 +02:00
<?php
namespace App\Http\Middleware;
2015-03-12 10:44:39 +10:00
2015-04-20 17:34:23 +03:00
use App\Models\Client;
2017-01-30 21:40:43 +02:00
use Closure;
2015-03-12 10:44:39 +10:00
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Http\RedirectResponse;
2017-01-30 21:40:43 +02:00
use Illuminate\Http\Request;
use Session;
2015-03-12 10:44:39 +10:00
/**
2017-01-30 21:40:43 +02:00
* Class RedirectIfAuthenticated.
*/
class RedirectIfAuthenticated
{
/**
* The Guard implementation.
*
* @var Guard
*/
protected $auth;
/**
* Create a new filter instance.
*
2017-01-30 21:40:43 +02:00
* @param Guard $auth
*/
public function __construct(Guard $auth)
{
$this->auth = $auth;
}
/**
* Handle an incoming request.
*
2017-01-30 21:40:43 +02:00
* @param Request $request
* @param Closure $next
*
* @return mixed
*/
2017-11-14 10:58:08 +02:00
public function handle(Request $request, Closure $next, $guard = null)
{
2017-11-14 10:58:08 +02:00
if (auth()->guard($guard)->check()) {
2015-04-27 15:28:40 +03:00
Session::reflash();
2017-11-14 10:58:08 +02:00
switch ($guard) {
case 'client':
if (session('contact_key')) {
return redirect('/client/dashboard');
}
break;
default:
return redirect('/dashboard');
break;
}
}
2015-03-12 10:44:39 +10:00
return $next($request);
}
2015-03-12 10:44:39 +10:00
}