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

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

@ -99,11 +99,16 @@ public class UserController {
*/
@PostMapping("/resetpwd/resetPwd")
public ResetPwdResponse resetPwd(UserResetPwd userResetPwd) {
if(userDao.resetPwd(userResetPwd.getUsername(),userResetPwd.getPassword())){
return new ResetPwdResponse(Result.OK, ResetPwdResponse.Msg.step3_ok);
}else{
return new ResetPwdResponse(Result.FAIL, ResetPwdResponse.Msg.step3_fail);
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);
}
}
}
/**

@ -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;
@ -122,22 +126,33 @@ public class UserDao extends BaseDao<MyInfo> {
}
//检查用户和邮箱是否对应
public boolean hasUseWithEmail(String username, String email){
if(!StringUtils.isEmpty(username)&&!StringUtils.isEmpty(email)){
return mongoTemplate.exists(new Query().addCriteria(Criteria.where("username").is(username).and("email").is(email)),entityClass());
}else{
public boolean hasUseWithEmail(String username, String email) {
if (!StringUtils.isEmpty(username) && !StringUtils.isEmpty(email)) {
return mongoTemplate.exists(new Query().addCriteria(Criteria.where("username").is(username).and("email").is(email)), entityClass());
} else {
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){
if(!StringUtils.isEmpty(username)&&!StringUtils.isEmpty(password)){
String md5Password= DigestUtils.md5DigestAsHex(password.getBytes());
UpdateResult result=mongoTemplate.updateFirst(new Query().addCriteria(Criteria.where("username").is(username)), Update.update("password",md5Password),entityClass());
public boolean resetPwd(UserResetPwd userResetPwd) {
String username = userResetPwd.getUsername();
String password = userResetPwd.getPassword();
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();
}else{
} else {
return false;
}
}

Loading…
Cancel
Save