Class: Verge::Server::User

Inherits:
Object
  • Object
show all
Includes:
DataMapper::Resource
Defined in:
lib/verge/server/models.rb

Class Method Summary collapse

Instance Method Summary collapse

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(, password)
  user = User.first(:login => )
  (user.nil? || user.password != password) && nil || user
end

.remove_expired_usersObject

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

#tokenObject

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