feat(修改): 🐛 图形验证码生成;

This commit is contained in:
Bunny 2024-07-28 00:10:10 +08:00
parent 7ac9b68141
commit 92fc93e5b4
7 changed files with 42 additions and 7 deletions

View File

@ -89,7 +89,8 @@ public class WebSecurityConfig {
@Bean
public WebSecurityCustomizer webSecurityCustomizer() {
String[] annotations = {"/", "/test/**", "/diagram-viewer/**", "/editor-app/**", "/*.html",
"/*/*/noAuth/**", "/*/noAuth/**", "/favicon.ico", "/swagger-resources/**", "/webjars/**", "/v3/**", "/swagger-ui.html/**", "/doc.html"};
"/*/*/noAuth/**", "/*/noAuth/**", "/favicon.ico", "/swagger-resources/**", "/webjars/**",
"/v3/**", "/swagger-ui.html/**", "/doc.html"};
return web -> web.ignoring().requestMatchers(annotations);
}
}

View File

@ -23,7 +23,8 @@ spring:
grace-destroy: false #是否优雅关闭数据源默认为false设置为true时关闭数据源时如果数据源中还存在活跃连接至多等待10s后强制关闭
datasource:
master:
driver-class-name: com.zaxxer.hikari.HikariDataSource
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://${bunny.datasource.host}:${bunny.datasource.port}/${bunny.datasource.sqlData}?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true
username: ${bunny.datasource.username}
password: ${bunny.datasource.password}

View File

@ -30,8 +30,9 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
String[] excludeList = {"/api/checkCode", "/api/sendEmailCode", "/api/register", "/api/login", "/api/article/loadArticle/**"};
log.info("WebMvcConfiguration===>开始注册自定义拦截器...");
String[] excludeList = {"/api/**", "/api/sendEmailCode", "/api/register", "/api/login", "/**"};
registry.addInterceptor(userTokenInterceptor).addPathPatterns("/api/**")
.excludePathPatterns(excludeList);
}

View File

@ -9,6 +9,10 @@ import cn.bunny.vo.system.login.ValidateCodeVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@Tag(name = "登录和注册相关接口")
@ -32,6 +36,16 @@ public class LoginController {
return Result.success(vo);
}
@Operation(summary = "生成图片验证码", description = "生成图验证码")
@GetMapping("checkCodeImage")
public ResponseEntity<byte[]> checkCodeImage() {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.IMAGE_JPEG);
byte[] checkCodeImage = loginService.checkCodeImage();
return new ResponseEntity<>(checkCodeImage, headers, HttpStatus.OK);
}
@Operation(summary = "发送邮箱验证码", description = "发送邮箱验证码")
@PostMapping("sendEmailCode")
public Result<String> sendEmailCode(String email) {

View File

@ -41,4 +41,11 @@ public interface LoginService extends IService<User> {
* 退出登录
*/
void logout();
/**
* * 生成图片验证码
*
* @return 验证码图片
*/
byte[] checkCodeImage();
}

View File

@ -6,12 +6,12 @@ import cn.bunny.common.service.utils.EmptyUtil;
import cn.bunny.common.service.utils.JwtHelper;
import cn.bunny.dto.user.LoginDto;
import cn.bunny.dto.user.RegisterDto;
import cn.bunny.pojo.email.EmailSend;
import cn.bunny.pojo.email.EmailSendInit;
import cn.bunny.entity.system.email.EmailTemplate;
import cn.bunny.entity.system.email.EmailUsers;
import cn.bunny.entity.system.user.User;
import cn.bunny.module.mail.utils.MailSenderUtil;
import cn.bunny.pojo.email.EmailSend;
import cn.bunny.pojo.email.EmailSendInit;
import cn.bunny.pojo.result.constant.ExceptionConstant;
import cn.bunny.pojo.result.constant.MailMessageConstant;
import cn.bunny.pojo.result.constant.RedisUserConstant;
@ -171,4 +171,15 @@ public class LoginServiceImpl extends ServiceImpl<UserMapper, User> implements L
// 删除Redis中用户信息
redisTemplate.delete(RedisUserConstant.getUserLoginInfoPrefix(user.getEmail()));
}
/**
* * 生成图片验证码
*
* @return 验证码图片
*/
@Override
public byte[] checkCodeImage() {
CircleCaptcha captcha = CaptchaUtil.createCircleCaptcha(150, 48, 4, 2);
return captcha.getImageBytes();
}
}

View File

@ -23,11 +23,11 @@ spring:
grace-destroy: false #是否优雅关闭数据源默认为false设置为true时关闭数据源时如果数据源中还存在活跃连接至多等待10s后强制关闭
datasource:
master:
driver-class-name: com.zaxxer.hikari.HikariDataSource
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://${bunny.datasource.host}:${bunny.datasource.port}/${bunny.datasource.sqlData}?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true
username: ${bunny.datasource.username}
password: ${bunny.datasource.password}
#
aop:
enabled: true