config.line -> config.strikethrough and release version 2.2.0
This commit is contained in:
parent
3939d1bb02
commit
0561e88a22
|
@ -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
|
||||
-----
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
```
|
||||
|
||||
|
|
2
Rakefile
2
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
|
|
@ -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!
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
module RuCaptcha
|
||||
VERSION = '2.1.4'
|
||||
VERSION = '2.2.0'
|
||||
end
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue