Auth.php 904 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2021 勾股工作室
  4. * @license https://opensource.org/licenses/Apache-2.0
  5. * @link https://www.gougucms.com
  6. */
  7. declare (strict_types = 1);
  8. namespace app\home\middleware;
  9. use think\facade\Session;
  10. class Auth
  11. {
  12. public function handle($request, \Closure $next)
  13. {
  14. //获取模块名称
  15. $controller = app('http')->getName();
  16. $pathInfo = str_replace('.' . $request->ext(), '', $request->pathInfo());
  17. $action = explode('/', $pathInfo)[0];
  18. // var_dump($pathInfo);
  19. //验证用户登录
  20. if ($action == 'user') {
  21. $session_user = get_config('app.session_user');
  22. if (!Session::has($session_user)) {
  23. return $request->isAjax() ? to_assign(404, '请先登录') : redirect((string) url('/home/login/index'));
  24. }
  25. }
  26. return $next($request);
  27. }
  28. }