feat: 添加验证码开关配置,适配Docker部署(prod连接mysql/redis)

This commit is contained in:
OpenCode
2026-07-08 16:24:26 +08:00
parent 14191d2720
commit 5116128355
5 changed files with 38 additions and 19 deletions
+1 -6
View File
@@ -1,14 +1,9 @@
# 使用 GraalVM 17 作为基础镜像
FROM ghcr.io/graalvm/graalvm-ce:latest
FROM eclipse-temurin:17-jre
# 设置容器内的工作目录
WORKDIR /app
# 将可执行的jar文件复制到容器内
COPY target/cool-admin-8.0.0.jar /app/cool-admin-8.0.0.jar
# 暴露Spring Boot应用程序运行的端口
EXPOSE 8001
# 运行Spring Boot应用程序的命令
ENTRYPOINT ["java", "-jar", "/app/cool-admin-8.0.0.jar", "--spring.profiles.active=prod"]
@@ -21,10 +21,8 @@ public class BaseSysLoginDto {
private String password;
@Schema(description = "验证码ID")
@NotBlank
private String captchaId;
@Schema(description = "验证码")
@NotBlank
private String verifyCode;
}
@@ -15,11 +15,13 @@ import com.cool.core.exception.CoolPreconditions;
import com.cool.core.security.jwt.JwtTokenUtil;
import com.cool.core.util.CoolSecurityUtil;
import com.cool.modules.base.dto.sys.BaseSysLoginDto;
import com.cool.modules.base.dto.sys.BaseSysLoginDto;
import com.cool.modules.base.entity.sys.BaseSysUserEntity;
import com.cool.modules.base.mapper.sys.BaseSysUserMapper;
import com.cool.modules.base.service.sys.BaseSysLoginService;
import com.cool.modules.base.service.sys.BaseSysPermsService;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.query.QueryWrapper;
import java.awt.Color;
import java.util.HashMap;
import java.util.Map;
@@ -44,6 +46,9 @@ public class BaseSysLoginServiceImpl implements BaseSysLoginService {
private final BaseSysPermsService baseSysPermsService;
@org.springframework.beans.factory.annotation.Value("${cool.captcha.enable:true}")
private boolean captchaEnable;
@Override
public Object captcha(UserTypeEnum userTypeEnum, String type, Integer width, Integer height) {
// 1、生成验证码 2、生成对应的ID并设置在缓存中,验证码过期时间30分钟;
@@ -80,7 +85,9 @@ public class BaseSysLoginServiceImpl implements BaseSysLoginService {
@Override
public Object login(BaseSysLoginDto baseSysLoginDto) {
// 1、检查验证码是否正确 2、执行登录操作
captchaCheck(baseSysLoginDto.getCaptchaId(), baseSysLoginDto.getVerifyCode());
if (captchaEnable) {
captchaCheck(baseSysLoginDto.getCaptchaId(), baseSysLoginDto.getVerifyCode());
}
UsernamePasswordAuthenticationToken upToken =
new UsernamePasswordAuthenticationToken(
baseSysLoginDto.getUsername(), baseSysLoginDto.getPassword());
@@ -94,7 +101,9 @@ public class BaseSysLoginServiceImpl implements BaseSysLoginService {
CoolPreconditions.check(
ObjectUtil.isEmpty(baseSysUserEntity) || baseSysUserEntity.getStatus() == 0, "用户已禁用");
Long[] roleIds = baseSysPermsService.getRoles(baseSysUserEntity);
coolCache.del("verify:img:" + baseSysLoginDto.getCaptchaId());
if (captchaEnable) {
coolCache.del("verify:img:" + baseSysLoginDto.getCaptchaId());
}
return generateToken(roleIds, baseSysUserEntity, null);
}
+23 -9
View File
@@ -1,27 +1,41 @@
spring:
datasource:
url: jdbc:mysql://127.0.0.1:3306/cool?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2b8
url: jdbc:mysql://mysql:3306/cool?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2b8
username: root
password: 123456
password: mysql
driver-class-name: com.mysql.cj.jdbc.Driver
cache:
type: redis
data:
redis:
host: redis
port: 6379
database: 0
password: redis
# AutoTable配置,根据实体类自动生成表
auto-table:
# 启用自动维护表功能
enable: false
enable: true
autoDropIndex: true
superInsertPosition: before
model-package: com.cool.**.entity
# Cool相关配置
cool:
# 初始化数据
initData: false
captcha:
enable: false
initData: true
file:
mode: local
local:
base-url: http://127.0.0.1:${server.port}/upload
# 文档
springdoc:
api-docs:
#是否开启文档功能 本地为了配合eps功能不可关闭
enabled: true
# 设置日志级别
logging:
level:
com.cool: error
com.cool: info
+3
View File
@@ -119,6 +119,9 @@ mybatis-flex:
# Cool相关配置
cool:
# 验证码开关
captcha:
enable: true
# 缓存名称
cacheName: comm
plugin: