Class: Verge::Server::User
- Inherits:
-
Object
- Object
- Verge::Server::User
- Includes:
- DataMapper::Resource
- Defined in:
- lib/verge/server/models.rb
Class Method Summary collapse
-
.authenticate(login, password) ⇒ Object
Attempts to find a user based on the credentials passed.
-
.remove_expired_users ⇒ Object
Removes expired users.
Instance Method Summary collapse
-
#activate! ⇒ Object
Marks this user as valid.
-
#generate_token(expiry = nil) ⇒ Object
Generates a new token for this user.
-
#token ⇒ Object
Returns a valid token for this user.
Class Method Details
.authenticate(login, password) ⇒ Object
Attempts to find a user based on the credentials passed.
47 48 49 50 |
# File 'lib/verge/server/models.rb', line 47 def self.authenticate(login, password) user = User.first(:login => login) (user.nil? || user.password != password) && nil || user end |
.remove_expired_users ⇒ Object
Removes expired users
53 54 55 |
# File 'lib/verge/server/models.rb', line 53 def self.remove_expired_users User.all(:expiry.lt => DateTime.now).destroy end |
Instance Method Details
#activate! ⇒ Object
Marks this user as valid. Invalid users will be destroyed after their expiry passes.
40 41 42 43 44 |
# File 'lib/verge/server/models.rb', line 40 def activate! activated = true expiry = nil save end |
#generate_token(expiry = nil) ⇒ Object
Generates a new token for this user.
29 30 31 |
# File 'lib/verge/server/models.rb', line 29 def generate_token(expiry = nil) tokens.create(expiry && {:expiry => expiry} || {}) end |
#token ⇒ Object
Returns a valid token for this user. If no tokens exist on is created
34 35 36 |
# File 'lib/verge/server/models.rb', line 34 def token tokens.count > 0 ? tokens.first : generate_token end |