Passed
Push — dev5 ( fee765...622739 )
by Ron
07:50
created

CheckPasswordExpire   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 44.44%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 27
ccs 4
cts 9
cp 0.4444
rs 10
c 1
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 18 6
1
<?php
2
3
namespace App\Http\Middleware;
4
5
use Closure;
6
use Carbon\Carbon;
7
use Illuminate\Support\Facades\Log;
8
use Illuminate\Support\Facades\Auth;
9
use Illuminate\Support\Facades\Route;
10
11
class CheckPasswordExpire
12
{
13
    /**
14
     * Handle an incoming request.
15
     *
16
     * @param  \Illuminate\Http\Request  $request
17
     * @param  \Closure  $next
18
     * @return mixed
19
     */
20 568
    public function handle($request, Closure $next)
21
    {
22 568
        if(Auth::check() && !(Route::current()->getName() === 'changePassword' || Route::current()->getName() === 'logout'))
23
        {
24
            //  Verify that the users password has not expired
25 510
            if(Auth::user()->password_expires !== null)
26
            {
27
                $passExp = new Carbon((Auth::user()->password_expires));
28
                if(Carbon::now() > $passExp )
29
                {
30
                    Log::notice('User ID-'.Auth::user()->user_id.' is being forced to change their password.');
31
                    $request->session()->flash('change_password', 'change_password');
32
                    return redirect()->route('changePassword');
33
                }
34
            }
35
        }
36
37 568
        return $next($request);
38
    }
39
}
40