| Conditions | 7 |
| Paths | 5 |
| Total Lines | 21 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 5 |
| CRAP Score | 11.3004 |
| Changes | 0 | ||
| 1 | <?php |
||
| 21 | public function handle($request, Closure $next, $role) |
||
| 22 | 15 | { |
|
| 23 | 3 | // If user logged in as admin, always pass, regardless of $role. |
|
| 24 | 3 | if (Auth::check() && Auth::user()->isAdmin()) { |
|
| 25 | Log::info('CheckRole Bypassed as Admin'); |
||
| 26 | return $next($request); |
||
| 27 | } |
||
| 28 | 12 | ||
| 29 | // Redirect if not logged in, or if not the correct role. |
||
| 30 | if (Auth::guest() || !Auth::user()->hasRole($role)) { |
||
| 31 | Log::info('CheckRole Failed'); |
||
| 32 | // TODO: redirect to some sort of error messag |
||
| 33 | if (WhichPortal::isManagerPortal()) { |
||
| 34 | return redirect(route('manager.home')); |
||
| 35 | } elseif (WhichPortal::isHrPortal()) { |
||
| 36 | return redirect(route('hr_advisor.home')); |
||
| 37 | 12 | } else { |
|
| 38 | return redirect(route('home')); |
||
| 39 | } |
||
| 40 | } |
||
| 41 | return $next($request); |
||
| 42 | } |
||
| 44 |