Class: User

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/generators/authkit/templates/app/models/user.rb

Instance Method Summary collapse

Instance Method Details

#change_password(password, password_confirmation) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/generators/authkit/templates/app/models/user.rb', line 128

def change_password(password, password_confirmation)
  self.password = password
  self.password_confirmation = password_confirmation

  # Don't nil out the token unless the changes are valid as it may be
  # needed again (when re-rendering the form, for instance)
  if valid?
    self.reset_password_token = nil
    self.reset_password_token_created_at = nil
  end

  self.save
end

#clear_remember_tokenObject



57
58
59
60
61
# File 'lib/generators/authkit/templates/app/models/user.rb', line 57

def clear_remember_token
  self.remember_token = nil
  self.remember_token_created_at = nil
  self.save!
end

#confirmation_token_expired?Boolean

Returns:

  • (Boolean)


68
69
70
71
# File 'lib/generators/authkit/templates/app/models/user.rb', line 68

def confirmation_token_expired?
  # TODO confirmation tokens expire in 3 days by default
  self.confirmation_token_created_at.blank? || self.confirmation_token_created_at <= 3.days.ago
end

#display_nameObject



34
35
36
# File 'lib/generators/authkit/templates/app/models/user.rb', line 34

def display_name
  [first_name, last_name].compact.join(" ")
end

#email_confirmedObject



113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/generators/authkit/templates/app/models/user.rb', line 113

def email_confirmed
  return false if self.confirmation_token.blank? || self.confirmation_email.blank?

  self.email = self.confirmation_email

  # Don't nil out the token unless the changes are valid as it may be
  # needed again (when re-rendering the form, for instance)
  if valid?
    self.confirmation_token = nil
    self.confirmation_token_created_at = nil
  end

  self.save
end

#pending_confirmation?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/generators/authkit/templates/app/models/user.rb', line 109

def pending_confirmation?
  self.confirmation_token.present?
end

#remember_token_expired?Boolean

Returns:

  • (Boolean)


73
74
75
76
# File 'lib/generators/authkit/templates/app/models/user.rb', line 73

def remember_token_expired?
  # TODO remember tokens expire in 1 year by default
  self.remember_token_created_at.blank? || self.remember_token_created_at <= 1.year.ago
end

#reset_password_token_expired?Boolean

Returns:

  • (Boolean)


63
64
65
66
# File 'lib/generators/authkit/templates/app/models/user.rb', line 63

def reset_password_token_expired?
  # TODO reset password tokens expire in 1 day by default
  self.reset_password_token_created_at.blank? || self.reset_password_token_created_at <= 1.day.ago
end

#send_confirmationObject

The tokens created by this method have unique indexes but collisions are very unlikely (1/64^32). Because of this there shouldn’t be a conflict. If one occurs the ActiveRecord::StatementInvalid or ActiveRecord::RecordNotUnique exeception should bubble up.



100
101
102
103
104
105
106
107
# File 'lib/generators/authkit/templates/app/models/user.rb', line 100

def send_confirmation
  self.confirmation_token = SecureRandom.urlsafe_base64(32)
  self.confirmation_token_created_at = Time.now
  self.save!

  # TODO: insert your mailer logic here
  true
end

#send_reset_passwordObject

The tokens created by this method have unique indexes but collisions are very unlikely (1/64^32). Because of this there shouldn’t be a conflict. If one occurs the ActiveRecord::StatementInvalid or ActiveRecord::RecordNotUnique exeception should bubble up.



87
88
89
90
91
92
93
94
# File 'lib/generators/authkit/templates/app/models/user.rb', line 87

def send_reset_password
  self.reset_password_token = SecureRandom.urlsafe_base64(32)
  self.reset_password_token_created_at = Time.now
  self.save!

  # TODO: insert your mailer logic here
  true
end

#send_welcomeObject



78
79
80
81
# File 'lib/generators/authkit/templates/app/models/user.rb', line 78

def send_welcome
  # TODO insert your mailer logic here
  true
end

#set_remember_tokenObject

The tokens created by this method have unique indexes but collisions are very unlikely (1/64^32). Because of this there shouldn’t be a conflict. If one occurs the ActiveRecord::StatementInvalid or ActiveRecord::RecordNotUnique exeception should bubble up.



51
52
53
54
55
# File 'lib/generators/authkit/templates/app/models/user.rb', line 51

def set_remember_token
  self.remember_token = SecureRandom.urlsafe_base64(32)
  self.remember_token_created_at = Time.now
  self.save!
end

#track_sign_in(ip) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/generators/authkit/templates/app/models/user.rb', line 38

def (ip)
  self. += 1
  self. = self.
  self. = self.
  self. = Time.now
  self. = ip
  self.save
end