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

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

@ -99,13 +99,18 @@ public class UserController {
*/ */
@PostMapping("/resetpwd/resetPwd") @PostMapping("/resetpwd/resetPwd")
public ResetPwdResponse resetPwd(UserResetPwd userResetPwd) { 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); return new ResetPwdResponse(Result.OK, ResetPwdResponse.Msg.step3_ok);
}else{ } else {
return new ResetPwdResponse(Result.FAIL, ResetPwdResponse.Msg.step3_fail); return new ResetPwdResponse(Result.FAIL, ResetPwdResponse.Msg.step3_fail);
} }
} }
}
/** /**
* 用户登录 * 用户登录
* @param username 用户 * @param username 用户

@ -20,6 +20,7 @@ public class ResetPwdResponse extends Response<ResetPwdResponse.Msg> {
step2_valid_ok, step2_valid_ok,
step2_valid_fail, step2_valid_fail,
step3_ok, 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.entity.vo.web.EditScore;
import com.community.pocket.repository.BaseDao; import com.community.pocket.repository.BaseDao;
import com.community.pocket.repository.CreditScoreDao; import com.community.pocket.repository.CreditScoreDao;
import com.community.pocket.repository.EmailDao;
import com.community.pocket.util.LookupOperationUtil; import com.community.pocket.util.LookupOperationUtil;
import com.mongodb.client.result.UpdateResult; import com.mongodb.client.result.UpdateResult;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -35,6 +36,9 @@ public class UserDao extends BaseDao<MyInfo> {
@Autowired @Autowired
private CreditScoreDao creditScoreDao; private CreditScoreDao creditScoreDao;
@Autowired
private EmailDao emailDao;
@Value("${register.credit-score}") @Value("${register.credit-score}")
private int creditScore; private int creditScore;
@ -122,22 +126,33 @@ public class UserDao extends BaseDao<MyInfo> {
} }
//检查用户和邮箱是否对应 //检查用户和邮箱是否对应
public boolean hasUseWithEmail(String username, String email){ public boolean hasUseWithEmail(String username, String email) {
if(!StringUtils.isEmpty(username)&&!StringUtils.isEmpty(email)){ if (!StringUtils.isEmpty(username) && !StringUtils.isEmpty(email)) {
return mongoTemplate.exists(new Query().addCriteria(Criteria.where("username").is(username).and("email").is(email)),entityClass()); return mongoTemplate.exists(new Query().addCriteria(Criteria.where("username").is(username).and("email").is(email)), entityClass());
}else{ } else {
return false; return false;
} }
} }
//检查新密码是否和原密码重复
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){ public boolean resetPwd(UserResetPwd userResetPwd) {
if(!StringUtils.isEmpty(username)&&!StringUtils.isEmpty(password)){ String username = userResetPwd.getUsername();
String md5Password= DigestUtils.md5DigestAsHex(password.getBytes()); String password = userResetPwd.getPassword();
UpdateResult result=mongoTemplate.updateFirst(new Query().addCriteria(Criteria.where("username").is(username)), Update.update("password",md5Password),entityClass()); String md5Password = DigestUtils.md5DigestAsHex(password.getBytes());
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(); return result.wasAcknowledged();
}else{ } else {
return false; return false;
} }
} }

Loading…
Cancel
Save