def set_defaults
self.creation_time = Time.now
self.timeout = Time.now
- self.token = make_token()
+ self.token = User.make_token()
end
def pass_crypt=(str)
def self.authenticate(email, passwd)
find_first([ "email = ? AND pass_crypt =?", email, Digest::MD5.hexdigest(passwd) ])
end
+
+ def self.authenticate_token(token)
+ find_first([ "token = ? ", token])
+ end
- private
- def make_token
+ def self.make_token(length=30)
chars = 'abcdefghijklmnopqrtuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
confirmstring = ''
- 30.times do
+ length.times do
confirmstring += chars[(rand * chars.length).to_i].chr
end