From 77ed68d1120876346e12cae785803ad988a0b9c3 Mon Sep 17 00:00:00 2001 From: tiroc Date: Mon, 14 Mar 2016 16:41:27 +0800 Subject: [PATCH] Added session[:_rucaptcha] expire time to configuration. --- lib/rucaptcha.rb | 1 + lib/rucaptcha/configuration.rb | 2 ++ lib/rucaptcha/controller_helpers.rb | 2 +- spec/configure_spec.rb | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/rucaptcha.rb b/lib/rucaptcha.rb index 3535f61..e444f46 100644 --- a/lib/rucaptcha.rb +++ b/lib/rucaptcha.rb @@ -18,6 +18,7 @@ module RuCaptcha @config.font_size = 45 @config.implode = 0.4 @config.cache_limit = 100 + @config.expires_in = 2.minutes @config end diff --git a/lib/rucaptcha/configuration.rb b/lib/rucaptcha/configuration.rb index 2c502e4..394f0da 100644 --- a/lib/rucaptcha/configuration.rb +++ b/lib/rucaptcha/configuration.rb @@ -11,5 +11,7 @@ module RuCaptcha # Number of Captcha codes limit # set 0 to disable limit and file cache, default: 100 attr_accessor :cache_limit + # session[:_rucaptcha] expire time, default 2 minutes + attr_accessor :expires_in end end diff --git a/lib/rucaptcha/controller_helpers.rb b/lib/rucaptcha/controller_helpers.rb index 845551f..daf530e 100644 --- a/lib/rucaptcha/controller_helpers.rb +++ b/lib/rucaptcha/controller_helpers.rb @@ -16,7 +16,7 @@ module RuCaptcha def verify_rucaptcha?(resource = nil) rucaptcha_at = session[:_rucaptcha_at].to_i # 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 end diff --git a/spec/configure_spec.rb b/spec/configure_spec.rb index a384113..90c9e50 100644 --- a/spec/configure_spec.rb +++ b/spec/configure_spec.rb @@ -6,6 +6,7 @@ describe RuCaptcha do expect(RuCaptcha.config.len).to eq(2) expect(RuCaptcha.config.font_size).to eq(48) expect(RuCaptcha.config.implode).to eq(0.111) + expect(RuCaptcha.config.expires_in).to eq(2.minutes) end end end