mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-13 02:57:13 +08:00
style: 优化全局代码格式
This commit is contained in:
@@ -112,8 +112,7 @@ public class AuthController {
|
||||
}
|
||||
|
||||
@Operation(summary = "用户退出", description = "注销用户的当前登录")
|
||||
@Parameter(name = "Authorization", description = "令牌", required = true, example = "Bearer xxxx-xxxx-xxxx-xxxx",
|
||||
in = ParameterIn.HEADER)
|
||||
@Parameter(name = "Authorization", description = "令牌", required = true, example = "Bearer xxxx-xxxx-xxxx-xxxx", in = ParameterIn.HEADER)
|
||||
@PostMapping("/logout")
|
||||
public R<Object> logout() {
|
||||
Object loginId = StpUtil.getLoginId(-1L);
|
||||
|
@@ -113,9 +113,7 @@ public class CaptchaController {
|
||||
|
||||
@Operation(summary = "获取邮箱验证码", description = "发送验证码到指定邮箱")
|
||||
@GetMapping("/mail")
|
||||
public R getMailCaptcha(
|
||||
@NotBlank(message = "邮箱不能为空") @Pattern(regexp = RegexConstants.EMAIL, message = "邮箱格式错误") String email)
|
||||
throws MessagingException {
|
||||
public R getMailCaptcha(@NotBlank(message = "邮箱不能为空") @Pattern(regexp = RegexConstants.EMAIL, message = "邮箱格式错误") String email) throws MessagingException {
|
||||
String limitKeyPrefix = CacheConstants.LIMIT_KEY_PREFIX;
|
||||
String captchaKeyPrefix = CacheConstants.CAPTCHA_KEY_PREFIX;
|
||||
String limitCaptchaKey = RedisUtils.formatKey(limitKeyPrefix, captchaKeyPrefix, email);
|
||||
@@ -126,8 +124,9 @@ public class CaptchaController {
|
||||
String captcha = RandomUtil.randomNumbers(captchaMail.getLength());
|
||||
// 发送验证码
|
||||
Long expirationInMinutes = captchaMail.getExpirationInMinutes();
|
||||
String content = TemplateUtils.render(captchaMail.getTemplatePath(),
|
||||
Dict.create().set("captcha", captcha).set("expiration", expirationInMinutes));
|
||||
String content = TemplateUtils.render(captchaMail.getTemplatePath(), Dict.create()
|
||||
.set("captcha", captcha)
|
||||
.set("expiration", expirationInMinutes));
|
||||
MailUtils.sendHtml(email, String.format("【%s】邮箱验证码", projectProperties.getName()), content);
|
||||
// 保存验证码
|
||||
String captchaKey = RedisUtils.formatKey(captchaKeyPrefix, email);
|
||||
@@ -138,13 +137,13 @@ public class CaptchaController {
|
||||
|
||||
@Operation(summary = "获取短信验证码", description = "发送验证码到指定手机号")
|
||||
@GetMapping("/sms")
|
||||
public R getSmsCaptcha(
|
||||
@NotBlank(message = "手机号不能为空") @Pattern(regexp = RegexConstants.MOBILE, message = "手机号格式错误") String phone,
|
||||
CaptchaVO captchaReq, HttpServletRequest request) {
|
||||
public R getSmsCaptcha(@NotBlank(message = "手机号不能为空") @Pattern(regexp = RegexConstants.MOBILE, message = "手机号格式错误") String phone,
|
||||
CaptchaVO captchaReq,
|
||||
HttpServletRequest request) {
|
||||
// 行为验证码校验
|
||||
ResponseModel verificationRes = captchaService.verification(captchaReq);
|
||||
ValidationUtils.throwIfNotEqual(verificationRes.getRepCode(), RepCodeEnum.SUCCESS.getCode(),
|
||||
verificationRes.getRepMsg());
|
||||
ValidationUtils.throwIfNotEqual(verificationRes.getRepCode(), RepCodeEnum.SUCCESS.getCode(), verificationRes
|
||||
.getRepMsg());
|
||||
CaptchaProperties.CaptchaSms captchaSms = captchaProperties.getSms();
|
||||
String templateId = captchaSms.getTemplateId();
|
||||
String limitKeyPrefix = CacheConstants.LIMIT_KEY_PREFIX;
|
||||
@@ -152,20 +151,19 @@ public class CaptchaController {
|
||||
String limitTemplateKeyPrefix = RedisUtils.formatKey(limitKeyPrefix, captchaKeyPrefix);
|
||||
// 限制短信发送频率
|
||||
// 1.同一号码同一短信模板,1分钟2条,1小时8条,24小时20条,e.g. LIMIT:CAPTCHA:XXX:188xxxxx:1
|
||||
CheckUtils.throwIf(!RedisUtils.rateLimit(RedisUtils.formatKey(limitTemplateKeyPrefix, "MIN", phone, templateId),
|
||||
RateType.OVERALL, 2, 60), "验证码发送过于频繁,请稍后后再试");
|
||||
CheckUtils
|
||||
.throwIf(!RedisUtils.rateLimit(RedisUtils.formatKey(limitTemplateKeyPrefix, "HOUR", phone, templateId),
|
||||
RateType.OVERALL, 8, 60 * 60), "验证码发送过于频繁,请稍后后再试");
|
||||
CheckUtils.throwIf(!RedisUtils.rateLimit(RedisUtils.formatKey(limitTemplateKeyPrefix, "DAY", phone, templateId),
|
||||
RateType.OVERALL, 20, 60 * 60 * 24), "验证码发送过于频繁,请稍后后再试");
|
||||
CheckUtils.throwIf(!RedisUtils.rateLimit(RedisUtils
|
||||
.formatKey(limitTemplateKeyPrefix, "MIN", phone, templateId), RateType.OVERALL, 2, 60), "验证码发送过于频繁,请稍后后再试");
|
||||
CheckUtils.throwIf(!RedisUtils.rateLimit(RedisUtils
|
||||
.formatKey(limitTemplateKeyPrefix, "HOUR", phone, templateId), RateType.OVERALL, 8, 60 * 60), "验证码发送过于频繁,请稍后后再试");
|
||||
CheckUtils.throwIf(!RedisUtils.rateLimit(RedisUtils
|
||||
.formatKey(limitTemplateKeyPrefix, "DAY", phone, templateId), RateType.OVERALL, 20, 60 * 60 * 24), "验证码发送过于频繁,请稍后后再试");
|
||||
// 2.同一号码所有短信模板 24 小时 100 条,e.g. LIMIT:CAPTCHA:188xxxxx
|
||||
String limitPhoneKey = RedisUtils.formatKey(limitKeyPrefix, captchaKeyPrefix, phone);
|
||||
CheckUtils.throwIf(!RedisUtils.rateLimit(limitPhoneKey, RateType.OVERALL, 100, 60 * 60 * 24),
|
||||
"验证码发送过于频繁,请稍后后再试");
|
||||
CheckUtils.throwIf(!RedisUtils
|
||||
.rateLimit(limitPhoneKey, RateType.OVERALL, 100, 60 * 60 * 24), "验证码发送过于频繁,请稍后后再试");
|
||||
// 3.同一 IP 每分钟限制发送 30 条,e.g. LIMIT:CAPTCHA:PHONE:1xx.1xx.1xx.1xx
|
||||
String limitIpKey =
|
||||
RedisUtils.formatKey(limitKeyPrefix, captchaKeyPrefix, "PHONE", JakartaServletUtil.getClientIP(request));
|
||||
String limitIpKey = RedisUtils.formatKey(limitKeyPrefix, captchaKeyPrefix, "PHONE", JakartaServletUtil
|
||||
.getClientIP(request));
|
||||
CheckUtils.throwIf(!RedisUtils.rateLimit(limitIpKey, RateType.OVERALL, 30, 60), "验证码发送过于频繁,请稍后后再试");
|
||||
// 生成验证码
|
||||
String captcha = RandomUtil.randomNumbers(captchaSms.getLength());
|
||||
@@ -175,8 +173,8 @@ public class CaptchaController {
|
||||
Map<String, String> messageMap = MapUtil.newHashMap(2, true);
|
||||
messageMap.put("captcha", captcha);
|
||||
messageMap.put("expirationInMinutes", String.valueOf(expirationInMinutes));
|
||||
SmsResponse smsResponse =
|
||||
smsBlend.sendMessage(phone, captchaSms.getTemplateId(), (LinkedHashMap<String, String>)messageMap);
|
||||
SmsResponse smsResponse = smsBlend.sendMessage(phone, captchaSms
|
||||
.getTemplateId(), (LinkedHashMap<String, String>)messageMap);
|
||||
CheckUtils.throwIf(!smsResponse.isSuccess(), "验证码发送失败");
|
||||
// 保存验证码
|
||||
String captchaKey = RedisUtils.formatKey(captchaKeyPrefix, phone);
|
||||
|
@@ -124,30 +124,31 @@ public class CommonController {
|
||||
@GetMapping("/option")
|
||||
@Cacheable(cacheNames = CacheConstants.OPTION_KEY_PREFIX)
|
||||
public R<List<LabelValueResp>> listOption(@Validated OptionQuery query) {
|
||||
return R.ok(optionService.list(query).stream().map(option -> new LabelValueResp(option.getCode(),
|
||||
StrUtil.nullToDefault(option.getValue(), option.getDefaultValue()))).collect(Collectors.toList()));
|
||||
return R.ok(optionService.list(query)
|
||||
.stream()
|
||||
.map(option -> new LabelValueResp(option.getCode(), StrUtil.nullToDefault(option.getValue(), option
|
||||
.getDefaultValue())))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据枚举类名查询
|
||||
*
|
||||
* @param enumClassName
|
||||
* 枚举类名
|
||||
* @param enumClassName 枚举类名
|
||||
* @return 枚举类型
|
||||
*/
|
||||
private Optional<Class<?>> getEnumClassByName(String enumClassName) {
|
||||
Set<Class<?>> classSet = ClassUtil.scanPackageBySuper(projectProperties.getBasePackage(), IBaseEnum.class);
|
||||
return classSet.stream()
|
||||
.filter(
|
||||
c -> StrUtil.equalsAnyIgnoreCase(c.getSimpleName(), enumClassName, StrUtil.toCamelCase(enumClassName)))
|
||||
.filter(c -> StrUtil.equalsAnyIgnoreCase(c.getSimpleName(), enumClassName, StrUtil
|
||||
.toCamelCase(enumClassName)))
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询枚举字典
|
||||
*
|
||||
* @param enumClass
|
||||
* 枚举类型
|
||||
* @param enumClass 枚举类型
|
||||
* @return 枚举字典
|
||||
*/
|
||||
private List<LabelValueResp> listEnumDict(Class<?> enumClass) {
|
||||
|
@@ -60,9 +60,7 @@ public class OnlineUserController {
|
||||
}
|
||||
|
||||
@Operation(summary = "强退在线用户", description = "强退在线用户")
|
||||
@Parameter(name = "token", description = "令牌",
|
||||
example = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb2dpblR5cGUiOiJsb2dpbiIsImxvZ2luSWQiOjEsInJuU3RyIjoiTUd6djdyOVFoeHEwdVFqdFAzV3M5YjVJRzh4YjZPSEUifQ.7q7U3ouoN7WPhH2kUEM7vPe5KF3G_qavSG-vRgIxKvE",
|
||||
in = ParameterIn.PATH)
|
||||
@Parameter(name = "token", description = "令牌", example = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb2dpblR5cGUiOiJsb2dpbiIsImxvZ2luSWQiOjEsInJuU3RyIjoiTUd6djdyOVFoeHEwdVFqdFAzV3M5YjVJRzh4YjZPSEUifQ.7q7U3ouoN7WPhH2kUEM7vPe5KF3G_qavSG-vRgIxKvE", in = ParameterIn.PATH)
|
||||
@SaCheckPermission("monitor:online:user:delete")
|
||||
@DeleteMapping("/{token}")
|
||||
public R kickout(@PathVariable String token) {
|
||||
|
@@ -45,8 +45,7 @@ import top.charles7c.continew.starter.extension.crud.model.resp.R;
|
||||
@Tag(name = "公告管理 API")
|
||||
@RestController
|
||||
@CrudRequestMapping("/system/announcement")
|
||||
public class AnnouncementController extends
|
||||
BaseController<AnnouncementService, AnnouncementResp, AnnouncementDetailResp, AnnouncementQuery, AnnouncementReq> {
|
||||
public class AnnouncementController extends BaseController<AnnouncementService, AnnouncementResp, AnnouncementDetailResp, AnnouncementQuery, AnnouncementReq> {
|
||||
|
||||
@Override
|
||||
@SaCheckPermission("system:announcement:add")
|
||||
@@ -58,7 +57,7 @@ public class AnnouncementController extends
|
||||
@Override
|
||||
@SaCheckPermission("system:announcement:update")
|
||||
public R update(@Validated(ValidateGroup.Crud.Update.class) @RequestBody AnnouncementReq req,
|
||||
@PathVariable Long id) {
|
||||
@PathVariable Long id) {
|
||||
this.checkTime(req);
|
||||
return super.update(req, id);
|
||||
}
|
||||
|
@@ -38,5 +38,4 @@ import top.charles7c.continew.starter.extension.crud.enums.Api;
|
||||
@Tag(name = "字典项管理 API")
|
||||
@RestController
|
||||
@CrudRequestMapping(value = "/system/dict/item", api = {Api.PAGE, Api.GET, Api.ADD, Api.UPDATE, Api.DELETE})
|
||||
public class DictItemController
|
||||
extends BaseController<DictItemService, DictItemResp, DictItemDetailResp, DictItemQuery, DictItemReq> {}
|
||||
public class DictItemController extends BaseController<DictItemService, DictItemResp, DictItemDetailResp, DictItemQuery, DictItemReq> {}
|
@@ -37,5 +37,4 @@ import top.charles7c.continew.starter.extension.crud.base.BaseController;
|
||||
@Tag(name = "存储库管理 API")
|
||||
@RestController
|
||||
@CrudRequestMapping("/system/storage")
|
||||
public class StorageController
|
||||
extends BaseController<StorageService, StorageResp, StorageDetailResp, StorageQuery, StorageReq> {}
|
||||
public class StorageController extends BaseController<StorageService, StorageResp, StorageDetailResp, StorageQuery, StorageReq> {}
|
@@ -95,14 +95,14 @@ public class UserCenterController {
|
||||
@Operation(summary = "修改密码", description = "修改用户登录密码")
|
||||
@PatchMapping("/password")
|
||||
public R updatePassword(@Validated @RequestBody UserPasswordUpdateReq updateReq) {
|
||||
String rawOldPassword =
|
||||
ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(updateReq.getOldPassword()));
|
||||
String rawOldPassword = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(updateReq
|
||||
.getOldPassword()));
|
||||
ValidationUtils.throwIfNull(rawOldPassword, "当前密码解密失败");
|
||||
String rawNewPassword =
|
||||
ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(updateReq.getNewPassword()));
|
||||
String rawNewPassword = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(updateReq
|
||||
.getNewPassword()));
|
||||
ValidationUtils.throwIfNull(rawNewPassword, "新密码解密失败");
|
||||
ValidationUtils.throwIf(!ReUtil.isMatch(RegexConstants.PASSWORD, rawNewPassword),
|
||||
"密码长度为 6 到 32 位,可以包含字母、数字、下划线,特殊字符,同时包含字母和数字");
|
||||
ValidationUtils.throwIf(!ReUtil
|
||||
.isMatch(RegexConstants.PASSWORD, rawNewPassword), "密码长度为 6 到 32 位,可以包含字母、数字、下划线,特殊字符,同时包含字母和数字");
|
||||
userService.updatePassword(rawOldPassword, rawNewPassword, LoginHelper.getUserId());
|
||||
return R.ok("修改成功");
|
||||
}
|
||||
@@ -110,8 +110,8 @@ public class UserCenterController {
|
||||
@Operation(summary = "修改手机号", description = "修改手机号")
|
||||
@PatchMapping("/phone")
|
||||
public R updatePhone(@Validated @RequestBody UserPhoneUpdateReq updateReq) {
|
||||
String rawCurrentPassword =
|
||||
ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(updateReq.getCurrentPassword()));
|
||||
String rawCurrentPassword = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(updateReq
|
||||
.getCurrentPassword()));
|
||||
ValidationUtils.throwIfBlank(rawCurrentPassword, "当前密码解密失败");
|
||||
String captchaKey = RedisUtils.formatKey(CacheConstants.CAPTCHA_KEY_PREFIX, updateReq.getNewPhone());
|
||||
String captcha = RedisUtils.get(captchaKey);
|
||||
@@ -125,8 +125,8 @@ public class UserCenterController {
|
||||
@Operation(summary = "修改邮箱", description = "修改用户邮箱")
|
||||
@PatchMapping("/email")
|
||||
public R updateEmail(@Validated @RequestBody UserEmailUpdateRequest updateReq) {
|
||||
String rawCurrentPassword =
|
||||
ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(updateReq.getCurrentPassword()));
|
||||
String rawCurrentPassword = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(updateReq
|
||||
.getCurrentPassword()));
|
||||
ValidationUtils.throwIfBlank(rawCurrentPassword, "当前密码解密失败");
|
||||
String captchaKey = RedisUtils.formatKey(CacheConstants.CAPTCHA_KEY_PREFIX, updateReq.getNewEmail());
|
||||
String captcha = RedisUtils.get(captchaKey);
|
||||
|
@@ -73,7 +73,7 @@ public class GeneratorController {
|
||||
@SaCheckPermission("tool:generator:list")
|
||||
@GetMapping("/field/{tableName}")
|
||||
public R<List<FieldConfigDO>> listFieldConfig(@PathVariable String tableName,
|
||||
@RequestParam(required = false, defaultValue = "false") Boolean requireSync) {
|
||||
@RequestParam(required = false, defaultValue = "false") Boolean requireSync) {
|
||||
return R.ok(generatorService.listFieldConfig(tableName, requireSync));
|
||||
}
|
||||
|
||||
|
@@ -23,5 +23,6 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
class ContiNewAdminApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {}
|
||||
void contextLoads() {
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user