HighSpeaker/.history/app/middleware/Auth_20221223195107.php
2022-12-24 22:10:40 +08:00

23 lines
618 B
PHP

<?php
namespace app\middleware;
use Webman\MiddlewareInterface;
use Webman\Http\Response;
use Webman\Http\Request;
class Auth implements MiddlewareInterface
{
public function process(Request $request, callable $handler) : Response
{
$session = $request->session();
// 用户未登录
if (!$session->get('userinfo')) {
// 拦截请求,返回一个重定向响应,请求停止向洋葱芯穿越
$to=$request->uri();
return redirect('/login?to='.$to);
}
// 请求继续向洋葱芯穿越
return $handler($request);
}
}