Class: NoPassword::Email::Challenge

Inherits:
Link::Challenge show all
Defined in:
lib/nopassword/email/challenge.rb

Overview

Email-specific challenge that aliases identifier as email for convenience.

Constant Summary

Constants inherited from Link::Challenge

Link::Challenge::DEFAULT_TTL, Link::Challenge::TOKEN_SIZE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Link::Challenge

#expires_at

Methods inherited from Link::Base

#delete, delete, #persisted?, #save!, #save_without_validation, update

Constructor Details

#initialize(session, authentication: nil) ⇒ Challenge

Returns a new instance of Challenge.



10
11
12
13
# File 'lib/nopassword/email/challenge.rb', line 10

def initialize(session, authentication: nil, **)
  @authentication = authentication
  super(session, **)
end

Instance Attribute Details

#authenticationObject (readonly)

Returns the value of attribute authentication.



5
6
7
# File 'lib/nopassword/email/challenge.rb', line 5

def authentication
  @authentication
end

Instance Method Details

#emailObject

Convenience accessor - email is stored as identifier



16
17
18
# File 'lib/nopassword/email/challenge.rb', line 16

def email
  identifier
end

#email=(value) ⇒ Object



20
21
22
# File 'lib/nopassword/email/challenge.rb', line 20

def email=(value)
  self.identifier = value
end

#saveObject



24
25
26
27
28
29
30
31
32
# File 'lib/nopassword/email/challenge.rb', line 24

def save
  return false unless valid?
  # Sync email back to authentication before saving
  if authentication
    authentication.email = email
    authentication.save_without_validation
  end
  super
end