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, Integer, :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
43 #User.make_activation_code
47 #User.send_signup_notification
51 @login = value.downcase unless value.nil?
54 EMAIL_FROM = "info@mysite.com"
55 SIGNUP_MAIL_SUBJECT = "Welcome to MYSITE. Please activate your account."
56 ACTIVATE_MAIL_SUBJECT = "Welcome to MYSITE"
58 # Activates the user in the database
61 self.activated_at = Time.now.utc
62 self.activation_code = nil
65 # send mail for activation
66 UserMailer.dispatch_and_deliver( :activation_notification,
67 { :from => User::EMAIL_FROM,
69 :subject => User::ACTIVATE_MAIL_SUBJECT },
75 #def send_signup_notification
76 # UserMailer.dispatch_and_deliver(
77 # :signup_notification,
78 # { :from => User::EMAIL_FROM,
80 # :subject => User::SIGNUP_MAIL_SUBJECT },