feat(修改): 🐛 图形验证码生成;
This commit is contained in:
parent
7ac9b68141
commit
92fc93e5b4
|
@ -89,7 +89,8 @@ public class WebSecurityConfig {
|
||||||
@Bean
|
@Bean
|
||||||
public WebSecurityCustomizer webSecurityCustomizer() {
|
public WebSecurityCustomizer webSecurityCustomizer() {
|
||||||
String[] annotations = {"/", "/test/**", "/diagram-viewer/**", "/editor-app/**", "/*.html",
|
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);
|
return web -> web.ignoring().requestMatchers(annotations);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,8 @@ spring:
|
||||||
grace-destroy: false #是否优雅关闭数据源,默认为false,设置为true时,关闭数据源时如果数据源中还存在活跃连接,至多等待10s后强制关闭
|
grace-destroy: false #是否优雅关闭数据源,默认为false,设置为true时,关闭数据源时如果数据源中还存在活跃连接,至多等待10s后强制关闭
|
||||||
datasource:
|
datasource:
|
||||||
master:
|
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
|
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}
|
username: ${bunny.datasource.username}
|
||||||
password: ${bunny.datasource.password}
|
password: ${bunny.datasource.password}
|
||||||
|
|
|
@ -30,8 +30,9 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addInterceptors(InterceptorRegistry registry) {
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
String[] excludeList = {"/api/checkCode", "/api/sendEmailCode", "/api/register", "/api/login", "/api/article/loadArticle/**"};
|
|
||||||
log.info("WebMvcConfiguration===>开始注册自定义拦截器...");
|
log.info("WebMvcConfiguration===>开始注册自定义拦截器...");
|
||||||
|
|
||||||
|
String[] excludeList = {"/api/**", "/api/sendEmailCode", "/api/register", "/api/login", "/**"};
|
||||||
registry.addInterceptor(userTokenInterceptor).addPathPatterns("/api/**")
|
registry.addInterceptor(userTokenInterceptor).addPathPatterns("/api/**")
|
||||||
.excludePathPatterns(excludeList);
|
.excludePathPatterns(excludeList);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,10 @@ import cn.bunny.vo.system.login.ValidateCodeVo;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@Tag(name = "登录和注册相关接口")
|
@Tag(name = "登录和注册相关接口")
|
||||||
|
@ -32,6 +36,16 @@ public class LoginController {
|
||||||
return Result.success(vo);
|
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 = "发送邮箱验证码")
|
@Operation(summary = "发送邮箱验证码", description = "发送邮箱验证码")
|
||||||
@PostMapping("sendEmailCode")
|
@PostMapping("sendEmailCode")
|
||||||
public Result<String> sendEmailCode(String email) {
|
public Result<String> sendEmailCode(String email) {
|
||||||
|
|
|
@ -41,4 +41,11 @@ public interface LoginService extends IService<User> {
|
||||||
* 退出登录
|
* 退出登录
|
||||||
*/
|
*/
|
||||||
void logout();
|
void logout();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 生成图片验证码
|
||||||
|
*
|
||||||
|
* @return 验证码图片
|
||||||
|
*/
|
||||||
|
byte[] checkCodeImage();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,12 +6,12 @@ import cn.bunny.common.service.utils.EmptyUtil;
|
||||||
import cn.bunny.common.service.utils.JwtHelper;
|
import cn.bunny.common.service.utils.JwtHelper;
|
||||||
import cn.bunny.dto.user.LoginDto;
|
import cn.bunny.dto.user.LoginDto;
|
||||||
import cn.bunny.dto.user.RegisterDto;
|
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.EmailTemplate;
|
||||||
import cn.bunny.entity.system.email.EmailUsers;
|
import cn.bunny.entity.system.email.EmailUsers;
|
||||||
import cn.bunny.entity.system.user.User;
|
import cn.bunny.entity.system.user.User;
|
||||||
import cn.bunny.module.mail.utils.MailSenderUtil;
|
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.ExceptionConstant;
|
||||||
import cn.bunny.pojo.result.constant.MailMessageConstant;
|
import cn.bunny.pojo.result.constant.MailMessageConstant;
|
||||||
import cn.bunny.pojo.result.constant.RedisUserConstant;
|
import cn.bunny.pojo.result.constant.RedisUserConstant;
|
||||||
|
@ -171,4 +171,15 @@ public class LoginServiceImpl extends ServiceImpl<UserMapper, User> implements L
|
||||||
// 删除Redis中用户信息
|
// 删除Redis中用户信息
|
||||||
redisTemplate.delete(RedisUserConstant.getUserLoginInfoPrefix(user.getEmail()));
|
redisTemplate.delete(RedisUserConstant.getUserLoginInfoPrefix(user.getEmail()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 生成图片验证码
|
||||||
|
*
|
||||||
|
* @return 验证码图片
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public byte[] checkCodeImage() {
|
||||||
|
CircleCaptcha captcha = CaptchaUtil.createCircleCaptcha(150, 48, 4, 2);
|
||||||
|
return captcha.getImageBytes();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,11 +23,11 @@ spring:
|
||||||
grace-destroy: false #是否优雅关闭数据源,默认为false,设置为true时,关闭数据源时如果数据源中还存在活跃连接,至多等待10s后强制关闭
|
grace-destroy: false #是否优雅关闭数据源,默认为false,设置为true时,关闭数据源时如果数据源中还存在活跃连接,至多等待10s后强制关闭
|
||||||
datasource:
|
datasource:
|
||||||
master:
|
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
|
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}
|
username: ${bunny.datasource.username}
|
||||||
password: ${bunny.datasource.password}
|
password: ${bunny.datasource.password}
|
||||||
#
|
|
||||||
aop:
|
aop:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue