Total Complexity | 6 |
Total Lines | 41 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
21 | class LogsOutBannedUser |
||
22 | { |
||
23 | /** |
||
24 | * The Guard implementation. |
||
25 | * |
||
26 | * @var \Illuminate\Contracts\Auth\Guard |
||
27 | */ |
||
28 | protected $auth; |
||
29 | |||
30 | /** |
||
31 | * @param \Illuminate\Contracts\Auth\Guard $auth |
||
32 | */ |
||
33 | public function __construct(Guard $auth) |
||
34 | { |
||
35 | $this->auth = $auth; |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * Handle an incoming request. |
||
40 | * |
||
41 | * @param \Illuminate\Http\Request $request |
||
42 | * @param \Closure $next |
||
43 | * @return mixed |
||
44 | * @throws \Exception |
||
45 | */ |
||
46 | public function handle($request, Closure $next) |
||
47 | { |
||
48 | $user = $this->auth->user(); |
||
49 | $redirect_url = config('ban.redirect_url', null); |
||
50 | $errors = [ |
||
51 | 'login' => 'This account is blocked.', |
||
52 | ]; |
||
53 | |||
54 | if ($user && $user instanceof BannableContract && $user->isBanned()) { |
||
55 | if ($this->auth instanceof StatefulGuardContract) { |
||
56 | // TODO: Cover with tests |
||
57 | $this->auth->logout(); |
||
58 | } |
||
59 | |||
60 | f($redirect_url === null){ |
||
61 | return redirect()->back()->withInput()->withErrors($errors); |
||
|
|||
62 | } |
||
71 |