Add error message to resource when captcha code expired. close #22
This commit is contained in:
parent
0a7fa3782b
commit
be7d72feb0
|
@ -1,3 +1,8 @@
|
|||
0.4.1
|
||||
-----
|
||||
|
||||
- Add error message to resource when captcha code expired.
|
||||
|
||||
0.4.0
|
||||
-----
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
rucaptcha (0.4.0)
|
||||
rucaptcha (0.4.1)
|
||||
posix-spawn (>= 0.3.0)
|
||||
|
||||
GEM
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
module RuCaptcha
|
||||
VERSION = '0.4.0'
|
||||
VERSION = '0.4.1'
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue