Class: Beeta::Model::User

Inherits:
Sequel::Model
  • Object
show all
Includes:
Mixin
Defined in:
lib/beeta/model.rb

Constant Summary collapse

PublicProperties =
[
  :email,
  :created,
  :app_uris,
]

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixin

#to_json

Class Method Details

.authenticate(email, pw) ⇒ Object



31
32
33
34
35
# File 'lib/beeta/model.rb', line 31

def self.authenticate email, pw
  u = self[:email => email]
  return unless u
  return u if hash_password(u.salt, pw) == u.hashed_password
end

.hash_password(salt, pw) ⇒ Object



27
28
29
# File 'lib/beeta/model.rb', line 27

def self.hash_password salt, pw
  Digest::SHA1.hexdigest "#{salt}#{pw}"
end

.random_saltObject



23
24
25
# File 'lib/beeta/model.rb', line 23

def self.random_salt
  rand.to_s[2..-1]
end

Instance Method Details

#app_urisObject



42
43
44
# File 'lib/beeta/model.rb', line 42

def app_uris
  []
end

#before_createObject



37
38
39
40
# File 'lib/beeta/model.rb', line 37

def before_create
  self.created = Time.now
  super
end

#password=(pw) ⇒ Object



46
47
48
49
50
# File 'lib/beeta/model.rb', line 46

def password=(pw)
  self.salt = self.class.random_salt
  self.hashed_password = self.class.hash_password salt, pw
  pw
end