Skip to content

Commit

Permalink
Rename kapcha to kaptcha
Browse files Browse the repository at this point in the history
  • Loading branch information
oopsguy committed Dec 23, 2018
1 parent 75c0a39 commit fbdbac4
Show file tree
Hide file tree
Showing 18 changed files with 36 additions and 17 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Kaptcha Spring Boot Starter

Kaptcha Spring Boot Starter will help you use Google Kaptcha with Spring Boot.
Kaptcha Spring Boot Starter can help you use [Google Kaptcha](http://code.google.com/p/kaptcha/) with [Spring Boot](https://github.com/spring-projects/spring-boot) easier.

## Usage

Expand All @@ -10,7 +10,7 @@ Declare `kaptcha-spring-boot-starter` dependency in your `pom.xml` file.
<dependency>
<groupId>com.oopsguy.kaptcha</groupId>
<artifactId>kaptcha-spring-boot-starter</artifactId>
<version>1.0.0-beta</version>
<version>1.0.0-beta-2</version>
</dependency>
```

Expand Down Expand Up @@ -108,7 +108,7 @@ Then browse [http://localhost:8080/home/capthca](http://localhost:8080/home/capt
### Java Code
You can also inject `Producer` Bean directly by annotation to generate captcha.
You can also inject a `Producer` bean directly by annotation to generate captcha.

```java
@Controller
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<parent>
<groupId>com.oopsguy.kaptcha</groupId>
<artifactId>kaptcha-spring-boot-parent</artifactId>
<version>1.0.0-beta</version>
<version>1.0.0-beta-2</version>
<relativePath>../kaptcha-spring-boot-parent</relativePath>
</parent>
<packaging>jar</packaging>
<artifactId>kapcha-spring-boot-autoconfigure</artifactId>
<name>kapcha-spring-boot-autoconfigure</name>
<artifactId>kaptcha-spring-boot-autoconfigure</artifactId>
<name>kaptcha-spring-boot-autoconfigure</name>
<url>https://github.com/12software/kaptcha-spring-boot</url>
<description>Kaptcha Spring Boot AutoConfigurer</description>

Expand All @@ -19,6 +19,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
Expand All @@ -29,14 +34,14 @@
<artifactId>kaptcha</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
</dependencies>

</project>
4 changes: 2 additions & 2 deletions kaptcha-spring-boot-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>kaptcha-spring-boot</artifactId>
<groupId>com.oopsguy.kaptcha</groupId>
<version>1.0.0-beta</version>
<version>1.0.0-beta-2</version>
<relativePath>../</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand All @@ -17,7 +17,7 @@

<modules>
<module>../kaptcha</module>
<module>../kapcha-spring-boot-autoconfigure</module>
<module>../kaptcha-spring-boot-autoconfigure</module>
<module>../kaptcha-spring-boot-starter</module>
<module>../kaptcha-spring-boot-starter-example</module>
</modules>
Expand Down
2 changes: 1 addition & 1 deletion kaptcha-spring-boot-starter-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.oopsguy.kaptcha</groupId>
<artifactId>kaptcha-spring-boot-parent</artifactId>
<version>1.0.0-beta</version>
<version>1.0.0-beta-2</version>
<relativePath>../kaptcha-spring-boot-parent</relativePath>
</parent>
<artifactId>kaptcha-spring-boot-starter-example</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.util.Date;

@Controller
public class KaptchaController {

private final static String HOME_CAPTCHA_SESSION_KEY = "homeCaptcha";

private final static String HOME_CAPTCHA_SESSION_DATE = "homeCaptchaDate";

/**
* captcha expire time, millis
*/
private final static long VALID_MILLIS_TIME = 10 * 1000;

@Resource
private Producer captchaProducer;

Expand All @@ -44,7 +52,12 @@ public String checkHomeCaptcha(HttpServletRequest req) {
return "empty captcha";
}
String savedCaptcha = (String) req.getSession().getAttribute(HOME_CAPTCHA_SESSION_KEY);
Date sessionDate = (Date) req.getSession().getAttribute(HOME_CAPTCHA_SESSION_DATE);
if (captcha.equalsIgnoreCase(savedCaptcha)) {
if (sessionDate == null
|| System.currentTimeMillis() - sessionDate.getTime() > VALID_MILLIS_TIME) {
return "expired";
}
return "valid!";
}
return "invalid";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ kaptcha:
path: /home/captcha
session:
key: homeCaptcha
date: homeCaptchaDate
background:
color-from: '255,255,255'
color-to: '255,255,255'
Expand Down
4 changes: 2 additions & 2 deletions kaptcha-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.oopsguy.kaptcha</groupId>
<artifactId>kaptcha-spring-boot-parent</artifactId>
<version>1.0.0-beta</version>
<version>1.0.0-beta-2</version>
<relativePath>../kaptcha-spring-boot-parent</relativePath>
</parent>
<packaging>jar</packaging>
Expand All @@ -17,7 +17,7 @@
<dependencies>
<dependency>
<groupId>com.oopsguy.kaptcha</groupId>
<artifactId>kapcha-spring-boot-autoconfigure</artifactId>
<artifactId>kaptcha-spring-boot-autoconfigure</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion kaptcha/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>kaptcha-spring-boot-parent</artifactId>
<groupId>com.oopsguy.kaptcha</groupId>
<version>1.0.0-beta</version>
<version>1.0.0-beta-2</version>
<relativePath>../kaptcha-spring-boot-parent</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<groupId>com.oopsguy.kaptcha</groupId>
<artifactId>kaptcha-spring-boot</artifactId>
<packaging>pom</packaging>
<version>1.0.0-beta</version>
<version>1.0.0-beta-2</version>

<name>kaptcha-spring-boot</name>
<url>https://github.com/12software/kaptcha-spring-boot</url>
Expand Down

0 comments on commit fbdbac4

Please sign in to comment.