feat: 忘记密码
This commit is contained in:
@@ -45,7 +45,7 @@ public class UEmailController extends BaseController {
|
||||
if (!mailProperties.getEnabled()) {
|
||||
return R.fail(MessageUtils.message("user.email.not.enable"));
|
||||
}
|
||||
String key = GlobalConstants.CAPTCHA_CODE_KEY + email;
|
||||
String key = GlobalConstants.CAPTCHA_CODE_KEY + GlobalConstants.USER + email;
|
||||
String code = RandomUtil.randomNumbers(4);
|
||||
redisService.setCacheObject(key, code, Constants.MAIL_CAPTCHA_EXPIRATION, TimeUnit.MINUTES);
|
||||
try {
|
||||
|
||||
@@ -1,23 +1,33 @@
|
||||
package org.wfc.user.controller;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.wfc.common.core.constant.GlobalConstants;
|
||||
import org.wfc.common.core.domain.LoginUser;
|
||||
import org.wfc.common.core.domain.R;
|
||||
import org.wfc.common.core.exception.CaptchaException;
|
||||
import org.wfc.common.core.exception.VerificationCodeException;
|
||||
import org.wfc.common.core.utils.MessageUtils;
|
||||
import org.wfc.common.core.utils.StringUtils;
|
||||
import org.wfc.common.core.utils.file.FileTypeUtils;
|
||||
import org.wfc.common.core.utils.file.MimeTypeUtils;
|
||||
import org.wfc.common.core.web.controller.BaseController;
|
||||
import org.wfc.common.core.web.domain.AjaxResult;
|
||||
import org.wfc.common.log.annotation.Log;
|
||||
import org.wfc.common.log.enums.BusinessType;
|
||||
import org.wfc.common.redis.service.RedisService;
|
||||
import org.wfc.common.security.service.TokenService;
|
||||
import org.wfc.common.security.utils.SecurityUtils;
|
||||
import org.wfc.user.api.RemoteUFileService;
|
||||
import org.wfc.user.api.domain.UFile;
|
||||
import org.wfc.user.api.domain.UUser;
|
||||
import org.wfc.user.domain.bo.UUserForgotPwdBo;
|
||||
import org.wfc.user.service.IUUserService;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -40,6 +50,9 @@ public class UProfileController extends BaseController
|
||||
@Autowired
|
||||
private RemoteUFileService remoteUFileService;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
/**
|
||||
* 个人信息
|
||||
*/
|
||||
@@ -123,6 +136,44 @@ public class UProfileController extends BaseController
|
||||
}
|
||||
return error(MessageUtils.message("user.modify.password.failed.contact.administrator"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 忘记密码
|
||||
*/
|
||||
@PutMapping("/forgotPwd")
|
||||
public AjaxResult forgotPwd(@RequestBody UUserForgotPwdBo UUserForgotPwdBo) {
|
||||
UUser user = userService.selectUserByEmail(UUserForgotPwdBo.getEmail());
|
||||
if (ObjectUtil.isNull(user)) {
|
||||
return error("user.register.email.not.exist.error");
|
||||
}
|
||||
checkCaptchaEmail(UUserForgotPwdBo.getCode(), UUserForgotPwdBo.getEmail());
|
||||
|
||||
String newPassword = UUserForgotPwdBo.getPassword();
|
||||
String password = user.getPassword();
|
||||
String username = user.getUserName();
|
||||
if (SecurityUtils.matchesPassword(newPassword, password)) {
|
||||
return error("user.modify.password.failed.new.password.same.old.password");
|
||||
}
|
||||
newPassword = SecurityUtils.encryptPassword(newPassword);
|
||||
if (userService.resetUserPwd(username, newPassword) > 0) {
|
||||
return success();
|
||||
}
|
||||
return error("user.modify.password.failed.contact.administrator");
|
||||
}
|
||||
|
||||
public void checkCaptchaEmail(String code, String email) throws CaptchaException {
|
||||
if (StringUtils.isEmpty(code)) {
|
||||
throw new VerificationCodeException("email.code.not.blankk");
|
||||
}
|
||||
String verifyKey = GlobalConstants.CAPTCHA_CODE_KEY + GlobalConstants.USER + StringUtils.nvl(email, "");
|
||||
String captcha = redisService.getCacheObject(verifyKey);
|
||||
if (captcha == null) {
|
||||
throw new VerificationCodeException();
|
||||
}
|
||||
if (!code.equalsIgnoreCase(captcha)) {
|
||||
throw new VerificationCodeException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 头像上传
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.wfc.user.domain.bo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @description: 忘记密码bo
|
||||
* @author: cyc
|
||||
* @since: 2025-02-12
|
||||
*/
|
||||
@Data
|
||||
public class UUserForgotPwdBo {
|
||||
private String email;
|
||||
private String password;
|
||||
private String code;
|
||||
}
|
||||
@@ -44,6 +44,14 @@ public interface UUserMapper
|
||||
*/
|
||||
public UUser selectUserByUserName(String userName);
|
||||
|
||||
/**
|
||||
* 通过邮箱查询用户
|
||||
*
|
||||
* @param email 邮箱
|
||||
* @return 用户对象信息
|
||||
*/
|
||||
public UUser selectUserByEmail(String email);
|
||||
|
||||
/**
|
||||
* 通过用户ID查询用户
|
||||
*
|
||||
|
||||
@@ -43,6 +43,14 @@ public interface IUUserService
|
||||
*/
|
||||
public UUser selectUserByUserName(String userName);
|
||||
|
||||
/**
|
||||
* 通过邮箱查询用户
|
||||
*
|
||||
* @param email 用户名
|
||||
* @return 用户对象信息
|
||||
*/
|
||||
public UUser selectUserByEmail(String email);
|
||||
|
||||
/**
|
||||
* 通过用户ID查询用户
|
||||
*
|
||||
|
||||
@@ -109,6 +109,11 @@ public class UUserServiceImpl implements IUUserService
|
||||
return userMapper.selectUserByUserName(userName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUser selectUserByEmail(String email) {
|
||||
return userMapper.selectUserByEmail(email);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过用户ID查询用户
|
||||
*
|
||||
|
||||
@@ -149,6 +149,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<include refid="selectUserVo"/>
|
||||
where u.user_name = #{userName} and u.del_flag = '0'
|
||||
</select>
|
||||
|
||||
<select id="selectUserByEmail" parameterType="String" resultMap="UUserResult">
|
||||
<include refid="selectUserVo"/>
|
||||
where u.email = #{email} and u.del_flag = '0'
|
||||
</select>
|
||||
|
||||
<select id="selectUserById" parameterType="Long" resultMap="UUserResult">
|
||||
<include refid="selectUserVo"/>
|
||||
|
||||
Reference in New Issue
Block a user