Skip to content

Commit eb46fd3

Browse files
committed
Add README_zh-CN
1 parent fbdbac4 commit eb46fd3

File tree

7 files changed

+172
-24
lines changed

7 files changed

+172
-24
lines changed

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
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.
44

5+
- [中文文档](README_zh-CN.md)
6+
57
## Usage
68

7-
Declare `kaptcha-spring-boot-starter` dependency in your `pom.xml` file.
9+
Add `kaptcha-spring-boot-starter` dependency to your `pom.xml` file.
810

911
```xml
1012
<dependency>
@@ -16,18 +18,17 @@ Declare `kaptcha-spring-boot-starter` dependency in your `pom.xml` file.
1618

1719
## Properties
1820

19-
You can use some properties to custom your captcha without Java code as following:
21+
You can use properties to custom captcha without Java code:
2022

2123
```yaml
22-
# for kaptcha
2324
kaptcha:
2425
border:
2526
enabled: true
2627
color: '200,200,200'
2728
thickness: 1
2829
noise:
2930
color: '239,166,131'
30-
# you can specify your own implementation class
31+
# you can specify your own implementation
3132
impl:
3233
obscurificator:
3334
impl:
@@ -52,9 +53,8 @@ kaptcha:
5253
image:
5354
width: 200
5455
height: 60
55-
# You can configure multiple separate captcha
56-
# and configure properties for each, the configuration will
57-
# override the parent configuration
56+
# You can configure multiple captcha
57+
# and configure properties for them individually
5858
items:
5959
home:
6060
path: /home/captcha
@@ -73,7 +73,7 @@ kaptcha:
7373

7474
### YAML
7575

76-
The following yaml configure some common kaptcha properties
76+
The following use yaml to configure common kaptcha properties
7777
and define two kaptcha servlets(`home` and `admin`),
7878
you can configure them in your `application.yml`:
7979

