Module: Authlogic::Session::Cookies::InstanceMethods

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

Overview

The methods available for an Authlogic::Session::Base object that make up the cookie feature set.

Instance Method Summary collapse

Instance Method Details

#credentials=(value) ⇒ Object

Allows you to set the remember_me option when passing credentials.



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/authlogic/session/cookies.rb', line 89

def credentials=(value)
  super
  values = value.is_a?(Array) ? value : [value]
  case values.first
  when Hash
    self.remember_me = values.first.with_indifferent_access[:remember_me] if values.first.with_indifferent_access.key?(:remember_me)
  else
    r = values.find { |value| value.is_a?(TrueClass) || value.is_a?(FalseClass) }
    self.remember_me = r if !r.nil?
  end
end

#httponlyObject

If the cookie should be marked as httponly (not accessible via javascript)



157
158
159
160
# File 'lib/authlogic/session/cookies.rb', line 157

def httponly
  return @httponly if defined?(@httponly)
  @httponly = self.class.httponly
end

#httponly=(value) ⇒ Object

Accepts a boolean as to whether the cookie should be marked as httponly. If true, the cookie will not be accessible from javascript



164
165
166
# File 'lib/authlogic/session/cookies.rb', line 164

def httponly=(value)
  @httponly = value
end

#httponly?Boolean

See httponly

Returns:

  • (Boolean)


169
170
171
# File 'lib/authlogic/session/cookies.rb', line 169

def httponly?
  httponly == true || httponly == "true" || httponly == "1"
end

#remember_meObject

Is the cookie going to expire after the session is over, or will it stick around?



102
103
104
105
# File 'lib/authlogic/session/cookies.rb', line 102

def remember_me
  return @remember_me if defined?(@remember_me)
  @remember_me = self.class.remember_me
end

#remember_me=(value) ⇒ Object

Accepts a boolean as a flag to remember the session or not. Basically to expire the cookie at the end of the session or keep it for “remember_me_until”.



110
111
112
# File 'lib/authlogic/session/cookies.rb', line 110

def remember_me=(value)
  @remember_me = value
end

#remember_me?Boolean

See remember_me

Returns:

  • (Boolean)


115
116
117
# File 'lib/authlogic/session/cookies.rb', line 115

def remember_me?
  remember_me == true || remember_me == "true" || remember_me == "1"
end

#remember_me_expired?Boolean

Has the cookie expired due to current time being greater than remember_me_until.

Returns:

  • (Boolean)


134
135
136
137
# File 'lib/authlogic/session/cookies.rb', line 134

def remember_me_expired?
  return unless remember_me?
  (Time.parse(cookie_credentials[2]) < Time.now)
end

#remember_me_forObject

How long to remember the user if remember_me is true. This is based on the class level configuration: remember_me_for



121
122
123
124
# File 'lib/authlogic/session/cookies.rb', line 121

def remember_me_for
  return unless remember_me?
  self.class.remember_me_for
end

#remember_me_untilObject

When to expire the cookie. See remember_me_for configuration option to change this.



128
129
130
131
# File 'lib/authlogic/session/cookies.rb', line 128

def remember_me_until
  return unless remember_me?
  remember_me_for.from_now
end

#secureObject

If the cookie should be marked as secure (SSL only)



140
141
142
143
# File 'lib/authlogic/session/cookies.rb', line 140

def secure
  return @secure if defined?(@secure)
  @secure = self.class.secure
end

#secure=(value) ⇒ Object

Accepts a boolean as to whether the cookie should be marked as secure. If true the cookie will only ever be sent over an SSL connection.



147
148
149
# File 'lib/authlogic/session/cookies.rb', line 147

def secure=(value)
  @secure = value
end

#secure?Boolean

See secure

Returns:

  • (Boolean)


152
153
154
# File 'lib/authlogic/session/cookies.rb', line 152

def secure?
  secure == true || secure == "true" || secure == "1"
end

If the cookie should be signed



174
175
176
177
# File 'lib/authlogic/session/cookies.rb', line 174

def sign_cookie
  return @sign_cookie if defined?(@sign_cookie)
  @sign_cookie = self.class.sign_cookie
end

#sign_cookie=(value) ⇒ Object

Accepts a boolean as to whether the cookie should be signed. If true the cookie will be saved and verified using a signature.



181
182
183
# File 'lib/authlogic/session/cookies.rb', line 181

def sign_cookie=(value)
  @sign_cookie = value
end

#sign_cookie?Boolean

See sign_cookie

Returns:

  • (Boolean)


186
187
188
# File 'lib/authlogic/session/cookies.rb', line 186

def sign_cookie?
  sign_cookie == true || sign_cookie == "true" || sign_cookie == "1"
end