Class: Sinatra::Doorman::User
- Inherits:
-
Object
- Object
- Sinatra::Doorman::User
- Includes:
- DataMapper::Resource
- Defined in:
- lib/doorman/user.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
-
#password_confirmation ⇒ Object
Returns the value of attribute password_confirmation.
Class Method Summary collapse
Instance Method Summary collapse
- #authenticated?(password) ⇒ Boolean
- #confirm_email! ⇒ Object
- #forget_me! ⇒ Object
- #forgot_password! ⇒ Object
- #remember_me! ⇒ Object
- #remembered_password! ⇒ Object
- #reset_password!(new_password, new_password_confirmation) ⇒ Object
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
23 24 25 |
# File 'lib/doorman/user.rb', line 23 def password @password end |
#password_confirmation ⇒ Object
Returns the value of attribute password_confirmation.
23 24 25 |
# File 'lib/doorman/user.rb', line 23 def password_confirmation @password_confirmation end |
Class Method Details
.authenticate(login, password) ⇒ Object
41 42 43 44 45 |
# File 'lib/doorman/user.rb', line 41 def self.authenticate(login, password) user = User.first_by_login(login) return user if user && user.authenticated?(password) return nil end |
.first_by_login(login) ⇒ Object
35 36 37 38 39 |
# File 'lib/doorman/user.rb', line 35 def self.first_by_login(login) #if login has @ symbol, treat as email address column = ( login =~ /@/ ? :email : :username ) User.first(column => login) end |
Instance Method Details
#authenticated?(password) ⇒ Boolean
47 48 49 |
# File 'lib/doorman/user.rb', line 47 def authenticated?(password) self.password_hash == encrypt(password) end |
#confirm_email! ⇒ Object
61 62 63 64 65 |
# File 'lib/doorman/user.rb', line 61 def confirm_email! self.confirmed = true self.confirm_token = nil save end |
#forget_me! ⇒ Object
56 57 58 59 |
# File 'lib/doorman/user.rb', line 56 def forget_me! self.remember_token = nil save end |
#forgot_password! ⇒ Object
67 68 69 70 |
# File 'lib/doorman/user.rb', line 67 def forgot_password! self.confirm_token = new_token save end |
#remember_me! ⇒ Object
51 52 53 54 |
# File 'lib/doorman/user.rb', line 51 def remember_me! self.remember_token = new_token save end |
#remembered_password! ⇒ Object
72 73 74 75 |
# File 'lib/doorman/user.rb', line 72 def remembered_password! self.confirm_token = nil save end |
#reset_password!(new_password, new_password_confirmation) ⇒ Object
77 78 79 80 81 82 |
# File 'lib/doorman/user.rb', line 77 def reset_password!(new_password, new_password_confirmation) self.password = new_password self.password_confirmation = new_password_confirmation self.password_hash = encrypt(password) if valid? save end |