Skip to content

Commit

Permalink
Merge pull request #2 from dustlight-cn/dev
Browse files Browse the repository at this point in the history
v0.0.3-SNAPSHOT。1、仓库转移。2、RandomStringCodeGenerator 允许通过参数 'CODE_CHARS…
  • Loading branch information
Hansin1997 authored Dec 21, 2020
2 parents 07acea4 + dce421c commit 3adf620
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 108 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# CAPTCHA
[![Build Status](https://travis-ci.org/Hansin1997/captcha.svg?branch=main)](https://travis-ci.org/Hansin1997/captcha)
[![GitHub](https://img.shields.io/github/license/Hansin1997/captcha)](LICENSE)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/Hansin1997/captcha)](https://github.com/Hansin1997/captcha/releases)
[![Build Status](https://travis-ci.org/dustlight-cn/captcha.svg?branch=main)](https://travis-ci.org/dustlight-cn/captcha)
[![GitHub](https://img.shields.io/github/license/dustlight-cn/captcha)](LICENSE)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/dustlight-cn/captcha)](https://github.com/dustlight-cn/captcha/releases)

## 简介
**CAPTCHA** 是一个基于 **Spring Boot** 框架的验证码框架,它通过 AOP 的方式完成包含验证码生成、发送、存储等验证码相关业务,以避免与业务代码耦合。
Expand Down Expand Up @@ -157,4 +157,4 @@ public class TestController {
集成邮箱验证码发送功能。

## 获取帮助
如果需要报告问题或者功能需求,请在Github中 [创建issue](https://github.com/Hansin1997/captcha/issues/new) 。若有其他问题或建议,请发送电子邮件至 [[email protected]](mailto:[email protected])
如果需要报告问题或者功能需求,请在Github中 [创建issue](https://github.com/dustlight-cn/captcha/issues/new) 。若有其他问题或建议,请发送电子邮件至 [[email protected]](mailto:[email protected])
2 changes: 1 addition & 1 deletion captcha-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
[StringCodeVerifier](src/main/java/cn/dustlight/captcha/verifier/StringCodeVerifier.java) 是验证码校验器的默认实现,它将验证码值作为字符串进行比较,可以选择是否裁剪空白以及大小写敏感。

## 获取帮助
如果需要报告问题或者功能需求,请在Github中 [创建issue](https://github.com/Hansin1997/captcha/issues/new) 。若有其他问题或建议,请发送电子邮件至 [[email protected]](mailto:[email protected])
如果需要报告问题或者功能需求,请在Github中 [创建issue](https://github.com/dustlight-cn/captcha/issues/new) 。若有其他问题或建议,请发送电子邮件至 [[email protected]](mailto:[email protected])
25 changes: 6 additions & 19 deletions captcha-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>cn.dustlight.captcha</groupId>
<artifactId>captcha</artifactId>
<version>0.0.2</version>
<version>0.0.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>captcha-core</artifactId>
Expand Down Expand Up @@ -61,21 +61,8 @@
</plugin>
</plugins>
</build>

<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<name>OSS Snapshots Repository</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<name>OSS Staging Repository</name>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>

<url>https://github.com/Hansin1997/captcha</url>

<url>https://github.com/dustlight-cn/captcha</url>

<licenses>
<license>
Expand All @@ -94,9 +81,9 @@
</developers>

<scm>
<connection>scm:git:https://github.com/Hansin1997/captcha.git</connection>
<developerConnection>scm:git:https://github.com/Hansin1997/captcha.git</developerConnection>
<url>https://github.com/Hansin1997/captcha</url>
<connection>scm:git:https://github.com/dustlight-cn/captcha.git</connection>
<developerConnection>scm:git:https://github.com/dustlight-cn/captcha.git</developerConnection>
<url>https://github.com/dustlight-cn/captcha</url>
</scm>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public RandomStringCodeGenerator() {

public Code<String> generate(String name, Map<String, Object> parameters) throws GenerateCodeException {
try {
int len = this.length;
char[] chars = this.chars;
int len = length(parameters);
char[] chars = chars(parameters);
StringBuilder builder = new StringBuilder(length);
for (int i = 0; i < len; i++)
builder.append(chars[secureRandom.nextInt(chars.length)]);
Expand All @@ -57,4 +57,20 @@ public char[] getChars() {
public int getLength() {
return length;
}

private char[] chars(Map<String, Object> parameters) {
if (parameters == null ||
!parameters.containsKey("CODE_CHARS") ||
parameters.get("CODE_CHARS") == null)
return this.chars;
return parameters.get("CODE_CHARS").toString().toCharArray();
}

private int length(Map<String, Object> parameters) {
if (parameters == null ||
!parameters.containsKey("CODE_LENGTH") ||
parameters.get("CODE_LENGTH") == null)
return this.length;
return Integer.parseInt(parameters.get("CODE_LENGTH").toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public void send(Code<T> code, Map<String, Object> parameters) throws SendCodeEx
try {
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletResponse response = requestAttributes.getResponse();
image = imageHandler.getImage(code.getValue().toString(), width, height, parameters);
image = imageHandler.getImage(code.getValue().toString(),
width(parameters),
height(parameters),
parameters);
response.setStatus(200);
response.setContentType("image/jpeg");
ImageIO.write(image, "jpeg", new BufferedOutputStream(response.getOutputStream()));
Expand All @@ -53,6 +56,22 @@ public void send(Code<T> code, Map<String, Object> parameters) throws SendCodeEx
}
}

private int width(Map<String, Object> parameters) {
if (parameters == null ||
!parameters.containsKey("IMAGE_WIDTH") ||
parameters.get("IMAGE_WIDTH") == null)
return this.width;
return Integer.parseInt(parameters.get("IMAGE_WIDTH").toString());
}

private int height(Map<String, Object> parameters) {
if (parameters == null ||
!parameters.containsKey("IMAGE_HEIGHT") ||
parameters.get("IMAGE_HEIGHT") == null)
return this.height;
return Integer.parseInt(parameters.get("IMAGE_HEIGHT").toString());
}

public ImageHandler getImageHandler() {
return imageHandler;
}
Expand Down
2 changes: 1 addition & 1 deletion extensions/email-sender/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,4 @@ public class EmailController {
收到验证码后,打开 [http://localhost:8080/verify?code=xx](http://localhost:8080/verify?code=xx) 进行验证。(将 xx 改为您收到的验证码)

## 获取帮助
如果需要报告问题或者功能需求,请在Github中 [创建issue](https://github.com/Hansin1997/captcha/issues/new) 。若有其他问题或建议,请发送电子邮件至 [[email protected]](mailto:[email protected])
如果需要报告问题或者功能需求,请在Github中 [创建issue](https://github.com/dustlight-cn/captcha/issues/new) 。若有其他问题或建议,请发送电子邮件至 [[email protected]](mailto:[email protected])
23 changes: 5 additions & 18 deletions extensions/email-sender/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>cn.dustlight.captcha</groupId>
<artifactId>captcha</artifactId>
<version>0.0.2</version>
<version>0.0.3-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>email-sender</artifactId>
Expand Down Expand Up @@ -60,20 +60,7 @@
</plugins>
</build>

<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<name>OSS Snapshots Repository</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<name>OSS Staging Repository</name>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>

<url>https://github.com/Hansin1997/captcha</url>
<url>https://github.com/dustlight-cn/captcha</url>

<licenses>
<license>
Expand All @@ -92,9 +79,9 @@
</developers>

<scm>
<connection>scm:git:https://github.com/Hansin1997/captcha.git</connection>
<developerConnection>scm:git:https://github.com/Hansin1997/captcha.git</developerConnection>
<url>https://github.com/Hansin1997/captcha</url>
<connection>scm:git:https://github.com/dustlight-cn/captcha.git</connection>
<developerConnection>scm:git:https://github.com/dustlight-cn/captcha.git</developerConnection>
<url>https://github.com/dustlight-cn/captcha</url>
</scm>

</project>
2 changes: 1 addition & 1 deletion extensions/reCAPTCHA/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,4 @@ public class TestController {
| [http://localhost:8080/v3.html](http://localhost:8080/v3.html) | reCAPTCHA v3 测试页面 |

## 获取帮助
如果需要报告问题或者功能需求,请在Github中 [创建issue](https://github.com/Hansin1997/captcha/issues/new) 。若有其他问题或建议,请发送电子邮件至 [[email protected]](mailto:[email protected])
如果需要报告问题或者功能需求,请在Github中 [创建issue](https://github.com/dustlight-cn/captcha/issues/new) 。若有其他问题或建议,请发送电子邮件至 [[email protected]](mailto:[email protected])
23 changes: 5 additions & 18 deletions extensions/reCAPTCHA/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>cn.dustlight.captcha</groupId>
<artifactId>captcha</artifactId>
<version>0.0.2</version>
<version>0.0.3-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>recaptcha</artifactId>
Expand Down Expand Up @@ -55,20 +55,7 @@
</plugins>
</build>

<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<name>OSS Snapshots Repository</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<name>OSS Staging Repository</name>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>

<url>https://github.com/Hansin1997/captcha</url>
<url>https://github.com/dustlight-cn/captcha</url>

<licenses>
<license>
Expand All @@ -87,9 +74,9 @@
</developers>

<scm>
<connection>scm:git:https://github.com/Hansin1997/captcha.git</connection>
<developerConnection>scm:git:https://github.com/Hansin1997/captcha.git</developerConnection>
<url>https://github.com/Hansin1997/captcha</url>
<connection>scm:git:https://github.com/dustlight-cn/captcha.git</connection>
<developerConnection>scm:git:https://github.com/dustlight-cn/captcha.git</developerConnection>
<url>https://github.com/dustlight-cn/captcha</url>
</scm>

</project>
2 changes: 1 addition & 1 deletion extensions/redis-store/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ dustlight.captcha.store.redis.key-prefix=CAPTCHA_CODE
```

## 获取帮助
如果需要报告问题或者功能需求,请在Github中 [创建issue](https://github.com/Hansin1997/captcha/issues/new) 。若有其他问题或建议,请发送电子邮件至 [[email protected]](mailto:[email protected])
如果需要报告问题或者功能需求,请在Github中 [创建issue](https://github.com/dustlight-cn/captcha/issues/new) 。若有其他问题或建议,请发送电子邮件至 [[email protected]](mailto:[email protected])
23 changes: 5 additions & 18 deletions extensions/redis-store/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>cn.dustlight.captcha</groupId>
<artifactId>captcha</artifactId>
<version>0.0.2</version>
<version>0.0.3-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>redis-store</artifactId>
Expand Down Expand Up @@ -60,20 +60,7 @@
</plugins>
</build>

<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<name>OSS Snapshots Repository</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<name>OSS Staging Repository</name>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>

<url>https://github.com/Hansin1997/captcha</url>
<url>https://github.com/dustlight-cn/captcha</url>

<licenses>
<license>
Expand All @@ -92,9 +79,9 @@
</developers>

<scm>
<connection>scm:git:https://github.com/Hansin1997/captcha.git</connection>
<developerConnection>scm:git:https://github.com/Hansin1997/captcha.git</developerConnection>
<url>https://github.com/Hansin1997/captcha</url>
<connection>scm:git:https://github.com/dustlight-cn/captcha.git</connection>
<developerConnection>scm:git:https://github.com/dustlight-cn/captcha.git</developerConnection>
<url>https://github.com/dustlight-cn/captcha</url>
</scm>

</project>
2 changes: 1 addition & 1 deletion extensions/tencent-sms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,4 @@ public class TestController {
运行您的项目,打开 [http://localhost:8080/](http://localhost:8080/) 进行测试。

## 获取帮助
如果需要报告问题或者功能需求,请在Github中 [创建issue](https://github.com/Hansin1997/captcha/issues/new) 。若有其他问题或建议,请发送电子邮件至 [[email protected]](mailto:[email protected])
如果需要报告问题或者功能需求,请在Github中 [创建issue](https://github.com/dustlight-cn/captcha/issues/new) 。若有其他问题或建议,请发送电子邮件至 [[email protected]](mailto:[email protected])
23 changes: 5 additions & 18 deletions extensions/tencent-sms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>cn.dustlight.captcha</groupId>
<artifactId>captcha</artifactId>
<version>0.0.2</version>
<version>0.0.3-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>tencent-sms</artifactId>
Expand Down Expand Up @@ -57,20 +57,7 @@
</plugins>
</build>

<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<name>OSS Snapshots Repository</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<name>OSS Staging Repository</name>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>

<url>https://github.com/Hansin1997/captcha</url>
<url>https://github.com/dustlight-cn/captcha</url>

<licenses>
<license>
Expand All @@ -89,9 +76,9 @@
</developers>

<scm>
<connection>scm:git:https://github.com/Hansin1997/captcha.git</connection>
<developerConnection>scm:git:https://github.com/Hansin1997/captcha.git</developerConnection>
<url>https://github.com/Hansin1997/captcha</url>
<connection>scm:git:https://github.com/dustlight-cn/captcha.git</connection>
<developerConnection>scm:git:https://github.com/dustlight-cn/captcha.git</developerConnection>
<url>https://github.com/dustlight-cn/captcha</url>
</scm>

</project>
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<packaging>pom</packaging>
<groupId>cn.dustlight.captcha</groupId>
<artifactId>captcha</artifactId>
<version>0.0.2</version>
<version>0.0.3-SNAPSHOT</version>
<name>captcha</name>
<description>CAPTCHA service parent project for Spring Boot</description>

Expand Down Expand Up @@ -154,7 +154,7 @@
</repository>
</distributionManagement>

<url>https://github.com/Hansin1997/captcha</url>
<url>https://github.com/dustlight-cn/captcha</url>

<licenses>
<license>
Expand All @@ -173,8 +173,8 @@
</developers>

<scm>
<connection>scm:git:https://github.com/Hansin1997/captcha.git</connection>
<developerConnection>scm:git:https://github.com/Hansin1997/captcha.git</developerConnection>
<url>https://github.com/Hansin1997/captcha</url>
<connection>scm:git:https://github.com/dustlight-cn/captcha.git</connection>
<developerConnection>scm:git:https://github.com/dustlight-cn/captcha.git</developerConnection>
<url>https://github.com/dustlight-cn/captcha</url>
</scm>
</project>

0 comments on commit 3adf620

Please sign in to comment.