CheckPasswordExpire   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 44.44%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
eloc 10
c 3
b 0
f 0
dl 0
loc 26
ccs 4
cts 9
cp 0.4444
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 14 5
1
<?php
2
3
namespace App\Http\Middleware;
4
5
use Closure;
6
use Carbon\Carbon;
7
8
use Illuminate\Http\Request;
9
use Illuminate\Support\Facades\Log;
10
use Illuminate\Support\Facades\Route;
11
12
/*
13
*   If a user's password has expired, they must update it before being allowed to continue
14
*/
15
class CheckPasswordExpire
16
{
17
    //  Routes that are not affected by the password expiring
18
    protected $bypassRoutes = [
19
        'password.index',
20 700
        'password.store',
21
        'logout',
22 700
    ];
23
24
    /**
25 632
     *  Check to see if the users password has expired recently
26
     */
27
    public function handle(Request $request, Closure $next)
28
    {
29
        //  Check to see if we are logged in
30
        if($request->user() && !in_array(Route::current()->getName(), $this->bypassRoutes))
31
        {
32
            //  check to see if the password is expired
33
            if($request->user()->password_expires && $request->user()->password_expires < Carbon::now())
34
            {
35
                Log::stack(['auth', 'user'])->notice('User '.$request->user()->full_name.' is being forced to change their password');
36
                return redirect()->route('password.index')->with(['message' => 'Your Password Has Expired.  You must change your password to continue', 'type' => 'warning']);
37 700
            }
38
        }
39
40
        return $next($request);
41
    }
42
}
43