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.
29 lines
826 B
PHP
29 lines
826 B
PHP
<?php
|
|
|
|
namespace App\Middleware;
|
|
|
|
use App\Services\Auth as AuthService;
|
|
|
|
class Auth
|
|
{
|
|
/**
|
|
* @param \Slim\Http\Request $request
|
|
* @param \Slim\Http\Response $response
|
|
* @param callable $next
|
|
*
|
|
* @return \Slim\Http\Response
|
|
*/
|
|
public function __invoke($request, $response, $next)
|
|
{
|
|
$user = AuthService::getUser();
|
|
if (!$user->isLogin) {
|
|
return $response->withStatus(302)->withHeader('Location', '/auth/login');
|
|
}
|
|
$enablePages = array('/user/disable', '/user/backtoadmin', '/user/logout');
|
|
if ($user->enable == 0 && !in_array($_SERVER['REQUEST_URI'], $enablePages)) {
|
|
return $response->withStatus(302)->withHeader('Location', '/user/disable');
|
|
}
|
|
return $next($request, $response);
|
|
}
|
|
}
|