Browse Source

修改登陆验证码。

master
刘忱 2 years ago
parent
commit
b3759ecb59
  1. 21
      win-dependencies/pom.xml
  2. 6
      win-framework/win-spring-boot-starter-captcha/pom.xml
  3. 24
      win-framework/win-spring-boot-starter-captcha/src/main/java/com/win/framework/captcha/config/CaptchaProperties.java
  4. 84
      win-framework/win-spring-boot-starter-captcha/src/main/java/com/win/framework/captcha/config/WinCaptchaConfiguration.java
  5. 28
      win-framework/win-spring-boot-starter-captcha/src/main/java/com/win/framework/captcha/core/enums/CaptchaRedisKeyConstants.java
  6. 57
      win-framework/win-spring-boot-starter-captcha/src/main/java/com/win/framework/captcha/core/service/RedisCaptchaServiceImpl.java
  7. 15
      win-framework/win-spring-boot-starter-captcha/src/main/java/com/win/framework/captcha/enums/CaptchaRedisKeyConstants.java
  8. 1
      win-framework/win-spring-boot-starter-captcha/src/main/resources/META-INF/services/com.xingyuv.captcha.service.CaptchaCacheService
  9. 1
      win-framework/win-spring-boot-starter-captcha/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
  10. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/original/bg1.png
  11. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/original/bg2.png
  12. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/original/bg3.png
  13. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/original/bg4.png
  14. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/original/bg5.png
  15. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/original/bg6.png
  16. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/original/bg7.png
  17. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/original/bg8.png
  18. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/original/bg9.png
  19. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/slidingBlock/1.png
  20. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/slidingBlock/11/10.png
  21. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/slidingBlock/11/11.png
  22. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/slidingBlock/11/12.png
  23. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/slidingBlock/11/13.png
  24. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/slidingBlock/11/14.png
  25. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/slidingBlock/11/15.png
  26. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/slidingBlock/11/16.png
  27. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/slidingBlock/11/17.png
  28. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/slidingBlock/11/18.png
  29. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/slidingBlock/11/19.png
  30. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/slidingBlock/11/8.png
  31. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/slidingBlock/11/9.png
  32. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/slidingBlock/2.png
  33. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/slidingBlock/3.png
  34. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/slidingBlock/4.png
  35. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/pic-click/bg1.png
  36. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/pic-click/bg10.png
  37. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/pic-click/bg2.png
  38. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/pic-click/bg3.png
  39. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/pic-click/bg4.png
  40. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/pic-click/bg5.png
  41. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/pic-click/bg6.png
  42. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/pic-click/bg7.png
  43. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/pic-click/bg8.png
  44. BIN
      win-framework/win-spring-boot-starter-captcha/src/main/resources/images/pic-click/bg9.png
  45. 2
      win-framework/win-spring-boot-starter-redis/src/main/java/com/win/framework/redis/util/RedisCache.java
  46. 3
      win-framework/win-spring-boot-starter-redis/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
  47. 1
      win-module-infra/win-module-infra-biz/pom.xml
  48. 8
      win-module-system/win-module-system-api/src/main/java/com/win/module/system/enums/ErrorCodeConstants.java
  49. 2
      win-module-system/win-module-system-api/src/main/java/com/win/module/system/enums/logger/LoginResultEnum.java
  50. 17
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/admin/auth/vo/AuthLoginReqVO.java
  51. 116
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/admin/captcha/CaptchaController.java
  52. 53
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/auth/AdminAuthServiceImpl.java
  53. 2
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/serialnumber/SerialNumberServiceImpl.java
  54. 20
      win-server/src/main/resources/application.yaml

21
win-dependencies/pom.xml

