CheckUserStatus::handle()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 2
nop 2
dl 0
loc 11
ccs 0
cts 9
cp 0
crap 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/*
3
 * This file is part of the Laravel Platfourm package.
4
 *
5
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Longman\Platfourm\Auth\Middleware;
12
13
use Closure;
14
use Longman\Platfourm\Contracts\Auth\AuthUserService as AuthUserServiceContract;
15
16
class CheckUserStatus
17
{
18
19
    /**
20
     * @var \Longman\Platfourm\Contracts\Auth\AuthUserService
21
     */
22
    protected $authService;
23
24
    /**
25
     * CheckUserStatus constructor.
26
     *
27
     * @param \Longman\Platfourm\Contracts\Auth\AuthUserService $authService
28
     */
29
    public function __construct(AuthUserServiceContract $authService)
30
    {
31
        $this->authService = $authService;
32
    }
33
34
    /**
35
     * @param          $request
36
     * @param \Closure $next
37
     * @return \Illuminate\Http\RedirectResponse
38
     */
39
    public function handle($request, Closure $next)
40
    {
41
        if ($this->authService->check() && !$this->authService->user()->canLogin()) {
42
            $this->authService->logout();
43
44
            return redirect('auth/login')
45
                ->with(['error' => 'Your account is disabled']);
46
        }
47
48
        return $next($request);
49
    }
50
}
51