module SmartCapcha::Controller
Public Class Methods
included(obj)
click to toggle source
# File lib/smart_capcha.rb, line 7 def self.included(obj) obj.helper_method :captcha_passed?, :prepare_capcha_question obj.helper SmartCapcha::Helper end
Public Instance Methods
captcha_failure()
click to toggle source
# File lib/smart_capcha.rb, line 27 def captcha_failure flash[:capcha_error] = Questionnaire.config[:failure_message] false end
captcha_passed?()
click to toggle source
# File lib/smart_capcha.rb, line 23 def captcha_passed? session[:captcha_status] == encrypt(params[:captcha_answer]) end
prepare_capcha_question()
click to toggle source
# File lib/smart_capcha.rb, line 17 def prepare_capcha_question result = Questionnaire.find_random_question session[:captcha_status] = encrypt(result.last) result.first end
valid_smart_capcha?()
click to toggle source
# File lib/smart_capcha.rb, line 12 def valid_smart_capcha? return captcha_failure unless params[:captcha_answer] captcha_passed? ? true : captcha_failure end
Private Instance Methods
encrypt(answer)
click to toggle source
# File lib/smart_capcha.rb, line 34 def encrypt(answer) Digest::SHA512.hexdigest("--#{answer}--#{Questionnaire.config[:salt]}--") end