|
@@ -67,10 +67,11 @@ public class AuthController {
|
|
String verifyCode = ValidateCodeGenerator.generateVerifyCode(4);
|
|
String verifyCode = ValidateCodeGenerator.generateVerifyCode(4);
|
|
System.out.println(verifyCode);
|
|
System.out.println(verifyCode);
|
|
|
|
|
|
- VerifyCodeBean verifyCodeBean = this.verifyCodeService.add(VerifyCodeBean.builder().type(VerifyCodeType.IMG).verified(VerifyCodeStatus.UN_VERIFY).expireTime(verifyCodeExpireTime).verifyCode(verifyCode).build());
|
|
|
|
|
|
+ VerifyCodeBean verifyCodeBean = this.verifyCodeService.add(VerifyCodeBean.builder()
|
|
|
|
+ .type(VerifyCodeType.IMG).verified(VerifyCodeStatus.UN_VERIFY).expireTime(verifyCodeExpireTime).verifyCode(verifyCode).build());
|
|
|
|
|
|
|
|
+ //存入redis
|
|
redisTemplate.opsForValue().set("verifyCodeBean", verifyCodeBean);
|
|
redisTemplate.opsForValue().set("verifyCodeBean", verifyCodeBean);
|
|
- //request.getSession().setAttribute("verifyCodeBean", verifyCodeBean);
|
|
|
|
|
|
|
|
response.setContentType("application/force-download");
|
|
response.setContentType("application/force-download");
|
|
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(verifyCode, "UTF-8"));
|
|
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(verifyCode, "UTF-8"));
|
|
@@ -82,12 +83,11 @@ public class AuthController {
|
|
@RequestMapping
|
|
@RequestMapping
|
|
public Object login(UserBean userBean, HttpServletRequest request) {
|
|
public Object login(UserBean userBean, HttpServletRequest request) {
|
|
|
|
|
|
-
|
|
|
|
//校验验证码是否正确
|
|
//校验验证码是否正确
|
|
if (this.verifyCodeCheck) {
|
|
if (this.verifyCodeCheck) {
|
|
|
|
|
|
|
|
+ //获取redis中的验证码对象
|
|
VerifyCodeBean verifyCodeBean = (VerifyCodeBean) redisTemplate.opsForValue().get("verifyCodeBean");
|
|
VerifyCodeBean verifyCodeBean = (VerifyCodeBean) redisTemplate.opsForValue().get("verifyCodeBean");
|
|
- // VerifyCodeBean verifyCodeBean = (VerifyCodeBean) request.getSession().getAttribute("verifyCodeBean");
|
|
|
|
|
|
|
|
if (verifyCodeBean == null) {
|
|
if (verifyCodeBean == null) {
|
|
return ParamErrorResultBuilder.newBuilder().paramError("verifyCode", "没有获取到验证码").build();
|
|
return ParamErrorResultBuilder.newBuilder().paramError("verifyCode", "没有获取到验证码").build();
|
|
@@ -105,14 +105,10 @@ public class AuthController {
|
|
return ParamErrorResultBuilder.newBuilder().paramError("verifyCode", "没有获取到验证码").build();
|
|
return ParamErrorResultBuilder.newBuilder().paramError("verifyCode", "没有获取到验证码").build();
|
|
}
|
|
}
|
|
|
|
|
|
- // String verifyCode = verifyCodeBean.getVerifyCode();
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- //判断有效期
|
|
|
|
-// if ((System.currentTimeMillis() - verifyCodeBean.getCreateTime().getTime()) > verifyCodeBean.getExpireTime()) {
|
|
|
|
-// return ParamErrorResultBuilder.newBuilder().paramError("verifyCode", "验证码已过期").build();
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
|
|
+ // 判断有效期
|
|
|
|
+ if ((System.currentTimeMillis() - verifyCodeBean.getCreateTime().getTime()) > verifyCodeBean.getExpireTime()) {
|
|
|
|
+ return ParamErrorResultBuilder.newBuilder().paramError("verifyCode", "验证码已过期").build();
|
|
|
|
+ }
|
|
|
|
|
|
if (!verifyCode.toLowerCase().equals(userBean.getVerifyCode().toLowerCase())) {
|
|
if (!verifyCode.toLowerCase().equals(userBean.getVerifyCode().toLowerCase())) {
|
|
return ParamErrorResultBuilder.newBuilder().paramError("verifyCode", "验证码错误").build();
|
|
return ParamErrorResultBuilder.newBuilder().paramError("verifyCode", "验证码错误").build();
|
|
@@ -127,11 +123,11 @@ public class AuthController {
|
|
return ResponseBean.serverError("账号或密码错误");
|
|
return ResponseBean.serverError("账号或密码错误");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //删除redis中的验证码对象
|
|
redisTemplate.delete("verifyCodeBean");
|
|
redisTemplate.delete("verifyCodeBean");
|
|
- //request.getSession().removeAttribute("verifyCodeBean");
|
|
|
|
|
|
|
|
|
|
+ //将登录用户村热redis
|
|
redisTemplate.opsForValue().set("userBean", userBean);
|
|
redisTemplate.opsForValue().set("userBean", userBean);
|
|
- // request.getSession().setAttribute("userBean", userBean);
|
|
|
|
|
|
|
|
return ResponseBean.success("登录成功").addData("userBean", userBean);
|
|
return ResponseBean.success("登录成功").addData("userBean", userBean);
|
|
}
|
|
}
|
|
@@ -145,7 +141,6 @@ public class AuthController {
|
|
public Object updateUserPassword(String newPassword, String oldPassword, HttpServletRequest request) {
|
|
public Object updateUserPassword(String newPassword, String oldPassword, HttpServletRequest request) {
|
|
|
|
|
|
UserBean userBean = (UserBean) redisTemplate.opsForValue().get("userBean");
|
|
UserBean userBean = (UserBean) redisTemplate.opsForValue().get("userBean");
|
|
- // UserBean userBean = (UserBean) request.getSession().getAttribute("userBean");
|
|
|
|
|
|
|
|
if (userBean == null) {
|
|
if (userBean == null) {
|
|
return ResponseBean.unAuthorize("您未登录");
|
|
return ResponseBean.unAuthorize("您未登录");
|
|
@@ -161,7 +156,7 @@ public class AuthController {
|
|
|
|
|
|
this.logout(request);
|
|
this.logout(request);
|
|
|
|
|
|
- return ResponseBean.success("密码修改成功,请退出重新登录!");
|
|
|
|
|
|
+ return ResponseBean.success("密码修改成功,请重新登录!");
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -180,7 +175,6 @@ public class AuthController {
|
|
return ResponseBean.unAuthorize("您未登录");
|
|
return ResponseBean.unAuthorize("您未登录");
|
|
}
|
|
}
|
|
|
|
|
|
- //request.getSession().invalidate();
|
|
|
|
redisTemplate.delete("userBean");
|
|
redisTemplate.delete("userBean");
|
|
|
|
|
|
return ResponseBean.serverError("退出成功!");
|
|
return ResponseBean.serverError("退出成功!");
|