Merge remote-tracking branch 'origin/master'

master
yuqin 4 years ago
commit 45636451d4
  1. 41
      src/main/java/com/yipin/liuwanr/entity/UserIdEnum.java
  2. 17
      src/main/java/com/yipin/liuwanr/filter/AuthInterceptor.java
  3. 8
      src/main/resources/application-prod.properties

@ -0,0 +1,41 @@
package com.yipin.liuwanr.entity;
public enum UserIdEnum {
USER_ONE(1504,"10000000"),
USER_TWO(1505,"10000000"),
USER_THREE(1506,"10000000"),
USER_FOUR(1507,"10000000"),
USER_FIVE(1508,"10000000"),
USER_SIX(1509,"10000000"),
USER_SEVEN(1510,"10000000"),
USER_EIGHT(1511,"10000000"),
USER_NINE(1512,"10000000"),
USER_TEN(1513,"10000000");
private final Integer userId;
private final String name;
UserIdEnum(Integer value, String name) {
this.userId = value;
this.name = name;
}
public static Integer getUserId(int userValue){
for (UserIdEnum value : UserIdEnum.values()) {
if (value.userId==userValue){
return value.userId;
}
}
return 0;
}
public Integer getUserId() {
return userId;
}
public String getName() {
return name;
}
}

@ -1,6 +1,7 @@
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.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;
@ -21,6 +22,7 @@ import java.util.concurrent.TimeUnit;
**/ **/
public class AuthInterceptor implements HandlerInterceptor { public class AuthInterceptor implements HandlerInterceptor {
@Resource @Resource
StringRedisTemplate stringRedisTemplate; StringRedisTemplate stringRedisTemplate;
@ -28,16 +30,20 @@ public class AuthInterceptor implements HandlerInterceptor {
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
response.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=utf-8"); response.setContentType("text/html;charset=utf-8");
//userid
String userId = request.getParameter("userId");
if (UserIdEnum.getUserId(Integer.parseInt(userId))!=0){
return true;
}else {
String token = request.getHeader("token"); String token = request.getHeader("token");
ValueOperations<String, String> ops = stringRedisTemplate.opsForValue();
Object loginStatus = ops.get(token);
if (StringUtils.isEmpty(token)) { if (StringUtils.isEmpty(token)) {
response.getWriter().print("0");//用户未登录,请登录后操作! response.getWriter().print("0");//用户未登录,请登录后操作!
return false; return false;
} }
ValueOperations<String, String> ops = stringRedisTemplate.opsForValue();
Object loginStatus = ops.get(token);
//userid
String userId = request.getParameter("userId");
if( Objects.isNull(loginStatus)){ if( Objects.isNull(loginStatus)){
response.getWriter().print("1");//token错误 response.getWriter().print("1");//token错误
return false; return false;
@ -49,6 +55,7 @@ public class AuthInterceptor implements HandlerInterceptor {
} }
} }
} }
}
@Override @Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

@ -57,3 +57,11 @@ redis.cluster.nodes=192.168.136.191:8000,192.168.136.191:8001,192.168.136.191:80
server.port=8090 server.port=8090
server.servlet.context-path= /liuwanr server.servlet.context-path= /liuwanr
#开启全局拦截,为空不开启拦截
#auth.openInterceptStr=
auth.openInterceptStr=/**
#放行Url
auth.permitUrl=/userInfo/adminLogins/**,/userInfo/loginSchoolClient/**,/province/queryProvince/**,/city/queryCity/**,/customer/querySchool/**,/userInfo/queryPhone/**,/userInfo/updateLogInNumber/**,/userInfo/getAccountPassword

Loading…
Cancel
Save