Class: User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- User
- Defined in:
- lib/generators/authkit/templates/app/models/user.rb
Instance Method Summary collapse
- #change_password(password, password_confirmation) ⇒ Object
- #clear_remember_token ⇒ Object
- #confirmation_token_expired? ⇒ Boolean
- #display_name ⇒ Object
- #email_confirmed ⇒ Object
- #pending_confirmation? ⇒ Boolean
- #remember_token_expired? ⇒ Boolean
- #reset_password_token_expired? ⇒ Boolean
-
#send_confirmation ⇒ Object
The tokens created by this method have unique indexes but collisions are very unlikely (1/64^32).
-
#send_reset_password ⇒ Object
The tokens created by this method have unique indexes but collisions are very unlikely (1/64^32).
- #send_welcome ⇒ Object
-
#set_remember_token ⇒ Object
The tokens created by this method have unique indexes but collisions are very unlikely (1/64^32).
- #track_sign_in(ip) ⇒ Object
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_token ⇒ Object
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
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_name ⇒ Object
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_confirmed ⇒ Object
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
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
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
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_confirmation ⇒ Object
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_password ⇒ Object
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_welcome ⇒ Object
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_token ⇒ Object
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 track_sign_in(ip) self.sign_in_count += 1 self.last_sign_in_at = self.current_sign_in_at self.last_sign_in_ip = self.current_sign_in_ip self.current_sign_in_at = Time.now self.current_sign_in_ip = ip self.save end |