Class: PUNK::ChallengeClaimService

Inherits:
Service show all
Defined in:
lib/punk/services/challenge_claim.rb

Instance Attribute Summary

Attributes included from Validatable

#errors

Instance Method Summary collapse

Methods inherited from Service

#result, run

Methods included from Loggable

#exception, #logger, #profile_debug, #profile_info, #profile_trace

Methods inherited from Runnable

args, #method_missing, #respond_to_missing?

Methods included from Validatable

#default_validation_helpers_options, #get_column_value, #valid?, #validates_not_empty

Methods included from Plugins::Validation::InstanceMethods

#validates_email, #validates_event, #validates_phone, #validates_state, #validates_url

Methods inherited from Settings

#method_missing, #respond_to_missing?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class PUNK::Runnable

Instance Method Details

#processObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/punk/services/challenge_claim.rb', line 18

def process
  secret = SecretService.run.result
  salt = RbNaCl::Random.random_bytes(RbNaCl::PasswordHash::SCrypt::SALTBYTES)
  hash = RbNaCl::PasswordHash.scrypt(secret, salt, 1_048_576, 16_777_216)
  session.update(salt: salt, hash: hash)
  session.challenge!
  identity = session.identity
  case identity.claim_type
  when :email
    SendEmailWorker.perform_async(
      from: "GroupFire Accounts <[email protected]>",
      to: identity.claim,
      subject: "[GroupFire] Verification Code",
      template: "verify",
      tags: [:auth],
      variables: {
        name: identity.user&.name || "New User",
        secret: secret
      }
    )
  when :phone
    SendSmsWorker.perform_async(
      to: identity.claim,
      body: "Your GroupFire verification code is: #{secret}."
    )
  end
end

#validateObject



9
10
11
12
13
14
15
16
# File 'lib/punk/services/challenge_claim.rb', line 9

def validate
  validates_not_null :session
  validates_not_empty :session
  return if session.blank?
  validates_type Session, :session
  validates_state :session, :created
  validates_event :session, :challenge
end