@ -69,9 +69,9 @@
<aliyun-java-sdk-core.version>4.6.3</aliyun-java-sdk-core.version>
<aliyun-java-sdk-dysmsapi.version>2.2.1</aliyun-java-sdk-dysmsapi.version>
<tencentcloud-sdk-java.version>3.1.758</tencentcloud-sdk-java.version>
<justauth.version>1.0.4</justauth.version>
<jimureport.version>1.6.1</jimureport.version>
<xercesImpl.version>2.12.2</xercesImpl.version>
<kaptcha.version>2.3.3</kaptcha.version>
</properties>
<dependencyManagement>
@ -543,6 +543,19 @@
<version>${jsoup.version}</version>
</dependency>
<!-- 验证码 -->
<dependency>
<groupId>pro.fessional</groupId>
<artifactId>kaptcha</artifactId>
<version>${kaptcha.version}</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- 三方云服务相关 -->
<dependency>
<groupId>com.squareup.okio</groupId>
@ -593,12 +606,6 @@
</dependency>
<!-- SMS SDK end -->
<dependency>
<groupId>com.xingyuv</groupId>
<artifactId>spring-boot-starter-justauth</artifactId> <!-- 社交登陆(例如说,个人微信、企业微信等等) -->
<version>${justauth.version}</version>
</dependency>
<!-- 积木报表-->
<dependency>
<groupId>org.jeecgframework.jimureport</groupId>

6
win-framework/win-spring-boot-starter-captcha/pom.xml

@ -17,10 +17,12 @@
</description>
<dependencies>
<!-- 验证码 -->
<dependency>
<groupId>com.xingyuv</groupId>
<artifactId>spring-boot-starter-captcha-plus</artifactId>
<groupId>pro.fessional</groupId>
<artifactId>kaptcha</artifactId>
</dependency>
<!-- Spring 核心 -->
<dependency>
<groupId>org.springframework.boot</groupId>

24
win-framework/win-spring-boot-starter-captcha/src/main/java/com/win/framework/captcha/config/CaptchaProperties.java

@ -0,0 +1,24 @@
package com.win.framework.captcha.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "win.captcha")
@Data
public class CaptchaProperties {
/**
* 验证码的开关
*/
private Boolean enable;
/**
* 验证码类型 math 数组计算 char 字符验证
*/
private String captchaType;
/**
* 验证码有效期
*/
private Integer captchaExpiration;
}

84
win-framework/win-spring-boot-starter-captcha/src/main/java/com/win/framework/captcha/config/WinCaptchaConfiguration.java

