visual_captcha_cn 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +23 -0
- data/Rakefile +7 -0
- data/assets/audios/12times2.mp3 +0 -0
- data/assets/audios/12times2.ogg +0 -0
- data/assets/audios/2times10.mp3 +0 -0
- data/assets/audios/2times10.ogg +0 -0
- data/assets/audios/4plus1.mp3 +0 -0
- data/assets/audios/4plus1.ogg +0 -0
- data/assets/audios/4plus3.mp3 +0 -0
- data/assets/audios/4plus3.ogg +0 -0
- data/assets/audios/5plus1.mp3 +0 -0
- data/assets/audios/5plus1.ogg +0 -0
- data/assets/audios/5times2.mp3 +0 -0
- data/assets/audios/5times2.ogg +0 -0
- data/assets/audios/6plus6.mp3 +0 -0
- data/assets/audios/6plus6.ogg +0 -0
- data/assets/audios/99plus1.mp3 +0 -0
- data/assets/audios/99plus1.ogg +0 -0
- data/assets/audios/add3to1.mp3 +0 -0
- data/assets/audios/add3to1.ogg +0 -0
- data/assets/audios/addblueandyellow.mp3 +0 -0
- data/assets/audios/addblueandyellow.ogg +0 -0
- data/assets/audios/after2.mp3 +0 -0
- data/assets/audios/after2.ogg +0 -0
- data/assets/audios/capitaloffrance.mp3 +0 -0
- data/assets/audios/capitaloffrance.ogg +0 -0
- data/assets/audios/divide4by2.mp3 +0 -0
- data/assets/audios/divide4by2.ogg +0 -0
- data/assets/audios/firstletteralphabet.mp3 +0 -0
- data/assets/audios/firstletteralphabet.ogg +0 -0
- data/assets/audios/milkcolor.mp3 +0 -0
- data/assets/audios/milkcolor.ogg +0 -0
- data/assets/audios/skycolor.mp3 +0 -0
- data/assets/audios/skycolor.ogg +0 -0
- data/assets/audios/skynight.mp3 +0 -0
- data/assets/audios/skynight.ogg +0 -0
- data/assets/audios/sunastar.mp3 +0 -0
- data/assets/audios/sunastar.ogg +0 -0
- data/assets/audios/thirdmonth.mp3 +0 -0
- data/assets/audios/thirdmonth.ogg +0 -0
- data/assets/audios/yourobot.mp3 +0 -0
- data/assets/audios/yourobot.ogg +0 -0
- data/assets/audios.json +82 -0
- data/assets/images/airplane.png +0 -0
- data/assets/images/airplane@2x.png +0 -0
- data/assets/images/balloons.png +0 -0
- data/assets/images/balloons@2x.png +0 -0
- data/assets/images/camera.png +0 -0
- data/assets/images/camera@2x.png +0 -0
- data/assets/images/car.png +0 -0
- data/assets/images/car@2x.png +0 -0
- data/assets/images/cat.png +0 -0
- data/assets/images/cat@2x.png +0 -0
- data/assets/images/chair.png +0 -0
- data/assets/images/chair@2x.png +0 -0
- data/assets/images/clip.png +0 -0
- data/assets/images/clip@2x.png +0 -0
- data/assets/images/clock.png +0 -0
- data/assets/images/clock@2x.png +0 -0
- data/assets/images/cloud.png +0 -0
- data/assets/images/cloud@2x.png +0 -0
- data/assets/images/computer.png +0 -0
- data/assets/images/computer@2x.png +0 -0
- data/assets/images/envelope.png +0 -0
- data/assets/images/envelope@2x.png +0 -0
- data/assets/images/eye.png +0 -0
- data/assets/images/eye@2x.png +0 -0
- data/assets/images/flag.png +0 -0
- data/assets/images/flag@2x.png +0 -0
- data/assets/images/folder.png +0 -0
- data/assets/images/folder@2x.png +0 -0
- data/assets/images/foot.png +0 -0
- data/assets/images/foot@2x.png +0 -0
- data/assets/images/graph.png +0 -0
- data/assets/images/graph@2x.png +0 -0
- data/assets/images/house.png +0 -0
- data/assets/images/house@2x.png +0 -0
- data/assets/images/key.png +0 -0
- data/assets/images/key@2x.png +0 -0
- data/assets/images/leaf.png +0 -0
- data/assets/images/leaf@2x.png +0 -0
- data/assets/images/light-bulb.png +0 -0
- data/assets/images/light-bulb@2x.png +0 -0
- data/assets/images/lock.png +0 -0
- data/assets/images/lock@2x.png +0 -0
- data/assets/images/magnifying-glass.png +0 -0
- data/assets/images/magnifying-glass@2x.png +0 -0
- data/assets/images/man.png +0 -0
- data/assets/images/man@2x.png +0 -0
- data/assets/images/music-note.png +0 -0
- data/assets/images/music-note@2x.png +0 -0
- data/assets/images/pants.png +0 -0
- data/assets/images/pants@2x.png +0 -0
- data/assets/images/pencil.png +0 -0
- data/assets/images/pencil@2x.png +0 -0
- data/assets/images/printer.png +0 -0
- data/assets/images/printer@2x.png +0 -0
- data/assets/images/robot.png +0 -0
- data/assets/images/robot@2x.png +0 -0
- data/assets/images/scissors.png +0 -0
- data/assets/images/scissors@2x.png +0 -0
- data/assets/images/sunglasses.png +0 -0
- data/assets/images/sunglasses@2x.png +0 -0
- data/assets/images/t-shirt.png +0 -0
- data/assets/images/t-shirt@2x.png +0 -0
- data/assets/images/tag.png +0 -0
- data/assets/images/tag@2x.png +0 -0
- data/assets/images/tree.png +0 -0
- data/assets/images/tree@2x.png +0 -0
- data/assets/images/truck.png +0 -0
- data/assets/images/truck@2x.png +0 -0
- data/assets/images/umbrella.png +0 -0
- data/assets/images/umbrella@2x.png +0 -0
- data/assets/images/woman.png +0 -0
- data/assets/images/woman@2x.png +0 -0
- data/assets/images/world.png +0 -0
- data/assets/images/world@2x.png +0 -0
- data/assets/images.json +150 -0
- data/lib/visual_captcha_cn/captcha.rb +139 -0
- data/lib/visual_captcha_cn/session.rb +24 -0
- data/lib/visual_captcha_cn/version.rb +3 -0
- data/lib/visual_captcha_cn.rb +9 -0
- data/spec/lib/visual_captcha_cn/captcha_spec.rb +12 -0
- data/spec/lib/visual_captcha_cn_spec.rb +4 -0
- data/spec/spec_helper.rb +1 -0
- data/visual_captcha_cn.gemspec +26 -0
- metadata +231 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 4d074adf1861ce51e360724a571e4a550857c3f5
|
|
4
|
+
data.tar.gz: c1e5d9f6e2af3f5c1e7d1ef4ee0fc13417f21c46
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 829281a24aac9a29d3e60cda22ef7cc4d8301604debd9f104430cb693ef33ad6d4706835afc5bb0ae613589a74756325a8d7619e28d2944ddd1719fd550a1bff
|
|
7
|
+
data.tar.gz: 3dcc5e92741e484fe131278dcf7213fc01e9e3fde1df2a184dce07b8cd34fc9a14431ea3f7b06c697a969fdf01379ba3666b3a2e57dd5ae4602f9420eea788f1
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015 straightdave
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
# visualCaptcha-rubyGem for CN users
|
|
4
|
+
|
|
5
|
+
RubyGem package for visualCaptcha (CN version)'s backend service
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## Installation with Gem
|
|
9
|
+
|
|
10
|
+
You need Ruby 1.9.3+ installed.
|
|
11
|
+
```
|
|
12
|
+
gem install visual_captcha_cn
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
almost same with original version
|
|
19
|
+
|
|
20
|
+
## License
|
|
21
|
+
|
|
22
|
+
MIT. Check the [LICENSE](LICENSE) file.
|
|
23
|
+
Pride belongs to original authors (emotionLoop)
|
data/Rakefile
ADDED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/assets/audios.json
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"path": "5times2.mp3",
|
|
4
|
+
"value": "10"
|
|
5
|
+
},
|
|
6
|
+
{
|
|
7
|
+
"path": "2times10.mp3",
|
|
8
|
+
"value": "20"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"path": "5plus1.mp3",
|
|
12
|
+
"value": "6"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"path": "4plus1.mp3",
|
|
16
|
+
"value": "5"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"path": "4plus3.mp3",
|
|
20
|
+
"value": "7"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"path": "6plus6.mp3",
|
|
24
|
+
"value": "12"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"path": "12times2.mp3",
|
|
28
|
+
"value": "24"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"path": "99plus1.mp3",
|
|
32
|
+
"value": "100"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"path": "add3to1.mp3",
|
|
36
|
+
"value": "4"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"path": "addblueandyellow.mp3",
|
|
40
|
+
"value": "green"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"path": "after2.mp3",
|
|
44
|
+
"value": "3"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"path": "divide4by2.mp3",
|
|
48
|
+
"value": "2"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"path": "milkcolor.mp3",
|
|
52
|
+
"value": "white"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"path": "skycolor.mp3",
|
|
56
|
+
"value": "blue"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"path": "sunastar.mp3",
|
|
60
|
+
"value": "yes"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"path": "yourobot.mp3",
|
|
64
|
+
"value": "no"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"path": "capitaloffrance.mp3",
|
|
68
|
+
"value": "paris"
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"path": "skynight.mp3",
|
|
72
|
+
"value": "black"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"path": "thirdmonth.mp3",
|
|
76
|
+
"value": "march"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"path": "firstletteralphabet.mp3",
|
|
80
|
+
"value": "a"
|
|
81
|
+
}
|
|
82
|
+
]
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/assets/images.json
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"name": "飞机",
|
|
4
|
+
"path": "airplane.png"
|
|
5
|
+
},
|
|
6
|
+
{
|
|
7
|
+
"name": "气球",
|
|
8
|
+
"path": "balloons.png"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"name": "相机",
|
|
12
|
+
"path": "camera.png"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"name": "汽车",
|
|
16
|
+
"path": "car.png"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"name": "猫",
|
|
20
|
+
"path": "cat.png"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"name": "椅子",
|
|
24
|
+
"path": "chair.png"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"name": "回形针",
|
|
28
|
+
"path": "clip.png"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"name": "钟",
|
|
32
|
+
"path": "clock.png"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"name": "云",
|
|
36
|
+
"path": "cloud.png"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"name": "计算机",
|
|
40
|
+
"path": "computer.png"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"name": "信封",
|
|
44
|
+
"path": "envelope.png"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"name": "眼睛",
|
|
48
|
+
"path": "eye.png"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"name": "旗",
|
|
52
|
+
"path": "flag.png"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"name": "文件夹",
|
|
56
|
+
"path": "folder.png"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"name": "脚",
|
|
60
|
+
"path": "foot.png"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"name": "图表",
|
|
64
|
+
"path": "graph.png"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"name": "房屋",
|
|
68
|
+
"path": "house.png"
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"name": "钥匙",
|
|
72
|
+
"path": "key.png"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"name": "树叶",
|
|
76
|
+
"path": "leaf.png"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"name": "灯泡",
|
|
80
|
+
"path": "light-bulb.png"
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"name": "锁",
|
|
84
|
+
"path": "lock.png"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"name": "放大镜",
|
|
88
|
+
"path": "magnifying-glass.png"
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"name": "男人",
|
|
92
|
+
"path": "man.png"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"name": "音符",
|
|
96
|
+
"path": "music-note.png"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"name": "裤子",
|
|
100
|
+
"path": "pants.png"
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"name": "铅笔",
|
|
104
|
+
"path": "pencil.png"
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"name": "打印机",
|
|
108
|
+
"path": "printer.png"
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"name": "机器人",
|
|
112
|
+
"path": "robot.png"
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
"name": "剪刀",
|
|
116
|
+
"path": "scissors.png"
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"name": "太阳镜",
|
|
120
|
+
"path": "sunglasses.png"
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
"name": "标签",
|
|
124
|
+
"path": "tag.png"
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
"name": "树",
|
|
128
|
+
"path": "tree.png"
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
"name": "卡车",
|
|
132
|
+
"path": "truck.png"
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
"name": "T恤",
|
|
136
|
+
"path": "t-shirt.png"
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
"name": "伞",
|
|
140
|
+
"path": "umbrella.png"
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
"name": "女人",
|
|
144
|
+
"path": "woman.png"
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
"name": "世界",
|
|
148
|
+
"path": "world.png"
|
|
149
|
+
}
|
|
150
|
+
]
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
require 'securerandom'
|
|
3
|
+
|
|
4
|
+
class VisualCaptchaCN::Captcha
|
|
5
|
+
# @param session is the default session object
|
|
6
|
+
# @param assets_path is optional. Defaults to 'assets'. The path is relative to /
|
|
7
|
+
# @param default_images is optional. Defaults to the array inside ./images.json. The path is relative to ./images/
|
|
8
|
+
# @param default_audios is optional. Defaults to the array inside ./audios.json. The path is relative to ./audios/
|
|
9
|
+
def initialize(session, assets_path = nil, default_images = nil, default_audios = nil)
|
|
10
|
+
@session = session
|
|
11
|
+
|
|
12
|
+
@assets_path = assets_path
|
|
13
|
+
@assets_path ||= File.join VisualCaptchaCN.root, 'assets'
|
|
14
|
+
|
|
15
|
+
@image_options = default_images
|
|
16
|
+
@image_options ||= JSON.load File.read("#{@assets_path}/images.json")
|
|
17
|
+
|
|
18
|
+
@audio_options = default_audios
|
|
19
|
+
@audio_options ||= JSON.load File.read("#{@assets_path}/audios.json")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Generate a new valid option
|
|
23
|
+
# @param numberOfOptions is optional. Defaults to 5
|
|
24
|
+
def generate(number_of_options = 5)
|
|
25
|
+
@session.clear
|
|
26
|
+
|
|
27
|
+
number_of_options = number_of_options.to_i
|
|
28
|
+
number_of_options = 4 if number_of_options < 4
|
|
29
|
+
|
|
30
|
+
images = all_image_options.sample number_of_options
|
|
31
|
+
images.each do |image|
|
|
32
|
+
image['value'] = SecureRandom.hex 10
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
@session.set 'images', images
|
|
36
|
+
|
|
37
|
+
@session.set 'validImageOption', selected_images.sample
|
|
38
|
+
|
|
39
|
+
@session.set 'validAudioOption', all_audio_options.sample
|
|
40
|
+
|
|
41
|
+
@session.set 'frontendData', {
|
|
42
|
+
'values' => selected_images.map { |i| i['value'] },
|
|
43
|
+
'imageName' => valid_image_option['name'],
|
|
44
|
+
'imageFieldName' => SecureRandom.hex(10),
|
|
45
|
+
'audioFieldName' => SecureRandom.hex(10)
|
|
46
|
+
}
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Stream audio file
|
|
50
|
+
# @param headers object. used to store http headers for streaming
|
|
51
|
+
# @param fileType defaults to 'mp3', can also be 'ogg'
|
|
52
|
+
def stream_audio(headers, file_type = 'mp3')
|
|
53
|
+
audio_option = valid_audio_option
|
|
54
|
+
return nil if audio_option.nil?
|
|
55
|
+
|
|
56
|
+
audio_file_name = "#{audio_option['path']}"
|
|
57
|
+
audio_file_path = "#{@assets_path}/audios/#{audio_file_name}"
|
|
58
|
+
|
|
59
|
+
if file_type == 'ogg'
|
|
60
|
+
audio_file_path.gsub! /\.mp3/i, '.ogg'
|
|
61
|
+
|
|
62
|
+
content_type = 'application/ogg'
|
|
63
|
+
else
|
|
64
|
+
content_type = 'audio/mpeg'
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
read_file headers, audio_file_path, content_type
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Stream image file given an index in the session VisualCaptchaCN images array
|
|
71
|
+
# @param headers object. used to store http headers for streaming
|
|
72
|
+
# @param index of the image in the session images array to send
|
|
73
|
+
# @paran isRetina boolean. Defaults to false
|
|
74
|
+
def stream_image(headers, index, is_retina)
|
|
75
|
+
image_option = selected_image_at_index index.to_i
|
|
76
|
+
return nil if image_option.nil?
|
|
77
|
+
|
|
78
|
+
image_file_name = "#{image_option['path']}"
|
|
79
|
+
image_file_name.gsub! /\.png/i, '@2x.png' if (is_retina.to_i >= 1)
|
|
80
|
+
image_file_path = "#{@assets_path}/images/#{image_file_name}"
|
|
81
|
+
|
|
82
|
+
read_file headers, image_file_path, 'image/png'
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def selected_images
|
|
86
|
+
@session.get 'images'
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def selected_image_at_index(index)
|
|
90
|
+
images = selected_images
|
|
91
|
+
images[index] unless images.nil?
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def frontend_data
|
|
95
|
+
@session.get 'frontendData'
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def valid_image_option
|
|
99
|
+
@session.get 'validImageOption'
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def valid_audio_option
|
|
103
|
+
@session.get 'validAudioOption'
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def validate_image(sent_option)
|
|
107
|
+
sent_option == valid_image_option['value']
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def validate_audio(sent_option)
|
|
111
|
+
sent_option == valid_audio_option['value']
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def all_image_options
|
|
115
|
+
@image_options
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def all_audio_options
|
|
119
|
+
@audio_options
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
private
|
|
123
|
+
|
|
124
|
+
def read_file(headers, file_path, content_type)
|
|
125
|
+
return nil unless File.exists? file_path
|
|
126
|
+
|
|
127
|
+
headers['Content-Type'] = content_type
|
|
128
|
+
headers['Cache-Control'] = 'no-cache, no-store, must-revalidate'
|
|
129
|
+
headers['Pragma'] = 'no-cache'
|
|
130
|
+
headers['Expires'] = '0'
|
|
131
|
+
|
|
132
|
+
file_contents = File.read file_path
|
|
133
|
+
|
|
134
|
+
# Add some noise randomly, so images can't be saved and matched easily by filesize or checksum
|
|
135
|
+
file_contents += SecureRandom.hex(SecureRandom.random_number(1500))
|
|
136
|
+
|
|
137
|
+
return file_contents
|
|
138
|
+
end
|
|
139
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
class VisualCaptchaCN::Session
|
|
2
|
+
attr_accessor :session, :namespace
|
|
3
|
+
|
|
4
|
+
def initialize(session, namespace = 'VisualCaptchaCN')
|
|
5
|
+
self.session = session
|
|
6
|
+
self.namespace = namespace
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def clear
|
|
10
|
+
session[namespace] = {}
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def get(key)
|
|
14
|
+
clear if session[namespace].nil?
|
|
15
|
+
|
|
16
|
+
session[namespace][key]
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def set(key, value)
|
|
20
|
+
clear if session[namespace].nil?
|
|
21
|
+
|
|
22
|
+
session[namespace][key] = value
|
|
23
|
+
end
|
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'visual_captcha_cn'
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'visual_captcha_cn/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "visual_captcha_cn"
|
|
8
|
+
spec.version = VisualCaptchaCN::VERSION
|
|
9
|
+
spec.authors = ["straightdave"]
|
|
10
|
+
spec.email = "eyaswoo@163.com"
|
|
11
|
+
spec.description = "Repackaged visualCaptcha's backend service for CN users"
|
|
12
|
+
spec.summary = "visualCaptchaCn RubyGem Package"
|
|
13
|
+
spec.homepage = "http://straightdave.github.io"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files`.split($/)
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_dependency "json"
|
|
22
|
+
|
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
|
24
|
+
spec.add_development_dependency "rake"
|
|
25
|
+
spec.add_development_dependency "rspec"
|
|
26
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: visual_captcha_cn
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- straightdave
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-12-23 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: json
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: bundler
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.3'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.3'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rake
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rspec
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
description: Repackaged visualCaptcha's backend service for CN users
|
|
70
|
+
email: eyaswoo@163.com
|
|
71
|
+
executables: []
|
|
72
|
+
extensions: []
|
|
73
|
+
extra_rdoc_files: []
|
|
74
|
+
files:
|
|
75
|
+
- ".gitignore"
|
|
76
|
+
- Gemfile
|
|
77
|
+
- LICENSE
|
|
78
|
+
- README.md
|
|
79
|
+
- Rakefile
|
|
80
|
+
- assets/audios.json
|
|
81
|
+
- assets/audios/12times2.mp3
|
|
82
|
+
- assets/audios/12times2.ogg
|
|
83
|
+
- assets/audios/2times10.mp3
|
|
84
|
+
- assets/audios/2times10.ogg
|
|
85
|
+
- assets/audios/4plus1.mp3
|
|
86
|
+
- assets/audios/4plus1.ogg
|
|
87
|
+
- assets/audios/4plus3.mp3
|
|
88
|
+
- assets/audios/4plus3.ogg
|
|
89
|
+
- assets/audios/5plus1.mp3
|
|
90
|
+
- assets/audios/5plus1.ogg
|
|
91
|
+
- assets/audios/5times2.mp3
|
|
92
|
+
- assets/audios/5times2.ogg
|
|
93
|
+
- assets/audios/6plus6.mp3
|
|
94
|
+
- assets/audios/6plus6.ogg
|
|
95
|
+
- assets/audios/99plus1.mp3
|
|
96
|
+
- assets/audios/99plus1.ogg
|
|
97
|
+
- assets/audios/add3to1.mp3
|
|
98
|
+
- assets/audios/add3to1.ogg
|
|
99
|
+
- assets/audios/addblueandyellow.mp3
|
|
100
|
+
- assets/audios/addblueandyellow.ogg
|
|
101
|
+
- assets/audios/after2.mp3
|
|
102
|
+
- assets/audios/after2.ogg
|
|
103
|
+
- assets/audios/capitaloffrance.mp3
|
|
104
|
+
- assets/audios/capitaloffrance.ogg
|
|
105
|
+
- assets/audios/divide4by2.mp3
|
|
106
|
+
- assets/audios/divide4by2.ogg
|
|
107
|
+
- assets/audios/firstletteralphabet.mp3
|
|
108
|
+
- assets/audios/firstletteralphabet.ogg
|
|
109
|
+
- assets/audios/milkcolor.mp3
|
|
110
|
+
- assets/audios/milkcolor.ogg
|
|
111
|
+
- assets/audios/skycolor.mp3
|
|
112
|
+
- assets/audios/skycolor.ogg
|
|
113
|
+
- assets/audios/skynight.mp3
|
|
114
|
+
- assets/audios/skynight.ogg
|
|
115
|
+
- assets/audios/sunastar.mp3
|
|
116
|
+
- assets/audios/sunastar.ogg
|
|
117
|
+
- assets/audios/thirdmonth.mp3
|
|
118
|
+
- assets/audios/thirdmonth.ogg
|
|
119
|
+
- assets/audios/yourobot.mp3
|
|
120
|
+
- assets/audios/yourobot.ogg
|
|
121
|
+
- assets/images.json
|
|
122
|
+
- assets/images/airplane.png
|
|
123
|
+
- assets/images/airplane@2x.png
|
|
124
|
+
- assets/images/balloons.png
|
|
125
|
+
- assets/images/balloons@2x.png
|
|
126
|
+
- assets/images/camera.png
|
|
127
|
+
- assets/images/camera@2x.png
|
|
128
|
+
- assets/images/car.png
|
|
129
|
+
- assets/images/car@2x.png
|
|
130
|
+
- assets/images/cat.png
|
|
131
|
+
- assets/images/cat@2x.png
|
|
132
|
+
- assets/images/chair.png
|
|
133
|
+
- assets/images/chair@2x.png
|
|
134
|
+
- assets/images/clip.png
|
|
135
|
+
- assets/images/clip@2x.png
|
|
136
|
+
- assets/images/clock.png
|
|
137
|
+
- assets/images/clock@2x.png
|
|
138
|
+
- assets/images/cloud.png
|
|
139
|
+
- assets/images/cloud@2x.png
|
|
140
|
+
- assets/images/computer.png
|
|
141
|
+
- assets/images/computer@2x.png
|
|
142
|
+
- assets/images/envelope.png
|
|
143
|
+
- assets/images/envelope@2x.png
|
|
144
|
+
- assets/images/eye.png
|
|
145
|
+
- assets/images/eye@2x.png
|
|
146
|
+
- assets/images/flag.png
|
|
147
|
+
- assets/images/flag@2x.png
|
|
148
|
+
- assets/images/folder.png
|
|
149
|
+
- assets/images/folder@2x.png
|
|
150
|
+
- assets/images/foot.png
|
|
151
|
+
- assets/images/foot@2x.png
|
|
152
|
+
- assets/images/graph.png
|
|
153
|
+
- assets/images/graph@2x.png
|
|
154
|
+
- assets/images/house.png
|
|
155
|
+
- assets/images/house@2x.png
|
|
156
|
+
- assets/images/key.png
|
|
157
|
+
- assets/images/key@2x.png
|
|
158
|
+
- assets/images/leaf.png
|
|
159
|
+
- assets/images/leaf@2x.png
|
|
160
|
+
- assets/images/light-bulb.png
|
|
161
|
+
- assets/images/light-bulb@2x.png
|
|
162
|
+
- assets/images/lock.png
|
|
163
|
+
- assets/images/lock@2x.png
|
|
164
|
+
- assets/images/magnifying-glass.png
|
|
165
|
+
- assets/images/magnifying-glass@2x.png
|
|
166
|
+
- assets/images/man.png
|
|
167
|
+
- assets/images/man@2x.png
|
|
168
|
+
- assets/images/music-note.png
|
|
169
|
+
- assets/images/music-note@2x.png
|
|
170
|
+
- assets/images/pants.png
|
|
171
|
+
- assets/images/pants@2x.png
|
|
172
|
+
- assets/images/pencil.png
|
|
173
|
+
- assets/images/pencil@2x.png
|
|
174
|
+
- assets/images/printer.png
|
|
175
|
+
- assets/images/printer@2x.png
|
|
176
|
+
- assets/images/robot.png
|
|
177
|
+
- assets/images/robot@2x.png
|
|
178
|
+
- assets/images/scissors.png
|
|
179
|
+
- assets/images/scissors@2x.png
|
|
180
|
+
- assets/images/sunglasses.png
|
|
181
|
+
- assets/images/sunglasses@2x.png
|
|
182
|
+
- assets/images/t-shirt.png
|
|
183
|
+
- assets/images/t-shirt@2x.png
|
|
184
|
+
- assets/images/tag.png
|
|
185
|
+
- assets/images/tag@2x.png
|
|
186
|
+
- assets/images/tree.png
|
|
187
|
+
- assets/images/tree@2x.png
|
|
188
|
+
- assets/images/truck.png
|
|
189
|
+
- assets/images/truck@2x.png
|
|
190
|
+
- assets/images/umbrella.png
|
|
191
|
+
- assets/images/umbrella@2x.png
|
|
192
|
+
- assets/images/woman.png
|
|
193
|
+
- assets/images/woman@2x.png
|
|
194
|
+
- assets/images/world.png
|
|
195
|
+
- assets/images/world@2x.png
|
|
196
|
+
- lib/visual_captcha_cn.rb
|
|
197
|
+
- lib/visual_captcha_cn/captcha.rb
|
|
198
|
+
- lib/visual_captcha_cn/session.rb
|
|
199
|
+
- lib/visual_captcha_cn/version.rb
|
|
200
|
+
- spec/lib/visual_captcha_cn/captcha_spec.rb
|
|
201
|
+
- spec/lib/visual_captcha_cn_spec.rb
|
|
202
|
+
- spec/spec_helper.rb
|
|
203
|
+
- visual_captcha_cn.gemspec
|
|
204
|
+
homepage: http://straightdave.github.io
|
|
205
|
+
licenses:
|
|
206
|
+
- MIT
|
|
207
|
+
metadata: {}
|
|
208
|
+
post_install_message:
|
|
209
|
+
rdoc_options: []
|
|
210
|
+
require_paths:
|
|
211
|
+
- lib
|
|
212
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
213
|
+
requirements:
|
|
214
|
+
- - ">="
|
|
215
|
+
- !ruby/object:Gem::Version
|
|
216
|
+
version: '0'
|
|
217
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
218
|
+
requirements:
|
|
219
|
+
- - ">="
|
|
220
|
+
- !ruby/object:Gem::Version
|
|
221
|
+
version: '0'
|
|
222
|
+
requirements: []
|
|
223
|
+
rubyforge_project:
|
|
224
|
+
rubygems_version: 2.5.1
|
|
225
|
+
signing_key:
|
|
226
|
+
specification_version: 4
|
|
227
|
+
summary: visualCaptchaCn RubyGem Package
|
|
228
|
+
test_files:
|
|
229
|
+
- spec/lib/visual_captcha_cn/captcha_spec.rb
|
|
230
|
+
- spec/lib/visual_captcha_cn_spec.rb
|
|
231
|
+
- spec/spec_helper.rb
|