1 | <?php |
||
2 | |||
3 | namespace Yeelight\Http\Middleware; |
||
4 | |||
5 | use Closure; |
||
6 | use Illuminate\Support\Facades\Auth; |
||
7 | |||
8 | class Authenticate |
||
9 | { |
||
10 | /** |
||
11 | * Handle an incoming request. |
||
12 | * |
||
13 | * @param \Illuminate\Http\Request $request |
||
14 | * @param \Closure $next |
||
15 | * |
||
16 | * @return mixed |
||
17 | */ |
||
18 | public function handle($request, Closure $next) |
||
19 | { |
||
20 | if (Auth::guard(config('yeelight.backend.route.prefix'))->guest() && !$this->shouldPassThrough($request)) { |
||
21 | return redirect()->guest(backend_base_path('auth/login')); |
||
22 | } |
||
23 | |||
24 | return $next($request); |
||
25 | } |
||
26 | |||
27 | /** |
||
28 | * Determine if the request has a URI that should pass through verification. |
||
29 | * |
||
30 | * @param \Illuminate\Http\Request $request |
||
31 | * |
||
32 | * @return bool |
||
33 | */ |
||
34 | protected function shouldPassThrough($request) |
||
35 | { |
||
36 | $excepts = [ |
||
37 | backend_base_path('auth/login'), |
||
38 | backend_base_path('auth/logout'), |
||
39 | ]; |
||
40 | |||
41 | foreach ($excepts as $except) { |
||
42 | if ($except !== '/') { |
||
43 | $except = trim($except, '/'); |
||
44 | } |
||
45 | |||
46 | if ($request->is($except)) { |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
47 | return true; |
||
48 | } |
||
49 | } |
||
50 | |||
51 | return false; |
||
52 | } |
||
53 | } |
||
54 |