Add error message to resource when captcha code expired. close #22

This commit is contained in:
Jason Lee 2016-04-24 20:20:01 +08:00
parent 0a7fa3782b
commit be7d72feb0
4 changed files with 15 additions and 8 deletions

View File

@ -1,3 +1,8 @@
0.4.1
-----
- Add error message to resource when captcha code expired.
0.4.0
-----

View File

@ -1,7 +1,7 @@
PATH
remote: .
specs:
rucaptcha (0.4.0)
rucaptcha (0.4.1)
posix-spawn (>= 0.3.0)
GEM

View File

@ -15,17 +15,19 @@ module RuCaptcha
def verify_rucaptcha?(resource = nil)
rucaptcha_at = session[:_rucaptcha_at].to_i
captcha = params[:_rucaptcha].downcase.strip
# Captcha chars in Session expire in 2 minutes
if (Time.now.to_i - rucaptcha_at) > RuCaptcha.config.expires_in
return false
valid = false
if (Time.now.to_i - rucaptcha_at) <= RuCaptcha.config.expires_in
valid = captcha.present? && captcha == session[:_rucaptcha]
end
right = params[:_rucaptcha].present? && session[:_rucaptcha].present? &&
params[:_rucaptcha].downcase.strip == session[:_rucaptcha]
if resource && resource.respond_to?(:errors)
resource.errors.add(:base, t('rucaptcha.invalid')) unless right
resource.errors.add(:base, t('rucaptcha.invalid')) unless valid
end
right
valid
end
end
end

View File

@ -1,3 +1,3 @@
module RuCaptcha
VERSION = '0.4.0'
VERSION = '0.4.1'
end