@ -1,29 +1,77 @@
package com.win.framework.captcha.config;
import com.win.framework.captcha.core.service.RedisCaptchaServiceImpl;
import com.xingyuv.captcha.properties.AjCaptchaProperties;
import com.xingyuv.captcha.service.CaptchaCacheService;
import com.xingyuv.captcha.service.impl.CaptchaServiceFactory;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.StringRedisTemplate;
import javax.annotation.Resource;
import java.util.Properties;
import static com.google.code.kaptcha.Constants.*;
@AutoConfiguration
public class WinCaptchaConfiguration {
@Resource
private StringRedisTemplate stringRedisTemplate;
@Bean
public CaptchaCacheService captchaCacheService(AjCaptchaProperties config) {
// 缓存类型 redis/local/....
CaptchaCacheService ret = CaptchaServiceFactory.getCache(config.getCacheType().name());
if (ret instanceof RedisCaptchaServiceImpl) {
((RedisCaptchaServiceImpl) ret).setStringRedisTemplate(stringRedisTemplate);
}
return ret;
@Bean(name = "captchaProducer")
public DefaultKaptcha getKaptchaBean() {
DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
Properties properties = new Properties();
// 是否有边框 默认为true 我们可以自己设置yes,no
properties.setProperty(KAPTCHA_BORDER, "yes");
// 验证码文本字符颜色 默认为Color.BLACK
properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_COLOR, "black");
// 验证码图片宽度 默认为200
properties.setProperty(KAPTCHA_IMAGE_WIDTH, "160");
// 验证码图片高度 默认为50
properties.setProperty(KAPTCHA_IMAGE_HEIGHT, "60");
// 验证码文本字符大小 默认为40
properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_SIZE, "38");
// KAPTCHA_SESSION_KEY
properties.setProperty(KAPTCHA_SESSION_CONFIG_KEY, "kaptchaCode");
// 验证码文本字符长度 默认为5
properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, "4");
// 验证码文本字体样式 默认为new Font("Arial", 1, fontSize), new Font("Courier", 1, fontSize)
properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_NAMES, "Arial,Courier");
// 图片样式 水纹com.google.code.kaptcha.impl.WaterRipple 鱼眼com.google.code.kaptcha.impl.FishEyeGimpy 阴影com.google.code.kaptcha.impl.ShadowGimpy
properties.setProperty(KAPTCHA_OBSCURIFICATOR_IMPL, "com.google.code.kaptcha.impl.ShadowGimpy");
Config config = new Config(properties);
defaultKaptcha.setConfig(config);
return defaultKaptcha;
}
@Bean(name = "captchaProducerMath")
public DefaultKaptcha getKaptchaBeanMath() {
DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
Properties properties = new Properties();
// 是否有边框 默认为true 我们可以自己设置yes,no
properties.setProperty(KAPTCHA_BORDER, "yes");
// 边框颜色 默认为Color.BLACK
properties.setProperty(KAPTCHA_BORDER_COLOR, "105,179,90");
// 验证码文本字符颜色 默认为Color.BLACK
properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_COLOR, "blue");
// 验证码图片宽度 默认为200
properties.setProperty(KAPTCHA_IMAGE_WIDTH, "160");
// 验证码图片高度 默认为50
properties.setProperty(KAPTCHA_IMAGE_HEIGHT, "60");
// 验证码文本字符大小 默认为40
properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_SIZE, "35");
// KAPTCHA_SESSION_KEY
properties.setProperty(KAPTCHA_SESSION_CONFIG_KEY, "kaptchaCodeMath");
// 验证码文本生成器
properties.setProperty(KAPTCHA_TEXTPRODUCER_IMPL, "com.win.tms.framework.config.KaptchaTextCreator");
// 验证码文本字符间距 默认为2
properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_SPACE, "3");
// 验证码文本字符长度 默认为5
properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, "6");
// 验证码文本字体样式 默认为new Font("Arial", 1, fontSize), new Font("Courier", 1, fontSize)
properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_NAMES, "Arial,Courier");
// 验证码噪点颜色 默认为Color.BLACK
properties.setProperty(KAPTCHA_NOISE_COLOR, "white");
// 干扰实现类
properties.setProperty(KAPTCHA_NOISE_IMPL, "com.google.code.kaptcha.impl.NoNoise");
// 图片样式 水纹com.google.code.kaptcha.impl.WaterRipple 鱼眼com.google.code.kaptcha.impl.FishEyeGimpy 阴影com.google.code.kaptcha.impl.ShadowGimpy
properties.setProperty(KAPTCHA_OBSCURIFICATOR_IMPL, "com.google.code.kaptcha.impl.ShadowGimpy");
Config config = new Config(properties);
defaultKaptcha.setConfig(config);
return defaultKaptcha;
}
}

28
win-framework/win-spring-boot-starter-captcha/src/main/java/com/win/framework/captcha/core/enums/CaptchaRedisKeyConstants.java

@ -1,28 +0,0 @@
package com.win.framework.captcha.core.enums;
/**
* 验证码 Redis Key 枚举类
*
* @author 闻荫源码
*/
public interface CaptchaRedisKeyConstants {
/**
* 验证码的请求限流
*
* KEY 格式AJ.CAPTCHA.REQ.LIMIT-%s-%s
* VALUE 数据类型String // 例如说:验证失败 5 次,get 接口锁定
* 过期时间60
*/
String AJ_CAPTCHA_REQ_LIMIT = "AJ.CAPTCHA.REQ.LIMIT-%s-%s";
/**
* 验证码的坐标
*
* KEY 格式RUNNING:CAPTCHA:%s // AbstractCaptchaService.REDIS_CAPTCHA_KEY
* VALUE 数据类型String // PointVO.class {"secretKey":"PP1w2Frr2KEejD2m","x":162,"y":5}
* 过期时间120
*/
String AJ_CAPTCHA_RUNNING = "RUNNING:CAPTCHA:%s";
}

57
win-framework/win-spring-boot-starter-captcha/src/main/java/com/win/framework/captcha/core/service/RedisCaptchaServiceImpl.java

