客户端修改密码支持管理端用户
This commit is contained in:
parent
9d58b51998
commit
3ef915295c
|
|
@ -133,7 +133,8 @@ public class UserController extends ControllerBase {
|
|||
String email = AppUserUtil.getEmail();
|
||||
String kaptcha = RandomUtil.randomString(6);
|
||||
// 将生成的验证码存入redis
|
||||
stringRedisTemplate.opsForValue().set(StrUtil.format(Constant.REDIS_KEY_USER_UPDATE_KAPTCHA_APP, email), kaptcha, Duration.ofHours(72));
|
||||
String key = StrUtil.equals(AppUserUtil.getFrom(), Constant.FROM_APP) ? Constant.REDIS_KEY_USER_UPDATE_KAPTCHA_APP : Constant.REDIS_KEY_USER_UPDATE_KAPTCHA_ADMIN;
|
||||
stringRedisTemplate.opsForValue().set(StrUtil.format(key, email), kaptcha, Duration.ofHours(72));
|
||||
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)
|
||||
|
|
@ -152,11 +153,16 @@ public class UserController extends ControllerBase {
|
|||
**/
|
||||
@PostMapping("updatePassword")
|
||||
public ApiResult<Void> updatePassword(@Valid @RequestBody UpdatePasswordRequest request) {
|
||||
String redisKey = StrUtil.format(Constant.REDIS_KEY_USER_UPDATE_KAPTCHA_APP, AppUserUtil.getEmail());
|
||||
String key = StrUtil.equals(AppUserUtil.getFrom(), Constant.FROM_APP) ? Constant.REDIS_KEY_USER_UPDATE_KAPTCHA_APP : Constant.REDIS_KEY_USER_UPDATE_KAPTCHA_ADMIN;
|
||||
String redisKey = StrUtil.format(key, AppUserUtil.getEmail());
|
||||
String captcha = stringRedisTemplate.opsForValue().get(redisKey);
|
||||
VUtils.trueThrowBusinessError(StrUtil.isBlank(captcha)).throwMessage("验证码已失效,请重新获取");
|
||||
VUtils.trueThrowBusinessError(!StrUtil.equals(captcha, request.getCaptcha())).throwMessage("验证码不正确");
|
||||
if (StrUtil.equals(AppUserUtil.getFrom(), Constant.FROM_APP)) {
|
||||
appUserService.updatePassword(AppUserUtil.getUserId(), request.getNewPassword());
|
||||
} else if (StrUtil.equals(AppUserUtil.getFrom(), Constant.FROM_ADMIN)) {
|
||||
adminUserService.updatePassword(AppUserUtil.getUserId(), request.getNewPassword());
|
||||
}
|
||||
stringRedisTemplate.delete(redisKey);
|
||||
return ApiResult.success();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue