Module: Authlogic::Session::Password::InstanceMethods

Defined in:
lib/authlogic/session/password.rb

Overview

Password related instance methods

Instance Method Summary collapse

Instance Method Details

#credentialsObject



101
102
103
104
105
106
107
108
109
110
# File 'lib/authlogic/session/password.rb', line 101

def credentials
  if authenticating_with_password?
    details = {}
    details[.to_sym] = send()
    details[password_field.to_sym] = "<protected>"
    details
  else
    super
  end
end

#credentials=(value) ⇒ Object



112
113
114
115
116
117
118
119
120
121
# File 'lib/authlogic/session/password.rb', line 112

def credentials=(value)
  super
  values = value.is_a?(Array) ? value : [value]
  if values.first.is_a?(Hash)
    values.first.with_indifferent_access.slice(, password_field).each do |field, value|
      next if value.blank?
      send("#{field}=", value)
    end
  end
end

#initialize(*args) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/authlogic/session/password.rb', line 75

def initialize(*args)
  if !self.class.configured_password_methods
    if 
      self.class.send(:attr_writer, ) if !respond_to?("#{}=")
      self.class.send(:attr_reader, ) if !respond_to?()
    end
    
    if password_field
      self.class.send(:attr_writer, password_field) if !respond_to?("#{password_field}=")
      self.class.send(:define_method, password_field) {} if !respond_to?(password_field)

      self.class.class_eval <<-"end_eval", __FILE__, __LINE__
        private
          # The password should not be accessible publicly. This way forms using form_for don't fill the password with the attempted password. The prevent this we just create this method that is private.
          def protected_#{password_field}
            @#{password_field}
          end
      end_eval
    end

    self.class.configured_password_methods = true
  end
  
  super
end