修改密码、忘记密码接口修改

This commit is contained in:
tqzhang 2025-02-08 13:49:20 +08:00
parent cfd97c03d9
commit 7d3970198a
3 changed files with 119 additions and 84 deletions

View File

@ -29,8 +29,14 @@ public class CustInfoController extends BaseController {
@ApiOperation("小程序修改密码") @ApiOperation("小程序修改密码")
@PostMapping({"/change/password"}) @PostMapping({"/change/password"})
public AjaxResult changePassword(@Validated @RequestBody CustChangePasswordDTO content) { public AjaxResult changePassword(@Validated @RequestBody CustChangePasswordDTO content) {
this.custInfoService.custChangePassword(content); AjaxResult ajaxResult = new AjaxResult();
return success(); try {
ajaxResult = this.custInfoService.custChangePassword(content);
return ajaxResult;
} catch (Exception e) {
log.error("小程序修改密码异常", e);
return AjaxResult.error("小程序修改密码异常");
}
} }
@ApiOperation("忘记密码") @ApiOperation("忘记密码")
@ -38,8 +44,14 @@ public class CustInfoController extends BaseController {
public AjaxResult forgetPassword(@Validated @RequestBody CustForgetPasswordDTO content) { public AjaxResult forgetPassword(@Validated @RequestBody CustForgetPasswordDTO content) {
//content.setMobile(AesEncryptUtil.aesDecode(content.getMobile())); //content.setMobile(AesEncryptUtil.aesDecode(content.getMobile()));
//content.setNewPassword(AesEncryptUtil.aesDecode(content.getNewPassword())); //content.setNewPassword(AesEncryptUtil.aesDecode(content.getNewPassword()));
this.custInfoService.custForgetPassword(content); AjaxResult ajaxResult = new AjaxResult();
return success(); try {
ajaxResult = this.custInfoService.custForgetPassword(content);
return ajaxResult;
} catch (Exception e) {
log.error("忘记密码异常", e);
return AjaxResult.error("忘记密码异常");
}
} }
@ApiOperation(value = "获取支付二维码") @ApiOperation(value = "获取支付二维码")

View File

@ -1,5 +1,6 @@
package com.bonus.core.customer.service; package com.bonus.core.customer.service;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.core.customer.dto.CustChangePasswordDTO; import com.bonus.core.customer.dto.CustChangePasswordDTO;
import com.bonus.core.customer.dto.CustForgetPasswordDTO; import com.bonus.core.customer.dto.CustForgetPasswordDTO;
import com.bonus.core.customer.vo.CustInfoVo; import com.bonus.core.customer.vo.CustInfoVo;
@ -9,9 +10,9 @@ public interface CustInfoService {
CustInfoVo queryCustInfoDetail(CustInfo custInfo); CustInfoVo queryCustInfoDetail(CustInfo custInfo);
void custChangePassword(CustChangePasswordDTO content); AjaxResult custChangePassword(CustChangePasswordDTO content);
void custForgetPassword(CustForgetPasswordDTO content); AjaxResult custForgetPassword(CustForgetPasswordDTO content);
String getOrderQRCode(Integer sourceType, String paramValue); String getOrderQRCode(Integer sourceType, String paramValue);

View File

@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil;
import com.alibaba.nacos.shaded.javax.annotation.Nullable; import com.alibaba.nacos.shaded.javax.annotation.Nullable;
import com.bonus.common.core.constant.CacheConstants; import com.bonus.common.core.constant.CacheConstants;
import com.bonus.common.core.exception.ServiceException; import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.redis.service.RedisService; import com.bonus.common.redis.service.RedisService;
import com.bonus.constant.LeCodeUseSceneEnum; import com.bonus.constant.LeCodeUseSceneEnum;
import com.bonus.constant.LeConstants; import com.bonus.constant.LeConstants;
@ -27,6 +28,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.*; import java.util.*;
@Service @Service
@ -90,13 +92,17 @@ public class CustInfoServiceImpl implements CustInfoService {
public void custChangePassword(CustChangePasswordDTO content) { @Override
public AjaxResult custChangePassword(CustChangePasswordDTO content) {
AjaxResult ajaxResult = new AjaxResult();
CustInfo custInfoQuery = new CustInfo(); CustInfo custInfoQuery = new CustInfo();
custInfoQuery.setCustId(content.getCustId()); custInfoQuery.setCustId(content.getCustId());
CustInfo custInfo = custInfoMapper.selectOne(custInfoQuery); CustInfo custInfo = custInfoMapper.selectOne(custInfoQuery);
if (ObjectUtil.isNull(custInfo)) { if (ObjectUtil.isNull(custInfo)) {
log.error("小程序修改密码错误:人员不存在:" + String.valueOf(custInfo)); log.error("小程序修改密码错误:人员不存在:" + String.valueOf(custInfo));
throw new ServiceException("小程序修改密码错误:人员不存在"); // throw new ServiceException("小程序修改密码错误:人员不存在");
ajaxResult.put("msg", "小程序修改密码错误:人员不存在");
ajaxResult.put("code", "500");
} else { } else {
content.setOldPassword(AesEncryptUtil.aesDecode(content.getOldPassword())); content.setOldPassword(AesEncryptUtil.aesDecode(content.getOldPassword()));
content.setNewPassword(AesEncryptUtil.aesDecode(content.getNewPassword())); content.setNewPassword(AesEncryptUtil.aesDecode(content.getNewPassword()));
@ -104,20 +110,27 @@ public class CustInfoServiceImpl implements CustInfoService {
String newPassword = content.getNewPassword(); String newPassword = content.getNewPassword();
if (Objects.equals(oldPassword, newPassword)) { if (Objects.equals(oldPassword, newPassword)) {
log.error("小程序修改密码错误:两次密码不能一致"); log.error("小程序修改密码错误:两次密码不能一致");
throw new ServiceException("小程序修改密码错误:两次密码不能一致"); ajaxResult.put("msg", "小程序修改密码错误:两次密码不能一致");
ajaxResult.put("code", "500");
// throw new ServiceException("小程序修改密码错误:两次密码不能一致");
} else { } else {
BCryptPasswordEncoder bCrypt = new BCryptPasswordEncoder(); BCryptPasswordEncoder bCrypt = new BCryptPasswordEncoder();
if (!bCrypt.matches(oldPassword, custInfo.getPwd())) { if (!bCrypt.matches(oldPassword, custInfo.getPwd())) {
log.error("小程序修改密码错误:原密码不正确"); log.error("小程序修改密码错误:原密码不正确");
throw new ServiceException("小程序修改密码错误:原密码不正确"); ajaxResult.put("msg", "小程序修改密码错误:原密码不正确");
ajaxResult.put("code", "500");
// throw new ServiceException("小程序修改密码错误:原密码不正确");
} else { } else {
String password = bCrypt.encode(newPassword); String password = bCrypt.encode(newPassword);
custInfo.setPwd(password); custInfo.setPwd(password);
custInfoMapper.updateById(custInfo); custInfoMapper.updateById(custInfo);
this.custCasualApi.updateLoginState(content.getCustId(), content.getOpenid()); this.custCasualApi.updateLoginState(content.getCustId(), content.getOpenid());
ajaxResult.put("msg", "修改成功");
ajaxResult.put("code", "200");
} }
} }
} }
return ajaxResult;
} }
public static void main(String[] args) { public static void main(String[] args) {
@ -126,29 +139,38 @@ public class CustInfoServiceImpl implements CustInfoService {
System.out.println(flag); System.out.println(flag);
} }
public void custForgetPassword(CustForgetPasswordDTO content) { @Override
public AjaxResult custForgetPassword(CustForgetPasswordDTO content) {
// content.setMobile(AesEncryptUtil.aesDecode(content.getMobile())); // content.setMobile(AesEncryptUtil.aesDecode(content.getMobile()));
AjaxResult ajaxResult = new AjaxResult();
content.setNewPassword(AesEncryptUtil.aesDecode(content.getNewPassword())); content.setNewPassword(AesEncryptUtil.aesDecode(content.getNewPassword()));
SmsCodeVerifyDTO smsCodeVerifyDTO = new SmsCodeVerifyDTO(); SmsCodeVerifyDTO smsCodeVerifyDTO = new SmsCodeVerifyDTO();
smsCodeVerifyDTO.setTelephoneNumber(content.getMobile()); smsCodeVerifyDTO.setTelephoneNumber(content.getMobile());
smsCodeVerifyDTO.setCode(content.getCode()); smsCodeVerifyDTO.setCode(content.getCode());
if (!verifySmsCode(smsCodeVerifyDTO, CacheConstants.VERIFICATION_CODE)) { if (!verifySmsCode(smsCodeVerifyDTO, CacheConstants.VERIFICATION_CODE)) {
throw new ServiceException("验证码异常"); // throw new ServiceException("验证码异常");
ajaxResult.put("msg", "验证码异常");
ajaxResult.put("code", "500");
} else { } else {
CustInfo custInfoQuery = new CustInfo(); CustInfo custInfoQuery = new CustInfo();
custInfoQuery.setMobile(SM4EncryptUtils.sm4Encryptbyconfig(content.getMobile())); custInfoQuery.setMobile(SM4EncryptUtils.sm4Encryptbyconfig(content.getMobile()));
CustInfo custInfo = custInfoMapper.selectOne(custInfoQuery); CustInfo custInfo = custInfoMapper.selectOne(custInfoQuery);
if (ObjectUtil.isNull(custInfo)) { if (ObjectUtil.isNull(custInfo)) {
log.error("修改密码错误:人员不存在:" + custInfo); log.error("修改密码错误:人员不存在:" + custInfo);
throw new ServiceException("修改密码错误:人员不存在", RetCodeEnum.PAY_PERSONAL_NO_EXIT.getKey()); // throw new ServiceException("修改密码错误:人员不存在", RetCodeEnum.PAY_PERSONAL_NO_EXIT.getKey());
ajaxResult.put("msg", "修改密码错误:人员不存在");
ajaxResult.put("code", "500");
} else { } else {
String newPassword = content.getNewPassword(); String newPassword = content.getNewPassword();
BCryptPasswordEncoder bCrypt = new BCryptPasswordEncoder(); BCryptPasswordEncoder bCrypt = new BCryptPasswordEncoder();
String password = bCrypt.encode(newPassword); String password = bCrypt.encode(newPassword);
custInfo.setPwd(password); custInfo.setPwd(password);
custInfoMapper.updateById(custInfo); custInfoMapper.updateById(custInfo);
ajaxResult.put("msg", "修改成功");
ajaxResult.put("code", "200");
} }
} }
return ajaxResult;
} }
public boolean verifySmsCode(SmsCodeVerifyDTO smsCodeVerifyDTO, String cacheKey) { public boolean verifySmsCode(SmsCodeVerifyDTO smsCodeVerifyDTO, String cacheKey) {