class Captchah::Verifier

Public Class Methods

call(params) click to toggle source
# File lib/captchah/verifier.rb, line 5
def self.call(params)
  return :no_params unless params.present?

  return :invalid if params[:guess].blank? || params[:truth].blank?

  truth_payload = Encryptor.decrypt(params[:truth])

  guess = params[:guess].downcase.delete(' ')

  return :expired unless truth_payload[:timestamp] >= Time.current

  return :valid if guess == truth_payload[:truth].downcase

  :invalid
rescue ArgumentError, MessageEncryptor::InvalidMessage
  :invalid
end