rucaptcha 2.0.0.beta4 → 2.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: abeea0fd2c1d23218c330e3ff7452b3b9906d6b4
4
- data.tar.gz: f9b5ff05abf6034537d7076ff3c16b968372455c
3
+ metadata.gz: 3d77f76c426739b1dff568c242d92e8aab993894
4
+ data.tar.gz: ce46de282f893b397a26c82bd7071090a2e9a405
5
5
  SHA512:
6
- metadata.gz: d9e5ed41b6c855ced136802a1117e9b9a22ad1838d2e8eb1e5ba049bba2580a5b1497bd0bae9202028fe306b629807806b065d44997913764114a3f41a3e8710
7
- data.tar.gz: a0a6e2411fb7bae88685ab07f24b74d177d8838170fb4d106c28f0718c3fd759f8b64d85745a2957142a7cf55db4e1476fdc6fa47f1833bbb660e13c270203e5
6
+ metadata.gz: a0f3f2fb8b5055f82019568aad37d8d927fb5dfc8c68325ec437f9c5d2746b826cb0e42b0868e5088f4e93bcab2e48c6a58ff6ce7aeae5364417436a42019690
7
+ data.tar.gz: fcef86bd39c1facaa06fc399947298477ba8924ede6091e6351379293b8d22db6be792706a4c79e07f4358febcea078bd8eacacb28928fa87127926be1f685ff
data/CHANGELOG.md CHANGED
@@ -6,8 +6,9 @@
6
6
  WARNING!: This version have so many break changes!
7
7
 
8
8
  - Use C ext instead of ImageMagick, now it's no dependencies!
9
- - New captcha style, because C code is complex, just generate black chars.
10
- - Remove `len`, `style`, `font_size`, `cache_limit` config key, no support now.
9
+ - New captcha style.
10
+ - Remove `len`, `font_size`, `cache_limit` config key, no support now.
11
+ - Output `GIF` format.
11
12
 
12
13
  1.2.0
