Completed
Pull Request — master (#59)
by
unknown
01:25
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 Illuminate\Contracts\Auth\Factory as Auth;
8
9
class ProtectAuthenticateImpersonation
10
{
11
    /**
12
     * The authentication factory instance.
13
     *
14
     * @var \Illuminate\Contracts\Auth\Factory
15
     */
16
    protected $auth;
17
18
    public function __construct(Auth $auth)
19
    {
20
        $this->auth = $auth;
21
    }
22
23
    /**
24
     * Handle an incoming request.
25
     *
26
     * @param   \Illuminate\Http\Request  $request
27
     * @param   \Closure  $next
28
     * @return  mixed
29
     */
30
    public function handle($request, Closure $next)
31
    {
32
        $guard = session(config('laravel-impersonate.session_guard'), config('auth.defaults.guard'));
33
34
        if(!$this->auth->guard($guard)->check())
35
        {
36
            return Redirect::back();
37
        }
38
39
        return $next($request);
40
    }
41
}