@ -1,57 +0,0 @@
package com.win.framework.captcha.core.service;
import com.xingyuv.captcha.service.CaptchaCacheService;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import org.springframework.data.redis.core.StringRedisTemplate;
import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;
/**
* 基于 Redis 实现验证码的存储
*
* @author 星语
*/
@NoArgsConstructor // 保证 aj-captcha 的 SPI 创建
@AllArgsConstructor
public class RedisCaptchaServiceImpl implements CaptchaCacheService {
@Resource // 保证 aj-captcha 的 SPI 创建时的注入
private StringRedisTemplate stringRedisTemplate;
@Override
public String type() {
return "redis";
}
public void setStringRedisTemplate(StringRedisTemplate stringRedisTemplate) {
this.stringRedisTemplate = stringRedisTemplate;
}
@Override
public void set(String key, String value, long expiresInSeconds) {
stringRedisTemplate.opsForValue().set(key, value, expiresInSeconds, TimeUnit.SECONDS);
}
@Override
public boolean exists(String key) {
return Boolean.TRUE.equals(stringRedisTemplate.hasKey(key));
}
@Override
public void delete(String key) {
stringRedisTemplate.delete(key);
}
@Override
public String get(String key) {
return stringRedisTemplate.opsForValue().get(key);
}
@Override
public Long increment(String key, long val) {
return stringRedisTemplate.opsForValue().increment(key,val);
}
}

15
win-framework/win-spring-boot-starter-captcha/src/main/java/com/win/framework/captcha/enums/CaptchaRedisKeyConstants.java

@ -0,0 +1,15 @@
package com.win.framework.captcha.enums;
/**
* 验证码 Redis Key 枚举类
*
* @author 闻荫源码
*/
public interface CaptchaRedisKeyConstants {
/**
* 验证码 redis key
*/
String CAPTCHA_CODE_KEY = "captcha_codes:";
}

1
win-framework/win-spring-boot-starter-captcha/src/main/resources/META-INF/services/com.xingyuv.captcha.service.CaptchaCacheService

@ -1 +0,0 @@
com.win.framework.captcha.core.service.RedisCaptchaServiceImpl

1
win-framework/win-spring-boot-starter-captcha/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports

@ -1 +1,2 @@
com.win.framework.captcha.config.CaptchaProperties
com.win.framework.captcha.config.WinCaptchaConfiguration

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/original/bg1.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/original/bg2.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/original/bg3.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/original/bg4.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/original/bg5.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/original/bg6.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/original/bg7.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/original/bg8.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/original/bg9.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/slidingBlock/1.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/slidingBlock/11/10.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/slidingBlock/11/11.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/slidingBlock/11/12.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/slidingBlock/11/13.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/slidingBlock/11/14.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/slidingBlock/11/15.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/slidingBlock/11/16.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/slidingBlock/11/17.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/slidingBlock/11/18.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/slidingBlock/11/19.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/slidingBlock/11/8.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/slidingBlock/11/9.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/slidingBlock/2.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/slidingBlock/3.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/jigsaw/slidingBlock/4.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/pic-click/bg1.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/pic-click/bg10.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/pic-click/bg2.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/pic-click/bg3.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/pic-click/bg4.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/pic-click/bg5.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/pic-click/bg6.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/pic-click/bg7.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/pic-click/bg8.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

BIN
win-framework/win-spring-boot-starter-captcha/src/main/resources/images/pic-click/bg9.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

2
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/util/redis/RedisCache.java → win-framework/win-spring-boot-starter-redis/src/main/java/com/win/framework/redis/util/RedisCache.java

@ -1,4 +1,4 @@
package com.win.module.system.util.redis;
package com.win.framework.redis.util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.BoundSetOperations;

3
win-framework/win-spring-boot-starter-redis/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports

@ -1,2 +1,3 @@
com.win.framework.redis.config.WinRedisAutoConfiguration
com.win.framework.redis.config.WinCacheAutoConfiguration
com.win.framework.redis.config.WinCacheAutoConfiguration
com.win.framework.redis.util.RedisCache

