9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/central_authentication/acts_as_central_authentication_user.rb', line 9
def acts_as_central_authentication_user
include InstanceMethods
belongs_to :central_authentication_user, :foreign_key => 'central_auth_user_id', :class_name => 'CentralAuthentication::User'
attr_accessor :password_confirmation, :password
acts_as_authentic do |config|
config.login_field = :email
config.validate_password_field = false
config.validate_login_field = false
end
validates_presence_of :password, :if => Proc.new {|user| user.new_record? && user.central_auth_user_id.nil?}
validates_presence_of :password_confirmation, :if => Proc.new {|user| user.new_record? && user.central_auth_user_id.nil?}
validates_format_of :password, :with => /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s).{9,15}$/,
:message => 'must be between 9 and 15 characters long, contain at least one uppercase and one lowercase letter as well as at least one numerical character.',
:if => Proc.new {|user| (user.password.present? || user.password_confirmation.present?)}
validates_format_of :password_confirmation, :with => /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s).{9,15}$/,
:message => 'must be between 9 and 15 characters long, contain at least one uppercase and one lowercase letter as well as at least one numerical character.',
:if => Proc.new {|user| (user.password.present? || user.password_confirmation.present?)}
validates_confirmation_of :password
before_validation :create_or_set_cauth_user
def self.find_by_persistence_token(persistence_token)
CentralAuthentication::User.find_by_persistence_token(persistence_token)
end
end
|