3 require File.join(File.dirname(__FILE__), '..', '..', "lib", "authenticated_system", "authenticated_dependencies")
9 include DataMapper::Persistable
10 include AuthenticatedSystem::Model
12 attr_accessor :password, :password_confirmation
14 property :login, :string
15 property :email, :string
16 property :crypted_password, :string
17 property :salt, :string
18 property :activation_code, :string
19 property :activated_at, :datetime
20 property :remember_token_expires_at, :datetime
21 property :remember_token, :string
22 property :created_at, :datetime
23 property :updated_at, :datetime
25 validates_length_of :login, :within => 3..40
26 validates_uniqueness_of :login
27 validates_presence_of :email
28 # validates_format_of :email, :as => :email_address
29 validates_length_of :email, :within => 3..100
30 validates_uniqueness_of :email
31 validates_presence_of :password, :if => proc {password_required?}
32 validates_presence_of :password_confirmation, :if => proc {password_required?}
33 validates_length_of :password, :within => 4..40, :if => proc {password_required?}
34 validates_confirmation_of :password, :groups => :create
36 before_save :encrypt_password
37 before_create :make_activation_code
38 after_create :send_signup_notification
41 @login = value.downcase unless value.nil?
45 EMAIL_FROM = "info@mysite.com"
46 SIGNUP_MAIL_SUBJECT = "Welcome to MYSITE. Please activate your account."
47 ACTIVATE_MAIL_SUBJECT = "Welcome to MYSITE"
49 # Activates the user in the database
52 self.activated_at = Time.now.utc
53 self.activation_code = nil
56 # send mail for activation
57 UserMailer.dispatch_and_deliver( :activation_notification,
58 { :from => User::EMAIL_FROM,
60 :subject => User::ACTIVATE_MAIL_SUBJECT },
66 def send_signup_notification
67 UserMailer.dispatch_and_deliver(
69 { :from => User::EMAIL_FROM,
71 :subject => User::SIGNUP_MAIL_SUBJECT },