@@ -119,15 +119,15 @@ class SystemController {
119119
private Producer captchaProducer;
120120
121121
@GetMapping("/captcha")
122-
public void getKaptchaImage(HttpServletResponse response) throws Exception {
122+
public void getKaptchaImage(HttpServletRequest request, HttpServletResponse response) throws Exception {
123123
response.setDateHeader("Expires", 0);
124124
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
125125
response.addHeader("Cache-Control", "post-check=0, pre-check=0");
126126
response.setHeader("Pragma", "no-cache");
127127
response.setContentType("image/jpeg");
128128
String capText = captchaProducer.createText();
129129
// Save the captcha code to the session
130-
ShiroKit.setSessionAttr(AdminConst.SESSION_KEY_CAPTCHA_LOGIN, capText);
130+
request.getSession().setAttribute("captchaCode", capText);
131131
BufferedImage bi = captchaProducer.createImage(capText);
132132
ServletOutputStream out = response.getOutputStream();
133133
ImageIO.write(bi, "jpg", out);
@@ -140,11 +140,11 @@ class SystemController {
140140
}
141141
```
142142

143-
For more examples, please see [kaptcha-spring-boot-starter-example](https://github.com/12software/kaptcha-spring-boot/tree/master/kaptcha-spring-boot-starter-example)
143+
For more examples, please see [kaptcha-spring-boot-starter-example](https://github.com/oopsguy/kaptcha-spring-boot/tree/master/kaptcha-spring-boot-starter-example)
144144

145145
## Notice
146146

147-
If you custom your own `Producer` bean, it will instead of default. But the separate configuration is still apply.
147+
If you custom your own `Producer` bean, it will replace the default.
148148

149149
## License
150150

README_zh-CN.md

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# Kaptcha Spring Boot Starter
2+
3+
Kaptcha Spring Boot Starter 可以让你更方便地在 [Spring Boot](https://github.com/spring-projects/spring-boot) 应用中使用 [Google Kaptcha](http://code.google.com/p/kaptcha/).
4+
5+
## 用法
6+
7+
在项目的 `pom.xml` 文件中加入 `kaptcha-spring-boot-starter` 依赖。
8+
9+
```xml
10+
<dependency>
11+
<groupId>com.oopsguy.kaptcha</groupId>
12+
<artifactId>kaptcha-spring-boot-starter</artifactId>
13+
<version>1.0.0-beta-2</version>
14+
</dependency>
15+
```
16+
17+
## Properties
18+
19+
你可以仅使用 properties 来自定义验证码,无需任何 Java 代码:
20+
21+
```yaml
22+
kaptcha:
23+
border:
24+
enabled: true
25+
color: '200,200,200'
26+
thickness: 1
27+
noise:
28+
color: '239,166,131'
29+
# 可以指定自定义的实现类
30+
impl:
31+
obscurificator:
32+
impl:
33+
producer:
34+
impl:
35+
background:
36+
impl:
37+
color-from: '255,0,0'
38+
color-to: '255,0,0'
39+
text-producer:
40+
impl:
41+
character:
42+
string: '01234567890ABCDEF'
43+
length: 4
44+
space: 10
45+
font:
46+
names:
47+
color: '255,255,255'
48+
size: 46
49+
word:
50+
impl:
51+
image:
52+
width: 200
53+
height: 60
54+
# 可以配置多个验证码,并为每个验证码单独配置
55+
# 独立的配置将覆盖上面的公共配置
56+
items:
57+
home:
58+
path: /home/captcha
59+
session:
60+
key: homeCaptcha
61+
background:
62+
color-from: '255,255,255'
63+
color-to: '255,255,255'
64+
text-producer:
65+
font:
66+
color: '68,155,44'
67+
# 更多...
68+
```
69+
70+
## 示例
71+
72+
### YAML 方式
73+
74+
下例使用 yaml 来配置 Kaptcha 的通用属性并定义了两个 Kaptcha servlet(`home``admin`)。你可以在 `application.yml` 文件中配置:
75+
76+
```yaml
77+
server:
78+
port: 8080
79+
80+
kaptcha:
81+
border:
82+
enbaled: true
83+
image:
84+
height: 60
85+
width: 160
86+
items:
87+
# home captcha
88+
home:
89+
path: /home/capthca
90+
text-producer:
91+
font:
92+
size: 16
93+
image:
94+
height: 40
95+
# admin captcha
96+
admin:
97+
path: /admin/capthca
98+
text-producer:
99+
character:
100+
length: 4
101+
```
102+
103+
配置完成后启动项目,可浏览 [http://localhost:8080/home/capthca](http://localhost:8080/home/capthca) 和 [http://localhost:8080/admin/capthca](http://localhost:8080/admin/capthca) 查看效果。
104+
105+
### Java 代码方式
106+
107+
你可以直接注入一个 `Producer` bean 来生成验证码。
108+
109+
```java
110+
@Controller
111+
@RequestMapping("/sys")
112+
class SystemController {
113+
114+
@Resource
115+
private Producer captchaProducer;
116+
117+
@GetMapping("/captcha")
118+
public void getKaptchaImage(HttpServletResponse response) throws Exception {
119+
response.setDateHeader("Expires", 0);
120+
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
121+
response.addHeader("Cache-Control", "post-check=0, pre-check=0");
122+
response.setHeader("Pragma", "no-cache");
123+
response.setContentType("image/jpeg");
124+
String capText = captchaProducer.createText();
125+
// 将验证码保存到 session 中
126+
ShiroKit.setSessionAttr(AdminConst.SESSION_KEY_CAPTCHA_LOGIN, capText);
127+
BufferedImage bi = captchaProducer.createImage(capText);
128+
ServletOutputStream out = response.getOutputStream();
129+
ImageIO.write(bi, "jpg", out);
130+
try {
131+
out.flush();
132+
} finally {
133+
out.close();
134+
}
135+
}
136+
}
137+
```
138+
139+
可查看 [kaptcha-spring-boot-starter-example](https://github.com/oopsguy/kaptcha-spring-boot/tree/master/kaptcha-spring-boot-starter-example) 获取更多示例。
140+
141+
## 注意
142+
143+
如果你定义了自己的 `Producer` bean,它将会代替默认的 `Producer`。但 `items` 下的独立配置不会被覆盖。
144+
145+
## 许可
146+
147+
MIT License
148+

kaptcha-spring-boot-autoconfigure/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<packaging>jar</packaging>
1212
<artifactId>kaptcha-spring-boot-autoconfigure</artifactId>
1313
<name>kaptcha-spring-boot-autoconfigure</name>
14-
<url>https://github.com/12software/kaptcha-spring-boot</url>
14+
<url>https://github.com/oospguy/kaptcha-spring-boot</url>
1515
<description>Kaptcha Spring Boot AutoConfigurer</description>
1616

1717
<dependencies>

kaptcha-spring-boot-parent/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<packaging>pom</packaging>
1313
<artifactId>kaptcha-spring-boot-parent</artifactId>
1414
<name>kaptcha-spring-boot-parent</name>
15-
<url>https://github.com/12software/kaptcha-spring-boot</url>
15+
<url>https://github.com/oospguy/kaptcha-spring-boot</url>
1616
<description>Kaptcha Spring Boot Starter Parent</description>
1717

1818
<modules>
@@ -41,7 +41,7 @@
4141
<version>4.12</version>
4242
<scope>test</scope>
4343
</dependency>
44-
<!--For java 9 or up-->
44+
<!-- For JDK 9+ -->
4545
<dependency>
4646
<groupId>javax.annotation</groupId>
4747
<artifactId>javax.annotation-api</artifactId>

kaptcha-spring-boot-starter-example/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Kaptcha Spring Boot Starter Example
22

3-
This project is a demo based on Spring Boot, you can run it as a jar
3+
This is a demo project based on Spring Boot, you can run it as a jar
44
or by following maven command:
55

66
```
@@ -11,7 +11,6 @@ The project will run on port `8081`.
1111

1212
You can view the results by browsing the links below:
1313

14-
1514
- [`http://localhost:8081/index.html`](http://localhost:8081/index.html)
1615
- [`http://localhost:8081/home/captcha`](http://localhost:8081/home/captcha)
1716
- [`http://localhost:8081/captcha`](http://localhost:8081/captcha)

kaptcha-spring-boot-starter/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<packaging>jar</packaging>
1212
<artifactId>kaptcha-spring-boot-starter</artifactId>
1313
<name>kaptcha-spring-boot-starter</name>
14-
<url>https://github.com/12software/kaptcha-spring-boot</url>
14+
<url>https://github.com/oospguy/kaptcha-spring-boot</url>
1515
<description>Kaptcha Spring Boot Starter</description>
1616

1717
<dependencies>

pom.xml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
<version>1.0.0-beta-2</version>
1616

1717
<name>kaptcha-spring-boot</name>
18-
<url>https://github.com/12software/kaptcha-spring-boot</url>
18+
<url>https://github.com/oospguy/kaptcha-spring-boot</url>
1919
<description>Kaptcha Spring Boot Starter</description>
2020

2121
<modules>
2222
<module>kaptcha-spring-boot-parent</module>
2323
</modules>
2424

2525
<properties>
26+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
2627
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2728
<maven.compiler.source>1.8</maven.compiler.source>
2829
<maven.compiler.target>1.8</maven.compiler.target>
@@ -39,14 +40,14 @@
3940
<name>oopsguy</name>
4041
<email>[email protected]</email>
4142
<url>https://github.com/oopsguy</url>
42-
<organization>12software</organization>
43-
<organizationUrl>https://github.com/12software</organizationUrl>
43+
<organization>oospguy</organization>
44+
<organizationUrl>https://github.com/oospguy</organizationUrl>
4445
</developer>
4546
</developers>
4647
<scm>
47-
<connection>scm:git:https://github.com/12software/kaptcha-spring-boot.git</connection>
48-
<developerConnection>scm:git:https://github.com/12software/kaptcha-spring-boot.git</developerConnection>
49-
<url>https://github.com/12software/kaptcha-spring-boot</url>
48+
<connection>scm:git:https://github.com/oospguy/kaptcha-spring-boot.git</connection>
49+
<developerConnection>scm:git:https://github.com/oospguy/kaptcha-spring-boot.git</developerConnection>
50+
<url>https://github.com/oospguy/kaptcha-spring-boot</url>
5051
</scm>
5152

5253
<build>

0 commit comments

Comments
 (0)