Added session[:_rucaptcha] expire time to configuration.

This commit is contained in:
tiroc 2016-03-14 16:41:27 +08:00
parent 2361f61ac8
commit 77ed68d112
4 changed files with 5 additions and 1 deletions

View File

@ -18,6 +18,7 @@ module RuCaptcha
@config.font_size = 45 @config.font_size = 45
@config.implode = 0.4 @config.implode = 0.4
@config.cache_limit = 100 @config.cache_limit = 100
@config.expires_in = 2.minutes
@config @config
end end

View File

@ -11,5 +11,7 @@ module RuCaptcha
# Number of Captcha codes limit # Number of Captcha codes limit
# set 0 to disable limit and file cache, default: 100 # set 0 to disable limit and file cache, default: 100
attr_accessor :cache_limit attr_accessor :cache_limit
# session[:_rucaptcha] expire time, default 2 minutes
attr_accessor :expires_in
end end
end end

View File

@ -16,7 +16,7 @@ module RuCaptcha
def verify_rucaptcha?(resource = nil) def verify_rucaptcha?(resource = nil)
rucaptcha_at = session[:_rucaptcha_at].to_i rucaptcha_at = session[:_rucaptcha_at].to_i
# Captcha chars in Session expire in 2 minutes # Captcha chars in Session expire in 2 minutes
if (Time.now.to_i - rucaptcha_at) > 120 if (Time.now.to_i - rucaptcha_at) > RuCaptcha.config.expires_in
return false return false
end end

View File

@ -6,6 +6,7 @@ describe RuCaptcha do
expect(RuCaptcha.config.len).to eq(2) expect(RuCaptcha.config.len).to eq(2)
expect(RuCaptcha.config.font_size).to eq(48) expect(RuCaptcha.config.font_size).to eq(48)
expect(RuCaptcha.config.implode).to eq(0.111) expect(RuCaptcha.config.implode).to eq(0.111)
expect(RuCaptcha.config.expires_in).to eq(2.minutes)
end end
end end
end end