3 require "dm-aggregates"
4 require "dm-validations"
6 require File.join(File.dirname(__FILE__), '..', '..', "lib", "authenticated_system", "authenticated_dependencies")
12 include DataMapper::Resource
13 include AuthenticatedSystem::Model
15 attr_accessor :password, :password_confirmation
17 property :id, Fixnum, :serial => true
18 property :login, String, :unique => true
19 property :email, String
20 property :crypted_password, String
21 property :salt, String
22 property :activation_code, String
23 property :activated_at, DateTime
24 property :remember_token_expires_at, DateTime
25 property :remember_token, String
26 property :created_at, DateTime
27 property :updated_at, DateTime
29 validates_length :login, :within => 3..40
30 validates_is_unique :login
31 validates_present :email
32 validates_format :email, :as => :email_address
33 validates_length :email, :within => 3..100
34 validates_is_unique :email
35 validates_present :password, :if => lambda { |r| r.password_required? }
36 validates_present :password_confirmation, :if => lambda { |r| r.password_required? }
37 validates_length :password, :within => 4..40, :if => lambda { |r| r.password_required? }
38 validates_is_confirmed :password#, :groups => :create
40 before :save, :encrypt_password
41 #before_class_method :create, :make_activation_code
42 #after_class_method :create, :send_signup_notification
45 @login = value.downcase unless value.nil?
48 EMAIL_FROM = "info@mysite.com"
49 SIGNUP_MAIL_SUBJECT = "Welcome to MYSITE. Please activate your account."
50 ACTIVATE_MAIL_SUBJECT = "Welcome to MYSITE"
52 # Activates the user in the database
55 self.activated_at = Time.now.utc
56 self.activation_code = nil
59 # send mail for activation
60 UserMailer.dispatch_and_deliver( :activation_notification,
61 { :from => User::EMAIL_FROM,
63 :subject => User::ACTIVATE_MAIL_SUBJECT },
69 #def send_signup_notification
70 # UserMailer.dispatch_and_deliver(
71 # :signup_notification,
72 # { :from => User::EMAIL_FROM,
74 # :subject => User::SIGNUP_MAIL_SUBJECT },