3 class User < ActiveRecord::Base
6 validates_confirmation_of :pass_crypt, :message => 'Password must match the confirmation password'
7 validates_uniqueness_of :display_name
8 validates_uniqueness_of :email
9 validates_length_of :pass_crypt, :minimum => 8
10 validates_length_of :display_name, :minimum => 3
11 validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
14 self.creation_time = Time.now
15 self.timeout = Time.now
16 self.token = make_token()
20 write_attribute("pass_crypt", Digest::MD5.hexdigest(str))
23 def pass_crypt_confirmation=(str)
24 write_attribute("pass_crypt_confirm", Digest::MD5.hexdigest(str))
27 def self.authenticate(email, passwd)
28 find_first([ "email = ? AND pass_crypt =?", email, Digest::MD5.hexdigest(passwd) ])
33 chars = 'abcdefghijklmnopqrtuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
37 confirmstring += chars[(rand * chars.length).to_i].chr