Commit 44e3a8d0 by xiaolang850403

增加token校验

parent 78086f7c
...@@ -204,8 +204,8 @@ public class UserController { ...@@ -204,8 +204,8 @@ public class UserController {
if (result.hasErrors()) { if (result.hasErrors()) {
return ResultUtil.Validated(result); return ResultUtil.Validated(result);
} }
String pass = MD5Util.getEncryption(user.getPassword()); //String pass = MD5Util.getEncryption(user.getPassword());
user.setPassword(pass); //user.setPassword(pass);
userService.updateById(user); userService.updateById(user);
if(user.getId() != null){ if(user.getId() != null){
//删除凭证的旧数据 //删除凭证的旧数据
......
...@@ -57,13 +57,13 @@ public class AdminController { ...@@ -57,13 +57,13 @@ public class AdminController {
public final String refuse = "审核不通过,原因:"; public final String refuse = "审核不通过,原因:";
@RequestMapping(value = "/getUserList") @RequestMapping(value = "/getUserList")
public Result getUserList(@RequestParam(defaultValue = "1") int currentPage, @RequestParam(defaultValue = "10") int per, User user) { public Result getUserList(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int per, User user) {
QueryWrapper<User> queryWrapper = new QueryWrapper<>(); QueryWrapper<User> queryWrapper = new QueryWrapper<>();
if(user.getState() != null){ if(user.getState() != null){
queryWrapper.eq("state",user.getState()).or().eq("name",user.getName()).or().eq("mobile",user.getMobile()).or().eq("email",user.getEmail()).or().eq("employer",user.getEmployer()); queryWrapper.eq("state",user.getState()).or().eq("name",user.getName()).or().eq("mobile",user.getMobile()).or().eq("email",user.getEmail()).or().eq("employer",user.getEmployer());
} }
//List list = userService.list(queryWrapper); //List list = userService.list(queryWrapper);
PageHelper.startPage(currentPage, per); PageHelper.startPage(page, per);
Map map = Pagination.Pagination(userService.list(queryWrapper)); Map map = Pagination.Pagination(userService.list(queryWrapper));
return ResultUtil.success(CodeEnum.SUCCESS,map); return ResultUtil.success(CodeEnum.SUCCESS,map);
} }
......
...@@ -27,7 +27,7 @@ public class FailLogController { ...@@ -27,7 +27,7 @@ public class FailLogController {
@GetMapping("/getFailLogByUid") @GetMapping("/getFailLogByUid")
public Result getFailLogByUid(int user_id) { public Result getFailLogByUid(int user_id) {
QueryWrapper<FailLog> queryWrapper = new QueryWrapper<>(); QueryWrapper<FailLog> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("userid",user_id); queryWrapper.eq("user_id",user_id);
List<FailLog> list = failLogService.list(queryWrapper); List<FailLog> list = failLogService.list(queryWrapper);
return ResultUtil.success(CodeEnum.SUCCESS,list); return ResultUtil.success(CodeEnum.SUCCESS,list);
} }
......
...@@ -24,9 +24,9 @@ public class AreaController { ...@@ -24,9 +24,9 @@ public class AreaController {
AreaService areaService; AreaService areaService;
@GetMapping("/getAreaList") @GetMapping("/getAreaList")
public Result getAreaList(int pid) { public Result getAreaList(int id) {
QueryWrapper<Area> queryWrapper = new QueryWrapper<>(); QueryWrapper<Area> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("pid",pid); queryWrapper.eq("pid",id);
List<Area> list = areaService.list(queryWrapper); List<Area> list = areaService.list(queryWrapper);
return ResultUtil.success(CodeEnum.SUCCESS,list); return ResultUtil.success(CodeEnum.SUCCESS,list);
} }
......
package com.asset.core.enums.filter; package com.asset.core.filter;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
......
...@@ -53,6 +53,7 @@ public class TokenInterceptor implements HandlerInterceptor { ...@@ -53,6 +53,7 @@ public class TokenInterceptor implements HandlerInterceptor {
queryWrapper.eq("mobile",mobile); queryWrapper.eq("mobile",mobile);
User user = userService.getOne(queryWrapper); User user = userService.getOne(queryWrapper);
//比较数据库里token的refexpire的最长期限 //比较数据库里token的refexpire的最长期限
if(user!=null){
if(Common.getStringToDate(user.getLoginTime())+Long.valueOf(user.getRefexpire()) > System.currentTimeMillis()){ if(Common.getStringToDate(user.getLoginTime())+Long.valueOf(user.getRefexpire()) > System.currentTimeMillis()){
System.out.println("刷新token,生成新的token"); System.out.println("刷新token,生成新的token");
token = TokenUtil.sign(mobile.toString()); token = TokenUtil.sign(mobile.toString());
...@@ -72,6 +73,8 @@ public class TokenInterceptor implements HandlerInterceptor { ...@@ -72,6 +73,8 @@ public class TokenInterceptor implements HandlerInterceptor {
response.getWriter().append(json.toJSONString()); response.getWriter().append(json.toJSONString());
return false; return false;
} }
}
return false;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
response.sendError(500); response.sendError(500);
......
...@@ -23,6 +23,11 @@ public class JWTConfiguration implements WebMvcConfigurer { ...@@ -23,6 +23,11 @@ public class JWTConfiguration implements WebMvcConfigurer {
System.out.println("*****"); System.out.println("*****");
List<String> excludePath = new ArrayList<>(); List<String> excludePath = new ArrayList<>();
//对以下资源请求不进行拦截和验证 //对以下资源请求不进行拦截和验证
excludePath.add("/user/register");
excludePath.add("/upload/oss");
excludePath.add("/area/getAreaList");
excludePath.add("/job/getJobList");
excludePath.add("/user/checkMobile");
excludePath.add("/login"); //登录 excludePath.add("/login"); //登录
registry.addInterceptor(tokenInterceptor) registry.addInterceptor(tokenInterceptor)
......
...@@ -8,8 +8,8 @@ import com.auth0.jwt.algorithms.Algorithm; ...@@ -8,8 +8,8 @@ import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.interfaces.DecodedJWT; import com.auth0.jwt.interfaces.DecodedJWT;
public class TokenUtil { public class TokenUtil {
//过期时间 //过期时间(10小时)
private static final long EXPIRE_TIME = 1 * 60 * 1000; private static final long EXPIRE_TIME = 1 * 60 * 60 * 1000;
//使用静态的字符密文或者key来获取算法器,token秘钥,请勿泄露,请勿随便修改 //使用静态的字符密文或者key来获取算法器,token秘钥,请勿泄露,请勿随便修改
private static final String TOKEN_SECRET = "expert"; //密钥盐 private static final String TOKEN_SECRET = "expert"; //密钥盐
......
...@@ -97,22 +97,22 @@ public class User implements Serializable { ...@@ -97,22 +97,22 @@ public class User implements Serializable {
private String expertTypeValue; private String expertTypeValue;
@TableField(exist = false) @TableField(exist = false)
private String expert; //专家凭证 private String expert; //专家凭证(入库用)
@TableField(exist = false) @TableField(exist = false)
private String recom; //推荐凭证 private String recom; //推荐凭证(入库用)
@TableField(exist = false) @TableField(exist = false)
private String other; //其他凭证 private String other; //其他凭证(入库用)
@TableField(exist = false) @TableField(exist = false)
private List reexpert; //专家凭证 private List reexpert; //专家凭证(展示)
@TableField(exist = false) @TableField(exist = false)
private List rerecom; //推荐凭证 private List rerecom; //推荐凭证(展示)
@TableField(exist = false) @TableField(exist = false)
private List reother; //其他凭证 private List reother; //其他凭证(展示)
private String expertRange; private String expertRange;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment