2011-03-10 21:48:15 +00:00
|
|
|
require 'digest/md5'
|
2011-03-09 16:16:48 +00:00
|
|
|
class User < ActiveRecord::Base
|
|
|
|
devise :database_authenticatable,
|
|
|
|
:recoverable, :rememberable, :validatable
|
|
|
|
|
|
|
|
attr_accessible :email, :password, :password_confirmation, :remember_me, :name
|
2011-03-10 21:48:15 +00:00
|
|
|
|
|
|
|
before_validation :generate_password, :on => :create
|
|
|
|
after_create :send_notification_email
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def generate_password
|
2011-03-29 23:16:04 +01:00
|
|
|
if self.password.blank?
|
|
|
|
self.password = self.password_confirmation = Digest::MD5.hexdigest(Date.today.to_s)[0..6]
|
|
|
|
end
|
2011-03-10 21:48:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def send_notification_email
|
|
|
|
UserMailer.new_user_notification(self).deliver
|
|
|
|
end
|
2011-03-09 16:16:48 +00:00
|
|
|
end
|