Class: AltchaSolution
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- AltchaSolution
- Defined in:
- lib/generators/altcha/install/templates/models/altcha_solution.rb
Instance Attribute Summary collapse
-
#took ⇒ Object
Returns the value of attribute took.
Class Method Summary collapse
Instance Attribute Details
#took ⇒ Object
Returns the value of attribute took.
3 4 5 |
# File 'lib/generators/altcha/install/templates/models/altcha_solution.rb', line 3 def took @took end |
Class Method Details
.cleanup ⇒ Object
22 23 24 25 26 27 |
# File 'lib/generators/altcha/install/templates/models/altcha_solution.rb', line 22 def self.cleanup # Replay attacks are protected by the time stamp in the salt of the challenge for # the duration configured in the timeout. All solutions in the database that older # can be deleted. AltchaSolution.where('created_at < ?', Time.now - Altcha.timeout).delete_all end |
.verify_and_save(base64encoded) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/generators/altcha/install/templates/models/altcha_solution.rb', line 5 def self.verify_and_save(base64encoded) p = JSON.parse(Base64.decode64(base64encoded)) rescue nil return false if p.nil? submission = Altcha::Submission.new(p) return false unless submission.valid? solution = self.new(p) begin return solution.save rescue ActiveRecord::RecordNotUnique # Replay attack return false end end |