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



93
94
95
96
97
98
99
100
101
102
# File 'lib/authlogic/session/password.rb', line 93

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



104
105
106
107
108
109
110
111
112
113
# File 'lib/authlogic/session/password.rb', line 104

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



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/authlogic/session/password.rb', line 72

def initialize(*args)
  if !self.class.configured_password_methods
    self.class.send(:attr_writer, ) if !respond_to?("#{}=")
    self.class.send(:attr_reader, ) if !respond_to?()
    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

    self.class.configured_password_methods = true
  end
  
  super
end