1
win-module-infra/win-module-infra-biz/pom.xml

@ -79,7 +79,6 @@
</dependency>
<!-- 工具类相关 -->
<dependency>
<groupId>com.win</groupId>
<artifactId>win-spring-boot-starter-excel</artifactId>

8
win-module-system/win-module-system-api/src/main/java/com/win/module/system/enums/ErrorCodeConstants.java

@ -74,6 +74,9 @@ public interface ErrorCodeConstants {
// ========== 通知公告 1-002-008-000 ==========
ErrorCode NOTICE_NOT_FOUND = new ErrorCode(1_002_008_001, "当前通知公告不存在");
// ========== 登陆 1-002-009-000 ==========
ErrorCode GENERATE_IMAGE_ERROR = new ErrorCode(1_002_008_001, "生成图片错误");
// ========== 短信渠道 1-002-011-000 ==========
ErrorCode SMS_CHANNEL_NOT_EXISTS = new ErrorCode(1_002_011_000, "短信渠道不存在");
ErrorCode SMS_CHANNEL_DISABLE = new ErrorCode(1_002_011_001, "短信渠道不处于开启状态,不允许选择");
@ -114,11 +117,6 @@ public interface ErrorCodeConstants {
ErrorCode ERROR_CODE_NOT_EXISTS = new ErrorCode(1_002_017_000, "错误码不存在");
ErrorCode ERROR_CODE_DUPLICATE = new ErrorCode(1_002_017_001, "已经存在编码为【{}】的错误码");
// ========== 社交用户 1-002-018-000 ==========
ErrorCode SOCIAL_USER_AUTH_FAILURE = new ErrorCode(1_002_018_000, "社交授权失败,原因是:{}");
ErrorCode SOCIAL_USER_UNBIND_NOT_SELF = new ErrorCode(1_002_018_001, "社交解绑失败,非当前用户绑定");
ErrorCode SOCIAL_USER_NOT_FOUND = new ErrorCode(1_002_018_002, "社交授权失败,找不到对应的用户");
// ========== 系统敏感词 1-002-019-000 =========
ErrorCode SENSITIVE_WORD_NOT_EXISTS = new ErrorCode(1_002_019_000, "系统敏感词在所有标签中都不存在");
ErrorCode SENSITIVE_WORD_EXISTS = new ErrorCode(1_002_019_001, "系统敏感词已在标签中存在");

2
win-module-system/win-module-system-api/src/main/java/com/win/module/system/enums/logger/LoginResultEnum.java

@ -13,7 +13,7 @@ public enum LoginResultEnum {
SUCCESS(0), // 成功
BAD_CREDENTIALS(10), // 账号或密码不正确
USER_DISABLED(20), // 用户被禁用
CAPTCHA_NOT_FOUND(30), // 图片验证码不存在
CAPTCHA_EXPIRE(30), // 验证码超期
CAPTCHA_CODE_ERROR(31), // 图片验证码不正确
;

17
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/admin/auth/vo/AuthLoginReqVO.java

@ -28,16 +28,19 @@ public class AuthLoginReqVO {
@Length(min = 4, max = 16, message = "密码长度为 4-16 位")
private String password;
// ========== 图片验证码相关 ==========
// ========== 验证码相关 ==========
@Schema(description = "验证码,验证码开启时,需要传递", requiredMode = Schema.RequiredMode.REQUIRED,
example = "PfcH6mgr8tpXuMWFjvW6YVaqrswIuwmWI5dsVZSg7sGpWtDCUbHuDEXl3cFB1+VvCC/rAkSwK8Fad52FSuncVg==")
@NotEmpty(message = "验证码不能为空", groups = CodeEnableGroup.class)
private String captchaVerification;
/**
* 验证码
*/
@Schema(description = "验证码", requiredMode = Schema.RequiredMode.REQUIRED, example = "12")
@NotEmpty(message = "验证码不能为空")
private String code;
/**
* 开启验证码的 Group
* 唯一标识
*/
public interface CodeEnableGroup {}
@NotEmpty(message = "uuid不能为空")
private String uuid;
}

116
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/admin/captcha/CaptchaController.java

@ -1,61 +1,83 @@
package com.win.module.system.controller.admin.captcha;
import cn.hutool.core.util.StrUtil;
import com.win.framework.common.util.servlet.ServletUtils;
import com.win.framework.operatelog.core.annotations.OperateLog;
import com.xingyuv.captcha.model.common.ResponseModel;
import com.xingyuv.captcha.model.vo.CaptchaVO;
import com.xingyuv.captcha.service.CaptchaService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.util.IdUtil;
import com.google.code.kaptcha.Producer;
import com.win.framework.captcha.config.CaptchaProperties;
import com.win.framework.captcha.enums.CaptchaRedisKeyConstants;
import com.win.framework.common.pojo.CommonResult;
import com.win.framework.redis.util.RedisCache;
import com.win.module.system.enums.ErrorCodeConstants;
import org.springframework.util.FastByteArrayOutputStream;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.servlet.http.HttpServletRequest;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static com.win.framework.common.pojo.CommonResult.error;
import static com.win.framework.common.pojo.CommonResult.success;
/**
* 验证码
*
* @author 闻荫源码
* 验证码操作处理
*
* @author win
*/
@Tag(name = "管理后台 - 验证码")
@RestController("adminCaptchaController")
@RequestMapping("/system/captcha")
@RestController
public class CaptchaController {
@Resource(name = "captchaProducer")
private Producer captchaProducer;
@Resource
private CaptchaService captchaService;
@PostMapping({"/get"})
@Operation(summary = "获得验证码")
@PermitAll
@OperateLog(enable = false) // 避免 Post 请求被记录操作日志
public ResponseModel get(@RequestBody CaptchaVO data, HttpServletRequest request) {
assert request.getRemoteHost() != null;
data.setBrowserInfo(getRemoteId(request));
return captchaService.get(data);
}
@PostMapping("/check")
@Operation(summary = "校验验证码")
@PermitAll
@OperateLog(enable = false) // 避免 Post 请求被记录操作日志
public ResponseModel check(@RequestBody CaptchaVO data, HttpServletRequest request) {
data.setBrowserInfo(getRemoteId(request));
return captchaService.check(data);
}
private RedisCache redisCache;
@Resource(name = "captchaProducerMath")
private Producer captchaProducerMath;
@Resource
private CaptchaProperties captchaProperties;
public static String getRemoteId(HttpServletRequest request) {
String ip = ServletUtils.getClientIP(request);
String ua = request.getHeader("user-agent");
if (StrUtil.isNotBlank(ip)) {
return ip + ua;
/**
* 生成验证码
*/
@GetMapping("/captchaImage")
public CommonResult<Object> getCode(HttpServletResponse response) throws IOException {
Map<String, Object> data = new HashMap<>();
boolean captchaEnabled = captchaProperties.getEnable();
data.put("captchaEnabled", captchaEnabled);
if (!captchaEnabled) {
return success(data);
}
// 保存验证码信息
String uuid = IdUtil.simpleUUID();
String verifyKey = CaptchaRedisKeyConstants.CAPTCHA_CODE_KEY + uuid;
String capStr;
String code = null;
BufferedImage image = null;
// 生成验证码
String captchaType = captchaProperties.getCaptchaType();
if ("math".equals(captchaType)) {
String capText = captchaProducerMath.createText();
capStr = capText.substring(0, capText.lastIndexOf("@"));
code = capText.substring(capText.lastIndexOf("@") + 1);
image = captchaProducerMath.createImage(capStr);
} else if ("char".equals(captchaType)) {
capStr = code = captchaProducer.createText();
image = captchaProducer.createImage(capStr);
}
return request.getRemoteAddr() + ua;
redisCache.setCacheObject(verifyKey, code, captchaProperties.getCaptchaExpiration(), TimeUnit.MINUTES);
// 转换流信息写出
FastByteArrayOutputStream os = new FastByteArrayOutputStream();
try {
ImageIO.write(image, "jpg", os);
} catch (IOException e) {
return error(ErrorCodeConstants.GENERATE_IMAGE_ERROR);
}
data.put("uuid", uuid);
data.put("img", Base64.encode(os.toByteArray()));
return success(data);
}
}

53
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/auth/AdminAuthServiceImpl.java

@ -1,12 +1,13 @@
package com.win.module.system.service.auth;
import cn.hutool.core.util.ObjectUtil;
import com.google.common.annotations.VisibleForTesting;
import com.win.framework.captcha.config.CaptchaProperties;
import com.win.framework.captcha.enums.CaptchaRedisKeyConstants;
import com.win.framework.common.enums.CommonStatusEnum;
import com.win.framework.common.enums.UserTypeEnum;
import com.win.framework.common.util.monitor.TracerUtils;
import com.win.framework.common.util.servlet.ServletUtils;
import com.win.framework.common.util.validation.ValidationUtils;
import com.win.framework.redis.util.RedisCache;
import com.win.module.system.api.logger.dto.LoginLogCreateReqDTO;
import com.win.module.system.api.sms.SmsCodeApi;
import com.win.module.system.controller.admin.auth.vo.AuthLoginReqVO;
@ -21,10 +22,8 @@ import com.win.module.system.service.logger.LoginLogService;
import com.win.module.system.service.member.MemberService;
import com.win.module.system.service.oauth2.OAuth2TokenService;
import com.win.module.system.service.user.AdminUserService;
import com.xingyuv.captcha.model.common.ResponseModel;
import com.xingyuv.captcha.model.vo.CaptchaVO;
import com.xingyuv.captcha.service.CaptchaService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@ -55,9 +54,11 @@ public class AdminAuthServiceImpl implements AdminAuthService {
@Resource
private Validator validator;
@Resource
private CaptchaService captchaService;
@Resource
private SmsCodeApi smsCodeApi;
@Resource
private CaptchaProperties captchaProperties;
@Resource
private RedisCache redisCache;
/**
* 验证码的开关默认为 true
@ -89,15 +90,14 @@ public class AdminAuthServiceImpl implements AdminAuthService {
@Override
public AuthLoginRespVO login(AuthLoginReqVO reqVO) {
// 校验验证码
validateCaptcha(reqVO);
validateCaptcha(reqVO.getUsername(), reqVO.getCode(), reqVO.getUuid());
// 使用账号密码,进行登录
AdminUserDO user = authenticate(reqVO.getUsername(), reqVO.getPassword());
// 创建 Token 令牌,记录登录日志
return createTokenAfterLoginSuccess(user.getId(), reqVO.getUsername(), LoginLogTypeEnum.LOGIN_USERNAME);
}
private void createLoginLog(Long userId, String username,
LoginLogTypeEnum logTypeEnum, LoginResultEnum loginResult) {
private void createLoginLog(Long userId, String username, LoginLogTypeEnum logTypeEnum, LoginResultEnum loginResult) {
// 插入登录日志
LoginLogCreateReqDTO reqDTO = new LoginLogCreateReqDTO();
reqDTO.setLogType(logTypeEnum.getType());
@ -115,22 +115,25 @@ public class AdminAuthServiceImpl implements AdminAuthService {
}
}
@VisibleForTesting
void validateCaptcha(AuthLoginReqVO reqVO) {
// 如果验证码关闭,则不进行校验
if (!captchaEnable) {
return;
/**
* 校验验证码
*
* @param username 用户名
* @param code 验证码
* @param uuid 唯一标识
* @return 结果
*/
public void validateCaptcha(String username, String code, String uuid) {
String verifyKey = CaptchaRedisKeyConstants.CAPTCHA_CODE_KEY + StringUtils.defaultString(uuid, "");
String captcha = redisCache.getCacheObject(verifyKey);
redisCache.deleteObject(verifyKey);
if (captcha == null) {
createLoginLog(null, username, LoginLogTypeEnum.LOGIN_USERNAME, LoginResultEnum.CAPTCHA_EXPIRE);
throw exception(AUTH_LOGIN_CAPTCHA_CODE_ERROR);
}
// 校验验证码
ValidationUtils.validate(validator, reqVO, AuthLoginReqVO.CodeEnableGroup.class);
CaptchaVO captchaVO = new CaptchaVO();
captchaVO.setCaptchaVerification(reqVO.getCaptchaVerification());
ResponseModel response = captchaService.verification(captchaVO);
// 验证不通过
if (!response.isSuccess()) {
// 创建登录失败日志(验证码不正确)
createLoginLog(null, reqVO.getUsername(), LoginLogTypeEnum.LOGIN_USERNAME, LoginResultEnum.CAPTCHA_CODE_ERROR);
throw exception(AUTH_LOGIN_CAPTCHA_CODE_ERROR, response.getRepMsg());
if (!code.equalsIgnoreCase(captcha)) {
createLoginLog(null, username, LoginLogTypeEnum.LOGIN_USERNAME, LoginResultEnum.CAPTCHA_CODE_ERROR);
throw exception(AUTH_LOGIN_CAPTCHA_CODE_ERROR);
}
}

2
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/serialnumber/SerialNumberServiceImpl.java

@ -2,6 +2,7 @@ package com.win.module.system.service.serialnumber;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.win.framework.common.pojo.PageResult;
import com.win.framework.redis.util.RedisCache;
import com.win.module.system.controller.admin.serialnumber.vo.SerialNumberCreateReqVO;
import com.win.module.system.controller.admin.serialnumber.vo.SerialNumberExportReqVO;
import com.win.module.system.controller.admin.serialnumber.vo.SerialNumberPageReqVO;
@ -9,7 +10,6 @@ import com.win.module.system.controller.admin.serialnumber.vo.SerialNumberUpdate
import com.win.module.system.convert.serialnumber.SerialNumberConvert;
import com.win.module.system.dal.dataobject.serialnumber.SerialNumberDO;
import com.win.module.system.dal.mysql.serialnumber.SerialNumberMapper;
import com.win.module.system.util.redis.RedisCache;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

20
win-server/src/main/resources/application.yaml

@ -91,24 +91,6 @@ spring:
redis:
repositories:
enabled: false # 项目未使用到 Spring Data Redis 的 Repository,所以直接禁用,保证启动速度
--- #################### 验证码相关配置 ####################
aj:
captcha:
jigsaw: classpath:images/jigsaw # 滑动验证,底图路径,不配置将使用默认图片;以 classpath: 开头,取 resource 目录下路径
pic-click: classpath:images/pic-click # 滑动验证,底图路径,不配置将使用默认图片;以 classpath: 开头,取 resource 目录下路径
cache-type: redis # 缓存 local/redis...
cache-number: 1000 # local 缓存的阈值,达到这个值,清除缓存
timing-clear: 180 # local定时清除过期缓存(单位秒),设置为0代表不执行
type: blockPuzzle # 验证码类型 default两种都实例化。 blockPuzzle 滑块拼图 clickWord 文字点选
water-mark: 闻荫源码 # 右下角水印文字(我的水印),可使用 https://tool.chinaz.com/tools/unicode.aspx 中文转 Unicode,Linux 可能需要转 unicode
interference-options: 0 # 滑动干扰项(0/1/2)
req-frequency-limit-enable: false # 接口请求次数一分钟限制是否开启 true|false
req-get-lock-limit: 5 # 验证失败 5 次,get接口锁定
req-get-lock-seconds: 10 # 验证失败后,锁定时间间隔
req-get-minute-limit: 30 # get 接口一分钟内请求数限制
req-check-minute-limit: 60 # check 接口一分钟内请求数限制
req-verify-minute-limit: 60 # verify 接口一分钟内请求数限制
--- #################### 闻荫相关配置 ####################
@ -137,6 +119,8 @@ win:
license-url: https://gitee.com/zhijiantianya/ruoyi-vue-pro/blob/master/LICENSE
captcha:
enable: true # 验证码的开关,默认为 true
captchaType: math # 验证码类型 math 数组计算 char 字符验证
captchaExpiration: 2 # 验证码有效期分众
codegen:
base-package: ${win.info.base-package}
db-schemas: ${spring.datasource.dynamic.datasource.master.name}

Loading…
Cancel
Save