Class: Captchah::Verifier

Inherits:
Object
  • Object
show all
Defined in:
lib/captchah/verifier.rb

Class Method Summary collapse

Class Method Details

.call(params) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 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