Module: Userify::User::InstanceMethods
- Defined in:
- lib/userify/user.rb
Instance Method Summary collapse
- #authenticated?(password) ⇒ Boolean
- #clear_token! ⇒ Object
- #confirm_email! ⇒ Object
- #encrypt(string) ⇒ Object
- #name ⇒ Object
- #remember? ⇒ Boolean
- #remember_me!(duration = 183) ⇒ Object
- #set_token!(expires_at = nil) ⇒ Object
- #update_password(new_password) ⇒ Object
Instance Method Details
#authenticated?(password) ⇒ Boolean
35 36 37 |
# File 'lib/userify/user.rb', line 35 def authenticated?(password) encrypted_password == encrypt(password) end |
#clear_token! ⇒ Object
69 70 71 72 |
# File 'lib/userify/user.rb', line 69 def clear_token! clear_token save end |
#confirm_email! ⇒ Object
52 53 54 55 56 |
# File 'lib/userify/user.rb', line 52 def confirm_email! self.is_email_confirmed = true clear_token save end |
#encrypt(string) ⇒ Object
39 40 41 |
# File 'lib/userify/user.rb', line 39 def encrypt(string) Digest::SHA1.hexdigest("--#{salt}--#{string}--") end |
#name ⇒ Object
31 32 33 |
# File 'lib/userify/user.rb', line 31 def name self.fullname or self.username end |
#remember? ⇒ Boolean
43 44 45 |
# File 'lib/userify/user.rb', line 43 def remember? is_email_confirmed? and token_expires_at and Time.now < token_expires_at end |
#remember_me!(duration = 183) ⇒ Object
47 48 49 50 |
# File 'lib/userify/user.rb', line 47 def remember_me!(duration=183) set_token duration.days.from_now unless remember? save end |
#set_token!(expires_at = nil) ⇒ Object
64 65 66 67 |
# File 'lib/userify/user.rb', line 64 def set_token!(expires_at=nil) set_token expires_at save end |
#update_password(new_password) ⇒ Object
58 59 60 61 62 |
# File 'lib/userify/user.rb', line 58 def update_password(new_password) self.password = new_password clear_token if valid? save end |