调整修改密码接口
This commit is contained in:
parent
b7b87d406c
commit
7a97610ca9
|
|
@ -73,12 +73,13 @@ public class UserController {
|
||||||
*/
|
*/
|
||||||
@PostMapping("/changePwd")
|
@PostMapping("/changePwd")
|
||||||
public Object changePwd(@RequestBody Map<String, String> params) {
|
public Object changePwd(@RequestBody Map<String, String> params) {
|
||||||
|
Assert.notNull(params.get("oldPassword"), "oldPassword参数缺失");
|
||||||
Assert.notNull(params.get("password"), "password参数缺失");
|
Assert.notNull(params.get("password"), "password参数缺失");
|
||||||
if(!Pattern.matches("^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$", params.get("password"))){
|
if(!Pattern.matches("^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$", params.get("password"))){
|
||||||
throw new OperateException("密码必须是6-20字母+数字组合!");
|
throw new OperateException("密码必须是6-20字母+数字组合!");
|
||||||
}
|
}
|
||||||
Integer userId = LikeFrontThreadLocal.getUserId();
|
Integer userId = LikeFrontThreadLocal.getUserId();
|
||||||
iUserService.changePwd(params.get("password"), userId);
|
iUserService.changePwd(params.get("password"), params.get("oldPassword"), userId);
|
||||||
return AjaxResult.success();
|
return AjaxResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,9 +42,10 @@ public interface IUserService {
|
||||||
*
|
*
|
||||||
* @author fzr
|
* @author fzr
|
||||||
* @param password 新密码
|
* @param password 新密码
|
||||||
|
* @param oldPassword 旧密码
|
||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
*/
|
*/
|
||||||
void changePwd(String password, Integer userId);
|
void changePwd(String password, String oldPassword, Integer userId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 绑定手机
|
* 绑定手机
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import com.mdd.front.vo.user.UserInfoVo;
|
||||||
import me.chanjar.weixin.common.error.WxErrorException;
|
import me.chanjar.weixin.common.error.WxErrorException;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
|
@ -172,15 +173,28 @@ public class UserServiceImpl implements IUserService {
|
||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void changePwd(String password, Integer userId) {
|
public void changePwd(String password, String oldPassword, Integer userId) {
|
||||||
|
User user = userMapper.selectOne(new QueryWrapper<User>()
|
||||||
|
.select("id,password,salt")
|
||||||
|
.eq("id", userId)
|
||||||
|
.eq("is_delete", 0)
|
||||||
|
.last("limit 1"));
|
||||||
|
|
||||||
|
Assert.notNull(user, "用户不存在");
|
||||||
|
String oldPwd = ToolsUtil.makeMd5(oldPassword.trim()+user.getSalt());
|
||||||
|
if (!oldPwd.equals(user.getPassword())) {
|
||||||
|
throw new OperateException("原密码不正确!");
|
||||||
|
}
|
||||||
|
|
||||||
String salt = ToolsUtil.randomString(5);
|
String salt = ToolsUtil.randomString(5);
|
||||||
String pwd = ToolsUtil.makeMd5(password.trim()+salt);
|
String pwd = ToolsUtil.makeMd5(password.trim()+salt);
|
||||||
|
|
||||||
User user = new User();
|
User u = new User();
|
||||||
user.setPassword(pwd);
|
u.setId(userId);
|
||||||
user.setSalt(salt);
|
u.setPassword(pwd);
|
||||||
user.setUpdateTime(System.currentTimeMillis() / 1000);
|
u.setSalt(salt);
|
||||||
userMapper.updateById(user);
|
u.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||||
|
userMapper.updateById(u);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue