| Total Complexity | 5 |
| Total Lines | 41 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | class AuthenticateSuperadmin |
||
| 10 | { |
||
| 11 | use AuthorizesRequests; |
||
| 12 | /** |
||
| 13 | * The Guard implementation. |
||
| 14 | * |
||
| 15 | * @var Guard |
||
| 16 | */ |
||
| 17 | protected $auth; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Create a new middleware instance. |
||
| 21 | * |
||
| 22 | * @param Guard $auth |
||
| 23 | * @return void |
||
| 24 | */ |
||
| 25 | public function __construct(Guard $auth) |
||
| 26 | { |
||
| 27 | $this->auth = $auth; |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Handle an incoming request. |
||
| 32 | * |
||
| 33 | * @param \Illuminate\Http\Request $request |
||
| 34 | * @param \Closure $next |
||
| 35 | * @return mixed |
||
| 36 | */ |
||
| 37 | public function handle($request, Closure $next) |
||
| 38 | { |
||
| 39 | // Low level way to only allow TT users |
||
| 40 | // this is not a safe way to handle security and is only used for convenience, not to secure page restriction!! |
||
| 41 | if (!$this->auth->user() || !$this->authorize('update-squanto')) { |
||
| 42 | if ($request->ajax()) { |
||
| 43 | return response('Unauthorized.', 401); |
||
| 44 | } else { |
||
| 45 | return redirect()->guest('admin/login'); |
||
| 46 | } |
||
| 47 | } |
||
| 48 | |||
| 49 | return $next($request); |
||
| 50 | } |
||
| 52 |