Completed
Pull Request — master (#59)
by
unknown
01:24
created

ProtectAuthenticateImpersonation::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
namespace Lab404\Impersonate\Middleware;
4
5
use Closure;
6
use Illuminate\Support\Facades\Redirect;
7
use Lab404\Impersonate\Services\ImpersonateManager;
8
use Illuminate\Contracts\Auth\Factory as Auth;
9
//\Illuminate\Auth\Middleware\Authenticate::class,
10
11
class ProtectAuthenticateImpersonation
12
{
13
    /**
14
     * The authentication factory instance.
15
     *
16
     * @var \Illuminate\Contracts\Auth\Factory
17
     */
18
    protected $auth;
19
20
    public function __construct(Auth $auth)
21
    {
22
        $this->auth = $auth;
23
    }
24
25
    /**
26
     * Handle an incoming request.
27
     *
28
     * @param   \Illuminate\Http\Request  $request
29
     * @param   \Closure  $next
30
     * @return  mixed
31
     */
32
    public function handle($request, Closure $next)
33
    {
34
        $guard = session(config('laravel-impersonate.session_guard_using'), config('auth.defaults.guard'));
35
36
        if(!$this->auth->guard($guard)->check())
37
        {
38
            return Redirect::back();
39
        }
40
41
        return $next($request);
42
    }
43
}