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
-
#credentials=(value) ⇒ Object
Allows you to set the remember_me option when passing credentials.
-
#encrypt_cookie ⇒ Object
If the cookie should be encrypted.
-
#encrypt_cookie=(value) ⇒ Object
Accepts a boolean as to whether the cookie should be encrypted.
-
#encrypt_cookie? ⇒ Boolean
See encrypt_cookie.
-
#httponly ⇒ Object
If the cookie should be marked as httponly (not accessible via javascript).
-
#httponly=(value) ⇒ Object
Accepts a boolean as to whether the cookie should be marked as httponly.
-
#httponly? ⇒ Boolean
See httponly.
-
#remember_me ⇒ Object
Is the cookie going to expire after the session is over, or will it stick around?.
-
#remember_me=(value) ⇒ Object
Accepts a boolean as a flag to remember the session or not.
-
#remember_me? ⇒ Boolean
See remember_me.
-
#remember_me_expired? ⇒ Boolean
Has the cookie expired due to current time being greater than remember_me_until.
-
#remember_me_for ⇒ Object
How long to remember the user if remember_me is true.
-
#remember_me_until ⇒ Object
When to expire the cookie.
-
#same_site ⇒ Object
If the cookie should be marked as SameSite with ‘Lax’ or ‘Strict’ flag.
-
#same_site=(value) ⇒ Object
Accepts nil, ‘Lax’ or ‘Strict’ as possible flags.
-
#secure ⇒ Object
If the cookie should be marked as secure (SSL only).
-
#secure=(value) ⇒ Object
Accepts a boolean as to whether the cookie should be marked as secure.
-
#secure? ⇒ Boolean
See secure.
-
#sign_cookie ⇒ Object
If the cookie should be signed.
-
#sign_cookie=(value) ⇒ Object
Accepts a boolean as to whether the cookie should be signed.
-
#sign_cookie? ⇒ Boolean
See sign_cookie.
Instance Method Details
#credentials=(value) ⇒ Object
Allows you to set the remember_me option when passing credentials.
119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/authlogic/session/cookies.rb', line 119 def credentials=(value) super values = value.is_a?(Array) ? value : [value] case values.first when Hash if values.first.with_indifferent_access.key?(:remember_me) self.remember_me = values.first.with_indifferent_access[:remember_me] end else r = values.find { |val| val.is_a?(TrueClass) || val.is_a?(FalseClass) } self.remember_me = r unless r.nil? end end |
#encrypt_cookie ⇒ Object
If the cookie should be encrypted
238 239 240 241 |
# File 'lib/authlogic/session/cookies.rb', line 238 def return if defined?() = self.class. end |
#encrypt_cookie=(value) ⇒ Object
Accepts a boolean as to whether the cookie should be encrypted. If true the cookie will be saved in an encrypted state.
245 246 247 |
# File 'lib/authlogic/session/cookies.rb', line 245 def (value) = value end |
#encrypt_cookie? ⇒ Boolean
See encrypt_cookie
250 251 252 |
# File 'lib/authlogic/session/cookies.rb', line 250 def == true || == "true" || == "1" end |
#httponly ⇒ Object
If the cookie should be marked as httponly (not accessible via javascript)
189 190 191 192 |
# File 'lib/authlogic/session/cookies.rb', line 189 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
196 197 198 |
# File 'lib/authlogic/session/cookies.rb', line 196 def httponly=(value) @httponly = value end |
#httponly? ⇒ Boolean
See httponly
201 202 203 |
# File 'lib/authlogic/session/cookies.rb', line 201 def httponly? httponly == true || httponly == "true" || httponly == "1" end |
#remember_me ⇒ Object
Is the cookie going to expire after the session is over, or will it stick around?
134 135 136 137 |
# File 'lib/authlogic/session/cookies.rb', line 134 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”.
142 143 144 |
# File 'lib/authlogic/session/cookies.rb', line 142 def remember_me=(value) @remember_me = value end |
#remember_me? ⇒ Boolean
See remember_me
147 148 149 |
# File 'lib/authlogic/session/cookies.rb', line 147 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.
166 167 168 169 |
# File 'lib/authlogic/session/cookies.rb', line 166 def remember_me_expired? return unless remember_me? (Time.parse([2]) < Time.now) end |
#remember_me_for ⇒ Object
How long to remember the user if remember_me is true. This is based on the class level configuration: remember_me_for
153 154 155 156 |
# File 'lib/authlogic/session/cookies.rb', line 153 def remember_me_for return unless remember_me? self.class.remember_me_for end |
#remember_me_until ⇒ Object
When to expire the cookie. See remember_me_for configuration option to change this.
160 161 162 163 |
# File 'lib/authlogic/session/cookies.rb', line 160 def remember_me_until return unless remember_me? remember_me_for.from_now end |
#same_site ⇒ Object
If the cookie should be marked as SameSite with ‘Lax’ or ‘Strict’ flag.
206 207 208 209 |
# File 'lib/authlogic/session/cookies.rb', line 206 def same_site return @same_site if defined?(@same_site) @same_site = self.class.same_site(nil) end |
#same_site=(value) ⇒ Object
Accepts nil, ‘Lax’ or ‘Strict’ as possible flags.
212 213 214 215 216 217 218 |
# File 'lib/authlogic/session/cookies.rb', line 212 def same_site=(value) unless VALID_SAME_SITE_VALUES.include?(value) msg = "Invalid same_site value: #{value}. Valid: #{VALID_SAME_SITE_VALUES.inspect}" raise ArgumentError.new(msg) end @same_site = value end |
#secure ⇒ Object
If the cookie should be marked as secure (SSL only)
172 173 174 175 |
# File 'lib/authlogic/session/cookies.rb', line 172 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.
179 180 181 |
# File 'lib/authlogic/session/cookies.rb', line 179 def secure=(value) @secure = value end |
#secure? ⇒ Boolean
See secure
184 185 186 |
# File 'lib/authlogic/session/cookies.rb', line 184 def secure? secure == true || secure == "true" || secure == "1" end |
#sign_cookie ⇒ Object
If the cookie should be signed
221 222 223 224 |
# File 'lib/authlogic/session/cookies.rb', line 221 def return if defined?() = self.class. 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.
228 229 230 |
# File 'lib/authlogic/session/cookies.rb', line 228 def (value) = value end |
#sign_cookie? ⇒ Boolean
See sign_cookie
233 234 235 |
# File 'lib/authlogic/session/cookies.rb', line 233 def == true || == "true" || == "1" end |