13
14
  -----
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![Build Status](https://travis-ci.org/huacnlee/rucaptcha.svg)](https://travis-ci.org/huacnlee/rucaptcha)
5
5
  [![Code Climate](https://codeclimate.com/github/huacnlee/rucaptcha/badges/gpa.svg)](https://codeclimate.com/github/huacnlee/rucaptcha)
6
6
 
7
- This is a Captcha gem for Rails Applications. It drawing captcha image with C extension.
7
+ This is a Captcha gem for Rails Applications. It drawing captcha image with C code.
8
8
 
9
9
  ## Example
10
10
 
@@ -31,6 +31,8 @@ Create `config/initializers/rucaptcha.rb`
31
31
 
32
32
  ```rb
33
33
  RuCaptcha.configure do
34
+ # Color style, default: :colorful, allows: [:colorful, :black_white]
35
+ # self.style = :colorful
34
36
  # Custom captcha code expire time if you need, default: 2 minutes
35
37
  # self.expires_in = 120
36
38
  # [Requirement]
@@ -3,21 +3,21 @@
3
3
  static char *colors[] = {
4
4
  // Black 500 #000000
5
5
  "GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
6
- "\x00\x00\x00"
7
- "\x00\x00\x00"
8
- "\x00\x00\x00"
9
- "\x00\x00\x00"
10
- "\x00\x00\x00"
11
- "\x00\x00\x00"
12
- "\x00\x00\x00"
13
- "\x00\x00\x00"
14
- "\x00\x00\x00"
15
- "\x00\x00\x00"
16
- "\x00\x00\x00"
17
- "\x00\x00\x00"
18
- "\x00\x00\x00"
19
- "\x00\x00\x00"
20
- "\x00\x00\x00"
6
+ "\x11\x11\x11"
7
+ "\x11\x11\x11"
8
+ "\x11\x11\x11"
9
+ "\x11\x11\x11"
10
+ "\x11\x11\x11"
11
+ "\x11\x11\x11"
12
+ "\x11\x11\x11"
13
+ "\x11\x11\x11"
14
+ "\x11\x11\x11"
15
+ "\x11\x11\x11"
16
+ "\x11\x11\x11"
17
+ "\x11\x11\x11"
18
+ "\x11\x11\x11"
19
+ "\x11\x11\x11"
20
+ "\x11\x11\x11"
21
21
  "\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
22
22
 
23
23
  // Red 500 #F44336
@@ -1,4 +1,2 @@
1
1
  require 'mkmf'
2
-
3
- # dir_config(extension_name)
4
2
  create_makefile('rucaptcha/rucaptcha')
@@ -1,7 +1,7 @@
1
1
  // http://github.com/ITikhonov/captcha
2
2
  const int gifsize;
3
3
  void captcha(unsigned char im[70*200], unsigned char l[6]);
4
- void makegif(unsigned char im[70*200], unsigned char gif[gifsize]);
4
+ void makegif(unsigned char im[70*200], unsigned char gif[gifsize], int style);
5
5
 
6
6
  #include <unistd.h>
7
7
  #include <stdint.h>
@@ -16,13 +16,16 @@ void makegif(unsigned char im[70*200], unsigned char gif[gifsize]);
16
16
  static int8_t *lt[];
17
17
  const int gifsize=17646;
18
18
 
19
- void makegif(unsigned char im[70*200], unsigned char gif[gifsize]) {
19
+ void makegif(unsigned char im[70*200], unsigned char gif[gifsize], int style) {
20
20
  // tag ; widthxheight ; GCT:0:0:7 ; bgcolor + aspect // GCT
21
21
  // Image Separator // left x top // widthxheight // Flags
22
22
  // LZW code size
23
23
  srand(time(NULL));
24
24
  int color_len = (int) sizeof(colors) / sizeof(colors[0]);
25
25
  int color_idx = rand() % color_len;
26
+ if (style == 0) {
27
+ color_idx = 0;
28
+ }
26
29
  memcpy(gif,colors[color_idx],13+48+10+1);
27
30
 
28
31
  int x,y;
@@ -185,20 +188,21 @@ VALUE RuCaptcha = Qnil;
185
188
 
186
189
  void Init_rucaptcha();
187
190
 
188
- VALUE create(VALUE self);
191
+ VALUE create(VALUE self, VALUE style);
189
192
 
190
193
  void Init_rucaptcha() {
191
194
  RuCaptcha = rb_define_module("RuCaptcha");
192
- rb_define_singleton_method(RuCaptcha, "create", create, 0);
195
+ rb_define_singleton_method(RuCaptcha, "create", create, 1);
193
196
  }
194
197
 
195
- VALUE create(VALUE self) {
198
+ VALUE create(VALUE self, VALUE style) {
196
199
  char l[6];
197
200
  unsigned char im[80*200];
198
201
  unsigned char gif[gifsize];
202
+ int i_style = FIX2INT(style);
199
203
 
200
- captcha(im,l);
201
- makegif(im,gif);
204
+ captcha(im, l);
205
+ makegif(im, gif, i_style);
202
206
 
203
207
  VALUE result = rb_ary_new2(2);
204
208
  rb_ary_push(result, rb_str_new2(l));
data/lib/rucaptcha.rb CHANGED
@@ -14,6 +14,7 @@ module RuCaptcha
14
14
  def config
15
15
  return @config if defined?(@config)
16
16
  @config = Configuration.new
17
+ @config.style = :colorful
17
18
  @config.expires_in = 2.minutes
18
19
  if Rails.application
19
20
  @config.cache_store = Rails.application.config.cache_store
@@ -26,6 +27,11 @@ module RuCaptcha
26
27
  def configure(&block)
27
28
  config.instance_exec(&block)
28
29
  end
30
+
31
+ def generate()
32
+ style = config.style == :colorful ? 1 : 0
33
+ self.create(style)
34
+ end
29
35
  end
30
36
  end
31
37
 
@@ -5,5 +5,7 @@ module RuCaptcha
5
5
  attr_accessor :cache_store
6
6
  # rucaptcha expire time, default 2 minutes
7
7
  attr_accessor :expires_in
8
+ # Color style, default: :colorful, allows: [:colorful, :black_white]
9
+ attr_accessor :style
8
10
  end
9
11
  end
@@ -14,7 +14,7 @@ module RuCaptcha
14
14
 
15
15
  # Generate a new Captcha
16
16
  def generate_rucaptcha
17
- res = RuCaptcha.create()
17
+ res = RuCaptcha.generate()
18
18
  session_val = {
19
19
  code: res[0],
20
20
  time: Time.now.to_i
@@ -1,3 +1,3 @@
1
1
  module RuCaptcha
2
- VERSION = '2.0.0.beta4'
2
+ VERSION = '2.0.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rucaptcha
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta4
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-20 00:00:00.000000000 Z
11
+ date: 2017-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -79,9 +79,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
79
  version: 2.0.0
80
80
  required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  requirements:
82
- - - ">"
82
+ - - ">="
83
83
  - !ruby/object:Gem::Version
84
- version: 1.3.1
84
+ version: '0'
85
85
  requirements: []
86
86
  rubyforge_project:
87
87
  rubygems_version: 2.5.2