mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-17 11:00:09 +08:00
优化:优化校验器相关方法名
This commit is contained in:
@@ -67,14 +67,14 @@ public class LoginController {
|
||||
// 校验验证码
|
||||
String captchaKey = RedisUtils.formatKey(CacheConstants.CAPTCHA_CACHE_KEY, loginRequest.getUuid());
|
||||
String captcha = RedisUtils.getCacheObject(captchaKey);
|
||||
ValidationUtils.exIfBlank(captcha, "验证码已失效");
|
||||
ValidationUtils.throwIfBlank(captcha, "验证码已失效");
|
||||
RedisUtils.deleteCacheObject(captchaKey);
|
||||
ValidationUtils.exIfNotEqualIgnoreCase(loginRequest.getCaptcha(), captcha, "验证码错误");
|
||||
ValidationUtils.throwIfNotEqualIgnoreCase(loginRequest.getCaptcha(), captcha, "验证码错误");
|
||||
|
||||
// 用户登录
|
||||
String rawPassword =
|
||||
ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(loginRequest.getPassword()));
|
||||
ValidationUtils.exIfBlank(rawPassword, "密码解密失败");
|
||||
ValidationUtils.throwIfBlank(rawPassword, "密码解密失败");
|
||||
String token = loginService.login(loginRequest.getUsername(), rawPassword);
|
||||
return R.ok(new LoginVO().setToken(token));
|
||||
}
|
||||
|
@@ -94,7 +94,7 @@ public class CaptchaController {
|
||||
String captchaCacheKey = CacheConstants.CAPTCHA_CACHE_KEY;
|
||||
String limitCaptchaKey = RedisUtils.formatKey(limitCacheKey, captchaCacheKey, email);
|
||||
long limitTimeInMillisecond = RedisUtils.getTimeToLive(limitCaptchaKey);
|
||||
ValidationUtils.exIfCondition(() -> limitTimeInMillisecond > 0,
|
||||
ValidationUtils.throwIf(() -> limitTimeInMillisecond > 0,
|
||||
String.format("发送邮箱验证码过于频繁,请您 %ds 后再试", limitTimeInMillisecond / 1000));
|
||||
|
||||
// 生成验证码
|
||||
|
@@ -70,13 +70,13 @@ public class UserCenterController {
|
||||
@PostMapping("/avatar")
|
||||
public R<AvatarVO> uploadAvatar(@NotNull(message = "头像不能为空") MultipartFile avatarFile) {
|
||||
// 校验
|
||||
ValidationUtils.exIfCondition(avatarFile::isEmpty, "头像不能为空");
|
||||
ValidationUtils.throwIf(avatarFile::isEmpty, "头像不能为空");
|
||||
Long avatarMaxSizeInMb = localStorageProperties.getAvatarMaxSizeInMb();
|
||||
ValidationUtils.exIfCondition(() -> avatarFile.getSize() > avatarMaxSizeInMb * 1024 * 1024,
|
||||
ValidationUtils.throwIf(() -> avatarFile.getSize() > avatarMaxSizeInMb * 1024 * 1024,
|
||||
String.format("请上传小于 %s MB 的图片", avatarMaxSizeInMb));
|
||||
String avatarImageType = FileNameUtil.extName(avatarFile.getOriginalFilename());
|
||||
String[] avatarSupportImgTypes = FileConstants.AVATAR_SUPPORTED_IMG_TYPES;
|
||||
ValidationUtils.exIfCondition(() -> !StrUtil.equalsAnyIgnoreCase(avatarImageType, avatarSupportImgTypes),
|
||||
ValidationUtils.throwIf(() -> !StrUtil.equalsAnyIgnoreCase(avatarImageType, avatarSupportImgTypes),
|
||||
String.format("头像仅支持 %s 格式的图片", String.join(",", avatarSupportImgTypes)));
|
||||
|
||||
// 上传头像
|
||||
@@ -100,15 +100,15 @@ public class UserCenterController {
|
||||
// 解密
|
||||
String rawOldPassword =
|
||||
ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(updatePasswordRequest.getOldPassword()));
|
||||
ValidationUtils.exIfBlank(rawOldPassword, "当前密码解密失败");
|
||||
ValidationUtils.throwIfBlank(rawOldPassword, "当前密码解密失败");
|
||||
String rawNewPassword =
|
||||
ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(updatePasswordRequest.getNewPassword()));
|
||||
ValidationUtils.exIfBlank(rawNewPassword, "新密码解密失败");
|
||||
ValidationUtils.throwIfBlank(rawNewPassword, "新密码解密失败");
|
||||
|
||||
// 校验
|
||||
ValidationUtils.exIfCondition(() -> !ReUtil.isMatch(RegExpConstants.PASSWORD, rawNewPassword),
|
||||
ValidationUtils.throwIf(() -> !ReUtil.isMatch(RegExpConstants.PASSWORD, rawNewPassword),
|
||||
"密码长度 6 到 32 位,同时包含数字和字母");
|
||||
ValidationUtils.exIfEqual(rawNewPassword, rawOldPassword, "新密码不能与当前密码相同");
|
||||
ValidationUtils.throwIfEqual(rawNewPassword, rawOldPassword, "新密码不能与当前密码相同");
|
||||
|
||||
// 修改密码
|
||||
userService.updatePassword(rawOldPassword, rawNewPassword, LoginHelper.getUserId());
|
||||
@@ -121,13 +121,13 @@ public class UserCenterController {
|
||||
// 解密
|
||||
String rawCurrentPassword =
|
||||
ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(updateEmailRequest.getCurrentPassword()));
|
||||
ValidationUtils.exIfBlank(rawCurrentPassword, "当前密码解密失败");
|
||||
ValidationUtils.throwIfBlank(rawCurrentPassword, "当前密码解密失败");
|
||||
|
||||
// 校验
|
||||
String captchaKey = RedisUtils.formatKey(CacheConstants.CAPTCHA_CACHE_KEY, updateEmailRequest.getNewEmail());
|
||||
String captcha = RedisUtils.getCacheObject(captchaKey);
|
||||
ValidationUtils.exIfBlank(captcha, "验证码已失效");
|
||||
ValidationUtils.exIfNotEqualIgnoreCase(updateEmailRequest.getCaptcha(), captcha, "验证码错误");
|
||||
ValidationUtils.throwIfBlank(captcha, "验证码已失效");
|
||||
ValidationUtils.throwIfNotEqualIgnoreCase(updateEmailRequest.getCaptcha(), captcha, "验证码错误");
|
||||
RedisUtils.deleteCacheObject(captchaKey);
|
||||
|
||||
// 修改邮箱
|
||||
|
Reference in New Issue
Block a user