增加修改密码

This commit is contained in:
TinyAnts 2022-09-08 14:53:01 +08:00
parent fb86e38040
commit 027fc078cb
4 changed files with 47 additions and 1 deletions

View File

@ -64,6 +64,24 @@ public class UserController {
return AjaxResult.success();
}
/**
* 修改密码
*
* @author fzr
* @param params 参数
* @return Object
*/
@PostMapping("/changePwd")
public Object changePwd(@RequestBody Map<String, String> params) {
Assert.notNull(params.get("password"), "password参数缺失");
if(!Pattern.matches("^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$", params.get("password"))){
throw new OperateException("密码必须是6-20字母+数字组合!");
}
Integer userId = LikeFrontThreadLocal.getUserId();
iUserService.changePwd(params.get("password"), userId);
return AjaxResult.success();
}
/**
* 绑定手机号
*

View File

@ -37,6 +37,15 @@ public interface IUserService {
*/
void edit(Map<String, String> params, Integer userId);
/**
* 修改密码
*
* @author fzr
* @param password 新密码
* @param userId 用户ID
*/
void changePwd(String password, Integer userId);
/**
* 绑定手机
*

View File

@ -163,6 +163,25 @@ public class UserServiceImpl implements IUserService {
}
}
/**
* 修改密码
*
* @author fzr
* @param password 新密码
* @param userId 用户ID
*/
@Override
public void changePwd(String password, Integer userId) {
String salt = ToolsUtil.randomString(5);
String pwd = ToolsUtil.makeMd5(password.trim()+salt);
User user = new User();
user.setPassword(pwd);
user.setSalt(salt);
user.setUpdateTime(System.currentTimeMillis() / 1000);
userMapper.updateById(user);
}
/**
* 绑定手机
*

View File

@ -25,7 +25,7 @@ public class RegParam implements Serializable {
@NotEmpty(message = "账号不能为空")
@Length(min = 3, max = 12, message = "账号必须在3~12个字符内")
@Pattern(message = "账号只允许是字母和数字", regexp="^[A-Za-z0-9]+$")
@Pattern(message = "账号应该为3-12位字组合", regexp="^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{3,12}$")
@Pattern(message = "账号应该为3-12位字、字组合", regexp="^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{3,12}$")
private String username;
@NotNull(message = "password参数缺失")