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
|
0.4.0
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
PATH
|
PATH
|
||||||
remote: .
|
remote: .
|
||||||
specs:
|
specs:
|
||||||
rucaptcha (0.4.0)
|
rucaptcha (0.4.1)
|
||||||
posix-spawn (>= 0.3.0)
|
posix-spawn (>= 0.3.0)
|
||||||
|
|
||||||
GEM
|
GEM
|
||||||
|
|
|
@ -15,17 +15,19 @@ 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 = params[:_rucaptcha].downcase.strip
|
||||||
|
|
||||||
# Captcha chars in Session expire in 2 minutes
|
# Captcha chars in Session expire in 2 minutes
|
||||||
if (Time.now.to_i - rucaptcha_at) > RuCaptcha.config.expires_in
|
valid = false
|
||||||
return false
|
if (Time.now.to_i - rucaptcha_at) <= RuCaptcha.config.expires_in
|
||||||
|
valid = captcha.present? && captcha == session[:_rucaptcha]
|
||||||
end
|
end
|
||||||
|
|
||||||
right = params[:_rucaptcha].present? && session[:_rucaptcha].present? &&
|
|
||||||
params[:_rucaptcha].downcase.strip == session[:_rucaptcha]
|
|
||||||
if resource && resource.respond_to?(:errors)
|
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
|
end
|
||||||
right
|
|
||||||
|
valid
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
module RuCaptcha
|
module RuCaptcha
|
||||||
VERSION = '0.4.0'
|
VERSION = '0.4.1'
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue