feat: 修改密码邮件内容从字典获取

This commit is contained in:
曹鹏飞 2025-02-23 13:22:07 +08:00
parent b6a0c52313
commit f66580cb75
3 changed files with 20 additions and 8 deletions

View File

@ -295,12 +295,12 @@ public class AdminUserController extends ControllerBase {
} }
/** /**
* 更新密码 * 修改密码
* @param request 请求信息 * @param request 请求信息
* @return 更新结果 * @return 更新结果
**/ **/
@PostMapping("updatePassword") @PostMapping("updatePassword")
@ApiMark(moduleName = "账号管理", apiName = "更新密码") @ApiMark(moduleName = "账号管理", apiName = "修改密码")
public ApiResult<Void> updatePassword(@Valid @RequestBody UpdatePasswordRequest request) { public ApiResult<Void> updatePassword(@Valid @RequestBody UpdatePasswordRequest request) {
String redisKey = StrUtil.format(Constant.REDIS_KEY_USER_UPDATE_KAPTCHA_ADMIN, AdminUserUtil.getEmail()); String redisKey = StrUtil.format(Constant.REDIS_KEY_USER_UPDATE_KAPTCHA_ADMIN, AdminUserUtil.getEmail());
String captcha = redisTemplate.opsForValue().get(redisKey); String captcha = redisTemplate.opsForValue().get(redisKey);
@ -321,8 +321,12 @@ public class AdminUserController extends ControllerBase {
String email = AdminUserUtil.getEmail(); String email = AdminUserUtil.getEmail();
String kaptcha = RandomUtil.randomString(6); String kaptcha = RandomUtil.randomString(6);
// 将生成的验证码存入redis // 将生成的验证码存入redis
redisTemplate.opsForValue().set(StrUtil.format(Constant.REDIS_KEY_USER_UPDATE_KAPTCHA_ADMIN, email), kaptcha, Duration.ofMinutes(10)); redisTemplate.opsForValue().set(StrUtil.format(Constant.REDIS_KEY_USER_UPDATE_KAPTCHA_ADMIN, email), kaptcha, Duration.ofHours(72));
emailService.sendEmail(email, "您正在申请修改密码", "验证码为: " + kaptcha); String subject = dictionaryItemTranslateService.getValueByCode(Constant.DICTIONARY_EMAIL_NOTIFY, Constant.DICTIONARY_ITEM_EMAIL_TITLE_ACCOUNT_CHANGE_PASSWORD, Constant.DEFAULT_LANGUAGE_CODE);
String content = dictionaryItemTranslateService.getValueByCode(Constant.DICTIONARY_EMAIL_NOTIFY, Constant.DICTIONARY_ITEM_EMAIL_CONTENT_ACCOUNT_CHANGE_PASSWORD, Constant.DEFAULT_LANGUAGE_CODE)
.replace("${loginName}",email)
.replace("${password}",kaptcha);
emailService.sendEmail(email, subject, content);
} catch (Exception ex) { } catch (Exception ex) {
throw new NflgException(STATE.BusinessError, "发送邮件失败:" + ex.getMessage()); throw new NflgException(STATE.BusinessError, "发送邮件失败:" + ex.getMessage());
} }

View File

@ -98,7 +98,7 @@ public class UserController extends ControllerBase {
} }
/** /**
* 发送更新密码验证码邮件 * 发送修改密码验证码邮件
**/ **/
@PostMapping("sendUpdatePasswordCaptchaEmail") @PostMapping("sendUpdatePasswordCaptchaEmail")
public ApiResult<Void> sendUpdatePasswordCaptchaEmail() { public ApiResult<Void> sendUpdatePasswordCaptchaEmail() {
@ -106,8 +106,12 @@ public class UserController extends ControllerBase {
String email = AppUserUtil.getEmail(); String email = AppUserUtil.getEmail();
String kaptcha = RandomUtil.randomString(6); String kaptcha = RandomUtil.randomString(6);
// 将生成的验证码存入redis // 将生成的验证码存入redis
redisTemplate.opsForValue().set(StrUtil.format(Constant.REDIS_KEY_USER_UPDATE_KAPTCHA_APP, email), kaptcha, Duration.ofMinutes(10)); redisTemplate.opsForValue().set(StrUtil.format(Constant.REDIS_KEY_USER_UPDATE_KAPTCHA_APP, email), kaptcha, Duration.ofHours(72));
emailService.sendEmail(email, "您正在申请修改密码", "验证码为: " + kaptcha); String subject = dictionaryItemTranslateService.getValueByCode(Constant.DICTIONARY_EMAIL_NOTIFY, Constant.DICTIONARY_ITEM_EMAIL_TITLE_ACCOUNT_CHANGE_PASSWORD, Constant.DEFAULT_LANGUAGE_CODE);
String content = dictionaryItemTranslateService.getValueByCode(Constant.DICTIONARY_EMAIL_NOTIFY, Constant.DICTIONARY_ITEM_EMAIL_CONTENT_ACCOUNT_CHANGE_PASSWORD, Constant.DEFAULT_LANGUAGE_CODE)
.replace("${loginName}",email)
.replace("${password}",kaptcha);
emailService.sendEmail(email, subject, content);
} catch (Exception ex) { } catch (Exception ex) {
throw new NflgException(STATE.BusinessError, "发送邮件失败:" + ex.getMessage()); throw new NflgException(STATE.BusinessError, "发送邮件失败:" + ex.getMessage());
} }
@ -115,7 +119,7 @@ public class UserController extends ControllerBase {
} }
/** /**
* 更新密码 * 修改密码
* @param request 请求信息 * @param request 请求信息
* @return 更新结果 * @return 更新结果
**/ **/

View File

@ -50,10 +50,14 @@ public class Constant {
public static final String DICTIONARY_ITEM_EMAIL_TITLE_ACCOUNT_RESET_PASSWORD="TitleResetPassword"; public static final String DICTIONARY_ITEM_EMAIL_TITLE_ACCOUNT_RESET_PASSWORD="TitleResetPassword";
public static final String DICTIONARY_ITEM_EMAIL_TITLE_ACCOUNT_CHANGE_PASSWORD="TitleChangePassword";
public static final String DICTIONARY_ITEM_EMAIL_TITLE_ACCOUNT_ACTIVATION="TitleAccountActivation"; public static final String DICTIONARY_ITEM_EMAIL_TITLE_ACCOUNT_ACTIVATION="TitleAccountActivation";
public static final String DICTIONARY_ITEM_EMAIL_CONTENT_RESET_PASSWORD_NOTIFY="ResetPassword"; public static final String DICTIONARY_ITEM_EMAIL_CONTENT_RESET_PASSWORD_NOTIFY="ResetPassword";
public static final String DICTIONARY_ITEM_EMAIL_CONTENT_ACCOUNT_CHANGE_PASSWORD="ChangePassword";
public static final String DICTIONARY_ITEM_EMAIL_CONTENT_ACCOUNT_ACTIVATION_NOTIFY="AccountActivation"; public static final String DICTIONARY_ITEM_EMAIL_CONTENT_ACCOUNT_ACTIVATION_NOTIFY="AccountActivation";
/** /**