Module: ActiveRecord::Acts::ActsAsCentralAuthenticationUser::ClassMethods

Defined in:
lib/central_authentication/acts_as_central_authentication_user.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_by_persistence_token(persistence_token) ⇒ Object



37
38
39
# File 'lib/central_authentication/acts_as_central_authentication_user.rb', line 37

def self.find_by_persistence_token(persistence_token)
  CentralAuthentication::User.find_by_persistence_token(persistence_token)
end

Instance Method Details

#acts_as_central_authentication_userObject



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

  #Here we set the authlogic options:
  # 1. Email will be used as the login field
  # 2. It doesn't validate the password field against a database field
  # 3. It doesn't validate the login field. Authlogic automatically validates the email field.
  acts_as_authentic do |config|
    config. = :email
    config.validate_password_field = false
    config. = 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