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 DataMapper::Validate
14 include AuthenticatedSystem::Model
16 attr_accessor :password, :password_confirmation
18 property :id, Fixnum, :serial => true
19 property :login, String, :unique => true
20 property :email, String
21 property :crypted_password, String
22 property :salt, String
23 property :activation_code, String
24 property :activated_at, DateTime
25 property :remember_token_expires_at, DateTime
26 property :remember_token, String
27 property :created_at, DateTime
28 property :updated_at, DateTime
30 validates_length_of :login, :within => 3..40
31 validates_uniqueness_of :login
32 validates_presence_of :email
33 validates_format_of :email, :as => :email_address
34 validates_length_of :email, :within => 3..100
35 validates_uniqueness_of :email
36 validates_presence_of :password, :if => lambda { |r| r.password_required? }
37 validates_presence_of :password_confirmation, :if => lambda { |r| r.password_required? }
38 validates_length_of :password, :within => 4..40, :if => lambda { |r| r.password_required? }
39 validates_confirmation_of :password#, :groups => :create
41 before :save, :encrypt_password
42 #before_class_method :create, :make_activation_code
43 #after_class_method :create, :send_signup_notification
46 @login = value.downcase unless value.nil?
49 EMAIL_FROM = "info@mysite.com"
50 SIGNUP_MAIL_SUBJECT = "Welcome to MYSITE. Please activate your account."
51 ACTIVATE_MAIL_SUBJECT = "Welcome to MYSITE"
53 # Activates the user in the database
56 self.activated_at = Time.now.utc
57 self.activation_code = nil
60 # send mail for activation
61 UserMailer.dispatch_and_deliver( :activation_notification,
62 { :from => User::EMAIL_FROM,
64 :subject => User::ACTIVATE_MAIL_SUBJECT },
70 #def send_signup_notification
71 # UserMailer.dispatch_and_deliver(
72 # :signup_notification,
73 # { :from => User::EMAIL_FROM,
75 # :subject => User::SIGNUP_MAIL_SUBJECT },