Module: RailsCaptcha::Model::InstanceMethods

Defined in:
lib/rails_captcha/captcha/model.rb

Instance Method Summary collapse

Instance Method Details

#captcha=(c) ⇒ Object



23
24
25
# File 'lib/rails_captcha/captcha/model.rb', line 23

def captcha=(c)
  @captcha = c || ''
end

#captcha_must_match_known_captchaObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rails_captcha/captcha/model.rb', line 31

def captcha_must_match_known_captcha
  return true if self.captcha.nil? || self.known_captcha.nil?
  decrypted = RailsCaptcha::Cipher.decrypt(self.known_captcha) rescue "no_decrypt"
  if self.captcha.strip.downcase != decrypted
    if self.captcha_options[:base]
      self.errors.add_to_base(
        case self.captcha_options[:base]
        when true
          I18n.t("rails_captcha.enter_the_correct_captcha")
        else
          self.captcha_options[:base]
        end
      )
    else
      self.errors.add(:captcha,
        case self.captcha_options[:field]
        when true, nil
          I18n.t("rails_captcha.wrong_captcha")
        else
          self.captcha_options[:field]
        end
      )
    end
  end
end

#known_captcha=(c) ⇒ Object



27
28
29
# File 'lib/rails_captcha/captcha/model.rb', line 27

def known_captcha=(c)
  @known_captcha = c || ''
end