Module: Captchator::Controller
- Included in:
- ActionController::Base
- Defined in:
- lib/captchator/controller.rb
Instance Method Summary collapse
- #captchator_session_id ⇒ Object
- #captchator_test ⇒ Object
-
#save_with_captchator(record, options = {}) ⇒ Object
> Accepts the following options: message.
- #verify_captchator ⇒ Object
Instance Method Details
#captchator_session_id ⇒ Object
16 17 18 |
# File 'lib/captchator/controller.rb', line 16 def captchator_session_id @captchator_session_id ||= (ENV['captchator_session_id'] || session[:session_id] || "#{rand}".gsub(/[^\d]/, '')) end |
#captchator_test ⇒ Object
25 26 27 |
# File 'lib/captchator/controller.rb', line 25 def captchator_test true end |
#save_with_captchator(record, options = {}) ⇒ Object
> Accepts the following options: message.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/captchator/controller.rb', line 5 def save_with_captchator(record, = {}) = [:message] || "Captchator thinks you are a robot. Please try again." return record.save unless record.valid? if !verify_captchator record.errors.add(:base, ) return false else return record.save end end |
#verify_captchator ⇒ Object
20 21 22 23 |
# File 'lib/captchator/controller.rb', line 20 def verify_captchator return captchator_test if Rails.env.test? open("http://captchator.com/captcha/check_answer/#{captchator_session_id}/#{params[:captchator_answer]}").read == '1' end |