Auth.php 875 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace app\http\middleware;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. class Auth
  6. {
  7. public function handle($request, \Closure $next)
  8. {
  9. $token = $request->param('token');
  10. $userId = $request->param('userId');
  11. if(empty($token) || empty($userId)){
  12. HelpHander::error('登录信息已失效',100200);
  13. }
  14. $tokeninfo = Db::name('token')
  15. ->where('code',$token)
  16. ->where('user_id',$userId)
  17. ->find();
  18. if(!$tokeninfo){
  19. HelpHander::error('登录信息已失效',100200);
  20. }
  21. // 检查用户是否被禁用
  22. $user = Db::name('user')->where('id',$userId)->find();
  23. if(!$user || $user['enable'] == 0 || $user['del'] == 1){
  24. HelpHander::error('登录信息已失效',100200);
  25. }
  26. return $next($request);
  27. }
  28. }