diff --git a/CHANGELOG.md b/CHANGELOG.md index 10ec3cf..eb7c9bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +2.2.0 +----- + +- Add option `config.length` for support change number chars. +- Add option `config.strikethrough` for enable or disable strikethrough. + 2.1.3 ----- diff --git a/Gemfile.lock b/Gemfile.lock index 3cfd9e2..3ca0fad 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - rucaptcha (2.1.4) + rucaptcha (2.2.0) railties (>= 3.2) GEM @@ -142,4 +142,4 @@ DEPENDENCIES rucaptcha! BUNDLED WITH - 1.14.5 + 1.15.4 diff --git a/README.md b/README.md index 5317ff5..897b43a 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ This is a Captcha gem for Rails Applications which generates captcha image by C - High performance. ## Usage + Put rucaptcha in your `Gemfile`: ``` @@ -41,10 +42,10 @@ RuCaptcha.configure do  # 默认:会从 Rails 配置的 cache_store 里面读取相同的配置信息,并尝试用可以运行的方式,用于存储验证码字符  # 但如果是 [:null_store, :memory_store, :file_store] 之类的,你可以通过下面的配置项单独给 RuCaptcha 配置 cache_store  self.cache_store = :mem_cache_store - # 验证码长度 length, 默认是 5, allows: [3,4,5,6,7] + # Chars length, default: 5, allows: [3 - 7] # self.length = 5 - # 验证码横线 line, 默认显示横线, default: true, allows: [true, false], 设置为false时, 横线不是显示, 验证码识别度高. - # self.line = true + # enable/disable Strikethrough. + # self.strikethrough = true end ``` diff --git a/Rakefile b/Rakefile index 3c74416..ed51560 100644 --- a/Rakefile +++ b/Rakefile @@ -13,6 +13,6 @@ task default: :spec task :preview do require 'rucaptcha' - res = RuCaptcha.create(1) + res = RuCaptcha.create(1, 3, 1) puts res[1] -end \ No newline at end of file +end diff --git a/lib/rucaptcha.rb b/lib/rucaptcha.rb index c89c51f..8bd18c4 100644 --- a/lib/rucaptcha.rb +++ b/lib/rucaptcha.rb @@ -15,10 +15,11 @@ module RuCaptcha def config return @config if defined?(@config) @config = Configuration.new - @config.style = :colorful - @config.length = 5 - @config.line = true - @config.expires_in = 2.minutes + @config.style = :colorful + @config.length = 5 + @config.strikethrough = true + @config.expires_in = 2.minutes + if Rails.application @config.cache_store = Rails.application.config.cache_store else @@ -35,9 +36,13 @@ module RuCaptcha def generate() style = config.style == :colorful ? 1 : 0 length = config.length - raise Rucaptcha::Errors::Configuration, 'length config error, value must in 3..7' unless length.in?(3..7) - line = config.line ? 1 : 0 - self.create(style, length, line) + + unless length.in?(3..7) + raise Rucaptcha::Errors::Configuration, 'length config error, value must in 3..7' + end + + strikethrough = config.strikethrough ? 1 : 0 + self.create(style, length, strikethrough) end def check_cache_store! diff --git a/lib/rucaptcha/configuration.rb b/lib/rucaptcha/configuration.rb index 9b383c4..d7dcb32 100644 --- a/lib/rucaptcha/configuration.rb +++ b/lib/rucaptcha/configuration.rb @@ -7,10 +7,9 @@ module RuCaptcha attr_accessor :expires_in # Color style, default: :colorful, allows: [:colorful, :black_white] attr_accessor :style - # Captcha Digits: default 5, allows: [3,4,5,6,7] + # Chars length: default 5, allows: [3..7] attr_accessor :length - # rucaptcha line, default: true, allows: [true, false] - attr_accessor :line - + # strikethrough, default: true + attr_accessor :strikethrough end end diff --git a/lib/rucaptcha/version.rb b/lib/rucaptcha/version.rb index 3adafbc..c090ace 100644 --- a/lib/rucaptcha/version.rb +++ b/lib/rucaptcha/version.rb @@ -1,3 +1,3 @@ module RuCaptcha - VERSION = '2.1.4' + VERSION = '2.2.0' end diff --git a/spec/captcha_spec.rb b/spec/captcha_spec.rb index 41a9bd4..4a6c3a3 100644 --- a/spec/captcha_spec.rb +++ b/spec/captcha_spec.rb @@ -82,14 +82,14 @@ describe RuCaptcha do expect(res[1]).not_to eq(nil) end - it 'should work with line true' do + it 'should work with strikethrough enable' do res = RuCaptcha.create(1, 7, 1) expect(res.length).to eq(2) expect(res[0].length).to eq(7) expect(res[1]).not_to eq(nil) end - it 'should work with line false' do + it 'should work with strikethrough disable' do res = RuCaptcha.create(1, 7, 0) expect(res.length).to eq(2) expect(res[0].length).to eq(7)