Class: SpamProtect::Guardian
- Inherits:
-
Object
- Object
- SpamProtect::Guardian
- Defined in:
- lib/spam_protect/guardian.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
-
#initialize(honeypot_value, encrypted_timestamp, cookie, min_seconds) ⇒ Guardian
constructor
A new instance of Guardian.
- #valid? ⇒ Boolean
Constructor Details
#initialize(honeypot_value, encrypted_timestamp, cookie, min_seconds) ⇒ Guardian
7 8 9 10 11 12 13 |
# File 'lib/spam_protect/guardian.rb', line 7 def initialize(honeypot_value, , , min_seconds) @honeypot_value = honeypot_value @encrypted_timestamp = @cookie = @min_seconds = min_seconds @errors = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
5 6 7 |
# File 'lib/spam_protect/guardian.rb', line 5 def errors @errors end |
Instance Method Details
#valid? ⇒ Boolean
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 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 56 57 58 59 60 61 |
# File 'lib/spam_protect/guardian.rb', line 15 def valid? payload = Encryption::Payload.new( Encryption.decrypt(@encrypted_timestamp) ) = if SpamProtect.config.require_js Encryption::Payload.new( Encryption.decrypt(@cookie) ) end payloads = [ payload, ].compact honeypot_policy = Policies::HoneypotPolicy.new(@honeypot_value) if honeypot_policy.invalid? @errors.append "Honeypot field is filled in" return false end = Policies::CookiePolicy.new(@cookie) if .invalid? @errors.append "Cookie is invalid" return false end payloads.each do |p| encryption_policy = Policies::EncryptionPolicy.new(p) if encryption_policy.invalid? @errors.append "Payload encryption is invalid or expired" return false end = Policies::TimestampPolicy.new(p["timestamp"], @min_seconds) if .invalid? @errors.append "Form submitted too quickly" return false end end true rescue @errors.append "Encryption failure" false end |