重置密码的新密码不能与原密码相同

master
panqihua 5 years ago
parent e336d30461
commit f4b06b0fdd
  1. 7
      src/main/java/com/community/pocket/api/android/UserController.java
  2. 3
      src/main/java/com/community/pocket/entity/vo/android/ResetPwdResponse.java
  3. 21
      src/main/java/com/community/pocket/repository/android/UserDao.java

@ -99,13 +99,18 @@ public class UserController {
*/
@PostMapping("/resetpwd/resetPwd")
public ResetPwdResponse resetPwd(UserResetPwd userResetPwd) {
if(userDao.resetPwd(userResetPwd.getUsername(),userResetPwd.getPassword())){
if (userDao.isNotDiffPwd(userResetPwd)) {
return new ResetPwdResponse(Result.FAIL, ResetPwdResponse.Msg.step3_diff_password);
} else {
if (userDao.resetPwd(userResetPwd)) {
return new ResetPwdResponse(Result.OK, ResetPwdResponse.Msg.step3_ok);
} else {
return new ResetPwdResponse(Result.FAIL, ResetPwdResponse.Msg.step3_fail);
}
}
}
/**
* 用户登录
* @param username 用户

@ -20,6 +20,7 @@ public class ResetPwdResponse extends Response<ResetPwdResponse.Msg> {
step2_valid_ok,
step2_valid_fail,
step3_ok,
step3_fail
step3_fail,
step3_diff_password
}
}

@ -7,6 +7,7 @@ import com.community.pocket.entity.vo.android.*;
import com.community.pocket.entity.vo.web.EditScore;
import com.community.pocket.repository.BaseDao;
import com.community.pocket.repository.CreditScoreDao;
import com.community.pocket.repository.EmailDao;
import com.community.pocket.util.LookupOperationUtil;
import com.mongodb.client.result.UpdateResult;
import org.slf4j.Logger;
@ -35,6 +36,9 @@ public class UserDao extends BaseDao<MyInfo> {
@Autowired
private CreditScoreDao creditScoreDao;
@Autowired
private EmailDao emailDao;
@Value("${register.credit-score}")
private int creditScore;
@ -131,11 +135,22 @@ public class UserDao extends BaseDao<MyInfo> {
}
//检查新密码是否和原密码重复
public boolean isNotDiffPwd(UserResetPwd userResetPwd) {
String md5Password = DigestUtils.md5DigestAsHex(userResetPwd.getPassword().getBytes());
MyInfo myInfo = mongoTemplate.findById(userResetPwd.getUsername(), entityClass());
return myInfo != null && myInfo.getPassword().equals(md5Password) && emailDao.clearEmail(myInfo.getEmail());
}
//重置密码
public boolean resetPwd(String username,String password){
if(!StringUtils.isEmpty(username)&&!StringUtils.isEmpty(password)){
public boolean resetPwd(UserResetPwd userResetPwd) {
String username = userResetPwd.getUsername();
String password = userResetPwd.getPassword();
String md5Password = DigestUtils.md5DigestAsHex(password.getBytes());
UpdateResult result=mongoTemplate.updateFirst(new Query().addCriteria(Criteria.where("username").is(username)), Update.update("password",md5Password),entityClass());
if (!StringUtils.isEmpty(username) && !StringUtils.isEmpty(md5Password)) {
UpdateResult result = mongoTemplate.updateFirst(new Query().addCriteria(
Criteria.where("username").is(username)),
Update.update("password", md5Password), entityClass());
return result.wasAcknowledged();
} else {
return false;

Loading…
Cancel
Save