IYUUPlus/app/middleware/AuthCheck.php
2022-10-05 22:32:55 +08:00

31 lines
986 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\middleware;
use Webman\MiddlewareInterface;
use Webman\Http\Response;
use Webman\Http\Request;
use app\common\Constant;
/**
* [中间件] 拦截未登录的Session
* @access private 常驻内存运行,禁止执行器调用
*/
class AuthCheck implements MiddlewareInterface
{
public function process(Request $request, callable $next): Response
{
$session = $request->session();
$action = $request->action;
$skip = in_array($action, Constant::Skip_AuthCheck); // 严格区分大小写
if ($skip || $session->get(Constant::Session_Token_Key)) {
//刷新SESSION修改时间避免被GC清除
$session->set('last_time', time());
// 不拦截账号登录、检查登录、绑定token、存在Session等
return $next($request);
}
// 拦截条件token不存在Session未登录 & 非指定的操作
return redirect('/page/login.html');
}
}