|
|
@ -1,8 +1,6 @@ |
|
|
|
package com.yipin.liuwanr.filter; |
|
|
|
package com.yipin.liuwanr.filter; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.yipin.liuwanr.entity.UserIdEnum; |
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate; |
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate; |
|
|
|
import org.springframework.data.redis.core.ValueOperations; |
|
|
|
import org.springframework.data.redis.core.ValueOperations; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
@ -13,7 +11,6 @@ import javax.annotation.Resource; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.util.Objects; |
|
|
|
import java.util.Objects; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @description |
|
|
|
* @description |
|
|
@ -31,28 +28,23 @@ public class AuthInterceptor implements HandlerInterceptor { |
|
|
|
response.setCharacterEncoding("UTF-8"); |
|
|
|
response.setCharacterEncoding("UTF-8"); |
|
|
|
response.setContentType("text/html;charset=utf-8"); |
|
|
|
response.setContentType("text/html;charset=utf-8"); |
|
|
|
|
|
|
|
|
|
|
|
//userid
|
|
|
|
String token = request.getHeader("token"); |
|
|
|
String userId = request.getParameter("userId"); |
|
|
|
|
|
|
|
if (UserIdEnum.getUserId(Integer.parseInt(userId))!=0){ |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String token = request.getHeader("token"); |
|
|
|
if (StringUtils.isEmpty(token)) { |
|
|
|
ValueOperations<String, String> ops = stringRedisTemplate.opsForValue(); |
|
|
|
response.getWriter().print("0");//用户未登录,请登录后操作!
|
|
|
|
Object loginStatus = ops.get(token); |
|
|
|
return false; |
|
|
|
if (StringUtils.isEmpty(token)) { |
|
|
|
} |
|
|
|
response.getWriter().print("0");//用户未登录,请登录后操作!
|
|
|
|
ValueOperations<String, String> ops = stringRedisTemplate.opsForValue(); |
|
|
|
return false; |
|
|
|
Object loginStatus = ops.get(token); |
|
|
|
} |
|
|
|
if( Objects.isNull(loginStatus)){ |
|
|
|
if( Objects.isNull(loginStatus)){ |
|
|
|
response.getWriter().print("1");//token错误
|
|
|
|
response.getWriter().print("1");//token错误
|
|
|
|
return false; |
|
|
|
return false; |
|
|
|
}else { |
|
|
|
|
|
|
|
if (request.getRequestURI().contains("logins")){ |
|
|
|
|
|
|
|
String userId = request.getParameter("userId"); |
|
|
|
|
|
|
|
return userId.equals(loginStatus); |
|
|
|
}else { |
|
|
|
}else { |
|
|
|
if (!StringUtils.isEmpty(userId)){ |
|
|
|
return true; |
|
|
|
return userId.equals(loginStatus); |
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|