|
@@ -1,5 +1,9 @@
|
|
|
package com.ruoyi.web.controller.system;
|
|
|
|
|
|
+import com.ruoyi.common.constant.Constants;
|
|
|
+import com.ruoyi.common.core.redis.RedisCache;
|
|
|
+import com.ruoyi.web.controller.PwdCheckUtil;
|
|
|
+import org.assertj.core.util.Preconditions;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
@@ -24,6 +28,8 @@ import com.ruoyi.common.utils.file.MimeTypeUtils;
|
|
|
import com.ruoyi.framework.web.service.TokenService;
|
|
|
import com.ruoyi.system.service.ISysUserService;
|
|
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+
|
|
|
/**
|
|
|
* 个人信息 业务处理
|
|
|
*
|
|
@@ -39,6 +45,9 @@ public class SysProfileController extends BaseController
|
|
|
@Autowired
|
|
|
private TokenService tokenService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RedisCache redisCache;
|
|
|
+
|
|
|
/**
|
|
|
* 个人信息
|
|
|
*/
|
|
@@ -95,6 +104,9 @@ public class SysProfileController extends BaseController
|
|
|
@PostMapping("/updatePwd")
|
|
|
public AjaxResult updatePwd(String oldPassword, String newPassword)
|
|
|
{
|
|
|
+ if ("1".equals(checkStrongPwd(newPassword))) {
|
|
|
+ return AjaxResult.error("密码必须包含数字、大小写字母、特殊符号且大于8位");
|
|
|
+ }
|
|
|
LoginUser loginUser = getLoginUser();
|
|
|
String userName = loginUser.getUsername();
|
|
|
String password = loginUser.getPassword();
|
|
@@ -111,11 +123,46 @@ public class SysProfileController extends BaseController
|
|
|
// 更新缓存用户密码
|
|
|
loginUser.getUser().setPassword(SecurityUtils.encryptPassword(newPassword));
|
|
|
tokenService.setLoginUser(loginUser);
|
|
|
+
|
|
|
+ //将修改后的密码存入redis并设置有效时间60天
|
|
|
+ redisCache.setCacheObject(Constants.PASSWORD_USER+"-"+userName, "60", Constants.EFFECTIVE_DATE, TimeUnit.DAYS);
|
|
|
+
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
|
return AjaxResult.error("修改密码异常,请联系管理员");
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @PostMapping("/resetPwdLogin")
|
|
|
+ public AjaxResult resetPwdLogin(@RequestParam("userName") String userName,@RequestParam("oldPassword") String oldPassword,@RequestParam("newPassword") String newPassword) {
|
|
|
+ //userService.checkUserAllowed(user);
|
|
|
+ if ("admin".equals(userName)){
|
|
|
+ return AjaxResult.success("不允许操作超级管理员");
|
|
|
+ }
|
|
|
+ SysUser user = userService.selectUserByUserName(userName);
|
|
|
+ if (user == null){
|
|
|
+ return AjaxResult.success("当前用户不存在");
|
|
|
+ }
|
|
|
+ String password = user.getPassword();
|
|
|
+ if (!SecurityUtils.matchesPassword(oldPassword, password))
|
|
|
+ {
|
|
|
+ return AjaxResult.success("修改密码失败,旧密码错误");
|
|
|
+ }
|
|
|
+ if (SecurityUtils.matchesPassword(newPassword, password))
|
|
|
+ {
|
|
|
+ return AjaxResult.success("新密码不能与旧密码相同");
|
|
|
+ }
|
|
|
+
|
|
|
+ if ("1".equals(checkStrongPwd(newPassword))) {
|
|
|
+ return AjaxResult.success("密码必须包含数字、大小写字母、特殊符号且大于8位");
|
|
|
+ }
|
|
|
+ user.setPassword(SecurityUtils.encryptPassword(newPassword));
|
|
|
+ user.setUpdateBy(userName);
|
|
|
+ redisCache.setCacheObject(Constants.PASSWORD_USER+"-"+userName, "60", Constants.EFFECTIVE_DATE, TimeUnit.DAYS);
|
|
|
+ return toAjax(userService.resetUserPwd(userName, user.getPassword()));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 头像上传
|
|
|
*/
|
|
@@ -139,4 +186,26 @@ public class SysProfileController extends BaseController
|
|
|
}
|
|
|
return AjaxResult.error("上传图片异常,请联系管理员");
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief 检测密码复杂度是否为 强
|
|
|
+ * @param[in] password 密码字符串
|
|
|
+ * @return 符合长度要求 返回true
|
|
|
+ */
|
|
|
+ public static String checkStrongPwd(String pwd) {
|
|
|
+ try {
|
|
|
+ Preconditions.checkNotNull(pwd);
|
|
|
+ if (!PwdCheckUtil.checkPasswordLength(pwd, "8", null)
|
|
|
+ || !PwdCheckUtil.checkContainLowerCase(pwd)
|
|
|
+ || !PwdCheckUtil.checkContainUpperCase(pwd)
|
|
|
+ || !PwdCheckUtil.checkContainDigit(pwd)
|
|
|
+ || !PwdCheckUtil.checkContainSpecialChar(pwd)
|
|
|
+ ) {
|
|
|
+ return "1";
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return "0";
|
|
|
+ }
|
|
|
}
|