module SimpleCaptchaReloaded::Model

Attributes

captcha[RW]
captcha_key[RW]

Public Instance Methods

captcha_valid?() click to toggle source
# File lib/simple_captcha_reloaded/model.rb, line 12
def captcha_valid?
  if @last_result.nil?
    @last_result = begin
                     data = SimpleCaptchaReloaded::Data.where(key: captcha_key).first
                     if !data
                       errors.add :captcha, I18n.t('simple_captcha_reloaded.errors.missing_captcha')
                       false
                     elsif !captcha.present?
                       errors.add :captcha, I18n.t('simple_captcha_reloaded.errors.blank')
                       false
                     elsif not data.valid_captcha?(captcha)
                       errors.add :captcha, I18n.t('simple_captcha_reloaded.errors.wrong')
                       false
                     else
                       true
                     end
                   end
  end
  @last_result
end
save_with_captcha(*args) click to toggle source
# File lib/simple_captcha_reloaded/model.rb, line 8
def save_with_captcha(*args)
  valid_with_captcha? & save(*args)
end
valid_with_captcha?() click to toggle source
# File lib/simple_captcha_reloaded/model.rb, line 4
def valid_with_captcha?
  valid? & captcha_valid?
end