Module: Confirmable

Extended by:
ActiveSupport::Concern
Defined in:
lib/generators/propel_authentication/templates/concerns/confirmable.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#can_login?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/generators/propel_authentication/templates/concerns/confirmable.rb', line 28

def can_login?
  confirmed? && !locked?
end

#confirm_by_token(token) ⇒ Object

CONFIRMATION TOKEN METHODS



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/generators/propel_authentication/templates/concerns/confirmable.rb', line 34

def confirm_by_token(token)
  return false if token.blank? || confirmation_token.blank?
  return false unless secure_compare(token, confirmation_token)
  return false if confirmation_expired?

  self.confirmed_at = Time.current
  self.confirmation_token = nil
  self.confirmation_sent_at = nil
  
  # If there's a pending email change, apply it
  if unconfirmed_email_address.present?
    self.email_address = unconfirmed_email_address
    self.unconfirmed_email_address = nil
  end
  
  save(validate: false)
end

#confirmation_expired?Boolean

Returns:

  • (Boolean)


23
24
25
26
# File 'lib/generators/propel_authentication/templates/concerns/confirmable.rb', line 23

def confirmation_expired?
  return false if confirmation_sent_at.blank?
  confirmation_sent_at < confirmation_period.ago
end

#confirmation_pending?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/generators/propel_authentication/templates/concerns/confirmable.rb', line 19

def confirmation_pending?
  !confirmed? && confirmation_token.present?
end

#confirmed?Boolean

CONFIRMATION STATUS METHODS

Returns:

  • (Boolean)


15
16
17
# File 'lib/generators/propel_authentication/templates/concerns/confirmable.rb', line 15

def confirmed?
  confirmed_at.present?
end

#resend_confirmation_instructionsObject



64
65
66
67
68
# File 'lib/generators/propel_authentication/templates/concerns/confirmable.rb', line 64

def resend_confirmation_instructions
  return false if confirmed?
  
  send_confirmation_instructions
end

#send_confirmation_instructionsObject



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/generators/propel_authentication/templates/concerns/confirmable.rb', line 52

def send_confirmation_instructions
  return false if confirmed?
  return false if confirmation_rate_limited?

  generate_confirmation_token
  self.confirmation_sent_at = Time.current
  save(validate: false)

  AuthMailer.email_confirmation(self).deliver_now
  true
end