UserConfirmed   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 50
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B handle() 0 19 5
1
<?php
2
3
namespace App\Http\Middleware;
4
5
use Auth;
6
use Illuminate\Session\Store;
7
8
class UserConfirmed
9
{
10
    /**
11
     * @var Store
12
     */
13
    private $session;
14
15
    protected $excludeRoutes = [
16
        'resend_verify_email_form',
17
        'resend_verify_email',
18
        'verify_email',
19
        'logout'
20
    ];
21
22
    /**
23
     * UserConfirmed constructor.
24
     * @param Store $session
25
     */
26
    public function __construct(Store $session)
27
    {
28
        $this->session = $session;
29
    }
30
31
    /**
32
     * Handle an incoming request.
33
     *
34
     * @param  \Illuminate\Http\Request $request
35
     * @param  \Closure $next
36
     * @return mixed
37
     */
38
    public function handle($request, \Closure $next)
39
    {
40
        if(Auth::check())
41
        {
42
            if(Auth::user()->confirmed)
43
                return $next($request);
44
45
            foreach ($this->excludeRoutes as $route) {
46
                if($request->route()->getName() == $route) {
47
                    return $next($request);
48
                }
49
            }
50
51
            Auth::logout();
52
            return redirect()->route('home');
53
        }
54
55
        return $next($request);
56
    }
57
}