Skip to content

Commit

Permalink
feat: 优化验证码超时显示效果,超时后显示已过期请刷新
Browse files Browse the repository at this point in the history
  • Loading branch information
jskils authored and Charles7c committed Apr 29, 2024
1 parent 23a0baf commit 4c6a7fb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,7 @@ public class CaptchaResp implements Serializable {
*/
@Schema(description = "验证码图片(Base64编码,带图片格式:data:image/gif;base64)", example = "data:image/png;base64,iVBORw0KGgoAAAAN...")
private String img;

@Schema(description = "过期时间戳", example = "1714376969409")
private Long expireTime;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import top.continew.admin.common.constant.RegexConstants;
import top.continew.admin.common.enums.DisEnableStatusEnum;
import top.continew.starter.extension.crud.model.req.BaseReq;
import top.continew.starter.extension.crud.util.ValidateGroup;

import java.io.Serial;

Expand All @@ -47,7 +46,7 @@ public class DeptReq extends BaseReq {
* 上级部门 ID
*/
@Schema(description = "上级部门 ID", example = "2")
@NotNull(message = "上级部门不能为空", groups = ValidateGroup.Crud.Add.class)
@NotNull(message = "上级部门不能为空")
private Long parentId;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package top.continew.admin.webapi.common;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.lang.Dict;
import cn.hutool.core.lang.RegexPool;
import cn.hutool.core.map.MapUtil;
Expand Down Expand Up @@ -57,6 +58,7 @@
import top.continew.starter.web.model.R;

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.LinkedHashMap;
import java.util.Map;

Expand Down Expand Up @@ -101,8 +103,10 @@ public R<CaptchaResp> getImageCaptcha() {
String uuid = IdUtil.fastUUID();
String captchaKey = CacheConstants.CAPTCHA_KEY_PREFIX + uuid;
Captcha captcha = graphicCaptchaService.getCaptcha();
long expireTime = LocalDateTimeUtil.toEpochMilli(LocalDateTime.now()
.plusMinutes(captchaProperties.getExpirationInMinutes()));
RedisUtils.set(captchaKey, captcha.text(), Duration.ofMinutes(captchaProperties.getExpirationInMinutes()));
return R.ok(CaptchaResp.builder().uuid(uuid).img(captcha.toBase64()).build());
return R.ok(CaptchaResp.builder().uuid(uuid).img(captcha.toBase64()).expireTime(expireTime).build());
}

@Operation(summary = "获取邮箱验证码", description = "发送验证码到指定邮箱")
Expand Down

0 comments on commit 4c6a7fb

Please sign in to comment.