You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Malio/app/Middleware/Admin.php

28 lines
682 B
PHTML

9 years ago
<?php
namespace App\Middleware;
use App\Services\Auth as AuthService;
class Admin
{
/**
* @param \Slim\Http\Request $request
* @param \Slim\Http\Response $response
* @param callable $next
*
* @return \Slim\Http\Response
*/
public function __invoke($request, $response, $next)
9 years ago
{
$user = AuthService::getUser();
if (!$user->isLogin) {
return $response->withStatus(302)->withHeader('Location', '/auth/login');
9 years ago
}
if (!$user->isAdmin()) {
return $response->withStatus(302)->withHeader('Location', '/user');
9 years ago
}
return $next($request, $response);
9 years ago
}
}