authlogic 2.1.11 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of authlogic might be problematic. Click here for more details.
- data/Gemfile +9 -1
- data/Gemfile.lock +39 -15
- data/LICENSE +1 -1
- data/README.rdoc +19 -8
- data/Rakefile +19 -0
- data/VERSION.yml +4 -4
- data/authlogic.gemspec +214 -18
- data/lib/authlogic/acts_as_authentic/email.rb +12 -12
- data/lib/authlogic/acts_as_authentic/logged_in_status.rb +2 -2
- data/lib/authlogic/acts_as_authentic/login.rb +14 -14
- data/lib/authlogic/acts_as_authentic/password.rb +2 -2
- data/lib/authlogic/acts_as_authentic/perishable_token.rb +15 -15
- data/lib/authlogic/acts_as_authentic/persistence_token.rb +1 -1
- data/lib/authlogic/acts_as_authentic/session_maintenance.rb +2 -15
- data/lib/authlogic/authenticates_many/base.rb +3 -4
- data/lib/authlogic/controller_adapters/sinatra_adapter.rb +1 -1
- data/lib/authlogic/regex.rb +8 -9
- data/lib/authlogic/session/active_record_trickery.rb +9 -1
- data/lib/authlogic/session/callbacks.rb +1 -1
- data/lib/authlogic/session/cookies.rb +15 -15
- data/lib/authlogic/session/foundation.rb +8 -0
- data/lib/authlogic/session/validation.rb +2 -2
- data/lib/generators/authlogic/USAGE +8 -0
- data/lib/generators/authlogic/session_generator.rb +14 -0
- data/lib/generators/authlogic/templates/session.rb +2 -0
- data/test/acts_as_authentic_test/base_test.rb +1 -1
- data/test/acts_as_authentic_test/email_test.rb +26 -22
- data/test/acts_as_authentic_test/logged_in_status_test.rb +1 -1
- data/test/acts_as_authentic_test/login_test.rb +21 -21
- data/test/acts_as_authentic_test/magic_columns_test.rb +1 -1
- data/test/acts_as_authentic_test/password_test.rb +1 -1
- data/test/acts_as_authentic_test/perishable_token_test.rb +1 -1
- data/test/acts_as_authentic_test/persistence_token_test.rb +1 -1
- data/test/acts_as_authentic_test/restful_authentication_test.rb +1 -1
- data/test/acts_as_authentic_test/session_maintenance_test.rb +1 -1
- data/test/acts_as_authentic_test/single_access_test.rb +1 -1
- data/test/authenticates_many_test.rb +1 -1
- data/test/crypto_provider_test/aes256_test.rb +1 -1
- data/test/crypto_provider_test/bcrypt_test.rb +1 -1
- data/test/crypto_provider_test/sha1_test.rb +1 -1
- data/test/crypto_provider_test/sha256_test.rb +1 -1
- data/test/crypto_provider_test/sha512_test.rb +1 -1
- data/test/i18n_test.rb +1 -1
- data/test/random_test.rb +1 -1
- data/test/session_test/activation_test.rb +1 -1
- data/test/session_test/active_record_trickery_test.rb +16 -6
- data/test/session_test/brute_force_protection_test.rb +1 -1
- data/test/session_test/callbacks_test.rb +1 -1
- data/test/session_test/cookies_test.rb +43 -21
- data/test/session_test/existence_test.rb +1 -1
- data/test/session_test/http_auth_test.rb +1 -1
- data/test/session_test/id_test.rb +1 -1
- data/test/session_test/klass_test.rb +1 -1
- data/test/session_test/magic_columns_test.rb +1 -1
- data/test/session_test/magic_states_test.rb +1 -1
- data/test/session_test/params_test.rb +1 -1
- data/test/session_test/password_test.rb +1 -1
- data/test/session_test/perishability_test.rb +1 -1
- data/test/session_test/persistence_test.rb +1 -1
- data/test/session_test/scopes_test.rb +1 -1
- data/test/session_test/session_test.rb +1 -1
- data/test/session_test/timeout_test.rb +1 -1
- data/test/session_test/unauthorized_record_test.rb +1 -1
- data/test/session_test/validation_test.rb +1 -1
- data/test/test_helper.rb +3 -19
- metadata +59 -96
- checksums.yaml +0 -7
- data/.gitignore +0 -10
- data/CHANGELOG.rdoc +0 -345
@@ -32,8 +32,8 @@ module Authlogic
|
|
32
32
|
klass.class_eval do
|
33
33
|
include InstanceMethods
|
34
34
|
|
35
|
-
|
36
|
-
|
35
|
+
scope :logged_in, lambda { {:conditions => ["last_request_at > ?", logged_in_timeout.seconds.ago]} }
|
36
|
+
scope :logged_out, lambda { {:conditions => ["last_request_at is NULL or last_request_at <= ?", logged_in_timeout.seconds.ago]} }
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -8,7 +8,7 @@ module Authlogic
|
|
8
8
|
add_acts_as_authentic_module(Methods)
|
9
9
|
end
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
# Confguration for the login field.
|
13
13
|
module Config
|
14
14
|
# The name of the login field in the database.
|
@@ -19,7 +19,7 @@ module Authlogic
|
|
19
19
|
rw_config(:login_field, value, first_column_to_exist(nil, :login, :username))
|
20
20
|
end
|
21
21
|
alias_method :login_field=, :login_field
|
22
|
-
|
22
|
+
|
23
23
|
# Whether or not the validate the login field
|
24
24
|
#
|
25
25
|
# * <tt>Default:</tt> true
|
@@ -28,7 +28,7 @@ module Authlogic
|
|
28
28
|
rw_config(:validate_login_field, value, true)
|
29
29
|
end
|
30
30
|
alias_method :validate_login_field=, :validate_login_field
|
31
|
-
|
31
|
+
|
32
32
|
# A hash of options for the validates_length_of call for the login field. Allows you to change this however you want.
|
33
33
|
#
|
34
34
|
# <b>Keep in mind this is ruby. I wanted to keep this as flexible as possible, so you can completely replace the hash or
|
@@ -41,7 +41,7 @@ module Authlogic
|
|
41
41
|
rw_config(:validates_length_of_login_field_options, value, {:within => 3..100})
|
42
42
|
end
|
43
43
|
alias_method :validates_length_of_login_field_options=, :validates_length_of_login_field_options
|
44
|
-
|
44
|
+
|
45
45
|
# A convenience function to merge options into the validates_length_of_login_field_options. So intead of:
|
46
46
|
#
|
47
47
|
# self.validates_length_of_login_field_options = validates_length_of_login_field_options.merge(:my_option => my_value)
|
@@ -52,25 +52,25 @@ module Authlogic
|
|
52
52
|
def merge_validates_length_of_login_field_options(options = {})
|
53
53
|
self.validates_length_of_login_field_options = validates_length_of_login_field_options.merge(options)
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
# A hash of options for the validates_format_of call for the login field. Allows you to change this however you want.
|
57
57
|
#
|
58
58
|
# <b>Keep in mind this is ruby. I wanted to keep this as flexible as possible, so you can completely replace the hash or
|
59
59
|
# merge options into it. Checkout the convenience function merge_validates_format_of_login_field_options to merge
|
60
60
|
# options.</b>
|
61
61
|
#
|
62
|
-
# * <tt>Default:</tt> {:with => Authlogic::Regex.login, :message => I18n.t('error_messages.login_invalid', :default => "should use only letters, numbers, spaces, and .-_@ please.")}
|
62
|
+
# * <tt>Default:</tt> {:with => Authlogic::Regex.login, :message => lambda {I18n.t('error_messages.login_invalid', :default => "should use only letters, numbers, spaces, and .-_@ please.")}}
|
63
63
|
# * <tt>Accepts:</tt> Hash of options accepted by validates_format_of
|
64
64
|
def validates_format_of_login_field_options(value = nil)
|
65
65
|
rw_config(:validates_format_of_login_field_options, value, {:with => Authlogic::Regex.login, :message => I18n.t('error_messages.login_invalid', :default => "should use only letters, numbers, spaces, and .-_@ please.")})
|
66
66
|
end
|
67
67
|
alias_method :validates_format_of_login_field_options=, :validates_format_of_login_field_options
|
68
|
-
|
68
|
+
|
69
69
|
# See merge_validates_length_of_login_field_options. The same thing, except for validates_format_of_login_field_options
|
70
70
|
def merge_validates_format_of_login_field_options(options = {})
|
71
71
|
self.validates_format_of_login_field_options = validates_format_of_login_field_options.merge(options)
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
# A hash of options for the validates_uniqueness_of call for the login field. Allows you to change this however you want.
|
75
75
|
#
|
76
76
|
# <b>Keep in mind this is ruby. I wanted to keep this as flexible as possible, so you can completely replace the hash or
|
@@ -83,18 +83,18 @@ module Authlogic
|
|
83
83
|
rw_config(:validates_uniqueness_of_login_field_options, value, {:case_sensitive => false, :scope => validations_scope, :if => "#{login_field}_changed?".to_sym})
|
84
84
|
end
|
85
85
|
alias_method :validates_uniqueness_of_login_field_options=, :validates_uniqueness_of_login_field_options
|
86
|
-
|
86
|
+
|
87
87
|
# See merge_validates_length_of_login_field_options. The same thing, except for validates_uniqueness_of_login_field_options
|
88
88
|
def merge_validates_uniqueness_of_login_field_options(options = {})
|
89
89
|
self.validates_uniqueness_of_login_field_options = validates_uniqueness_of_login_field_options.merge(options)
|
90
90
|
end
|
91
|
-
|
91
|
+
|
92
92
|
# This method allows you to find a record with the given login. If you notice, with ActiveRecord you have the
|
93
93
|
# validates_uniqueness_of validation function. They give you a :case_sensitive option. I handle this in the same
|
94
94
|
# manner that they handle that. If you are using the login field and set false for the :case_sensitive option in
|
95
95
|
# validates_uniqueness_of_login_field_options this method will modify the query to look something like:
|
96
96
|
#
|
97
|
-
#
|
97
|
+
# where("LOWER(#{quoted_table_name}.#{login_field}) = ?", login.downcase).first
|
98
98
|
#
|
99
99
|
# If you don't specify this it calls the good old find_by_* method:
|
100
100
|
#
|
@@ -112,17 +112,17 @@ module Authlogic
|
|
112
112
|
find_with_case(email_field, login, validates_uniqueness_of_email_field_options[:case_sensitive] != false)
|
113
113
|
end
|
114
114
|
end
|
115
|
-
|
115
|
+
|
116
116
|
private
|
117
117
|
def find_with_case(field, value, sensitivity = true)
|
118
118
|
if sensitivity
|
119
119
|
send("find_by_#{field}", value)
|
120
120
|
else
|
121
|
-
|
121
|
+
where("LOWER(#{quoted_table_name}.#{field}) = ?", value.mb_chars.downcase).first
|
122
122
|
end
|
123
123
|
end
|
124
124
|
end
|
125
|
-
|
125
|
+
|
126
126
|
# All methods relating to the login field
|
127
127
|
module Methods
|
128
128
|
# Adds in various validations, modules, etc.
|
@@ -277,7 +277,7 @@ module Authlogic
|
|
277
277
|
# Resets the password to a random friendly token and then saves the record.
|
278
278
|
def reset_password!
|
279
279
|
reset_password
|
280
|
-
save_without_session_maintenance(false)
|
280
|
+
save_without_session_maintenance(:validate => false)
|
281
281
|
end
|
282
282
|
alias_method :randomize_password!, :reset_password!
|
283
283
|
|
@@ -314,7 +314,7 @@ module Authlogic
|
|
314
314
|
|
315
315
|
def transition_password(attempted_password)
|
316
316
|
self.password = attempted_password
|
317
|
-
save(false)
|
317
|
+
save(:validate => false)
|
318
318
|
end
|
319
319
|
|
320
320
|
def require_password?
|
@@ -11,7 +11,7 @@ module Authlogic
|
|
11
11
|
add_acts_as_authentic_module(Methods)
|
12
12
|
end
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
# Change how the perishable token works.
|
16
16
|
module Config
|
17
17
|
# When using the find_using_perishable_token method the token can expire. If the token is expired, no
|
@@ -23,7 +23,7 @@ module Authlogic
|
|
23
23
|
rw_config(:perishable_token_valid_for, (!value.nil? && value.to_i) || value, 10.minutes.to_i)
|
24
24
|
end
|
25
25
|
alias_method :perishable_token_valid_for=, :perishable_token_valid_for
|
26
|
-
|
26
|
+
|
27
27
|
# Authlogic tries to expire and change the perishable token as much as possible, without comprising
|
28
28
|
# it's purpose. This is for security reasons. If you want to manage it yourself, you can stop
|
29
29
|
# Authlogic from getting your in way by setting this to true.
|
@@ -35,21 +35,21 @@ module Authlogic
|
|
35
35
|
end
|
36
36
|
alias_method :disable_perishable_token_maintenance=, :disable_perishable_token_maintenance
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
# All methods relating to the perishable token.
|
40
40
|
module Methods
|
41
41
|
def self.included(klass)
|
42
42
|
return if !klass.column_names.include?("perishable_token")
|
43
|
-
|
43
|
+
|
44
44
|
klass.class_eval do
|
45
45
|
extend ClassMethods
|
46
46
|
include InstanceMethods
|
47
|
-
|
47
|
+
|
48
48
|
validates_uniqueness_of :perishable_token, :if => :perishable_token_changed?
|
49
49
|
before_save :reset_perishable_token, :unless => :disable_perishable_token_maintenance?
|
50
50
|
end
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
# Class level methods for the perishable token
|
54
54
|
module ClassMethods
|
55
55
|
# Use this methdo to find a record with a perishable token. This method does 2 things for you:
|
@@ -63,37 +63,37 @@ module Authlogic
|
|
63
63
|
def find_using_perishable_token(token, age = self.perishable_token_valid_for)
|
64
64
|
return if token.blank?
|
65
65
|
age = age.to_i
|
66
|
-
|
66
|
+
|
67
67
|
conditions_sql = "perishable_token = ?"
|
68
|
-
conditions_subs = [token
|
69
|
-
|
68
|
+
conditions_subs = [token]
|
69
|
+
|
70
70
|
if column_names.include?("updated_at") && age > 0
|
71
71
|
conditions_sql += " and updated_at > ?"
|
72
72
|
conditions_subs << age.seconds.ago
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
find(:first, :conditions => [conditions_sql, *conditions_subs])
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
# This method will raise ActiveRecord::NotFound if no record is found.
|
79
79
|
def find_using_perishable_token!(token, age = perishable_token_valid_for)
|
80
80
|
find_using_perishable_token(token, age) || raise(ActiveRecord::RecordNotFound)
|
81
81
|
end
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
# Instance level methods for the perishable token.
|
85
85
|
module InstanceMethods
|
86
86
|
# Resets the perishable token to a random friendly token.
|
87
87
|
def reset_perishable_token
|
88
88
|
self.perishable_token = Random.friendly_token
|
89
89
|
end
|
90
|
-
|
90
|
+
|
91
91
|
# Same as reset_perishable_token, but then saves the record afterwards.
|
92
92
|
def reset_perishable_token!
|
93
93
|
reset_perishable_token
|
94
|
-
save_without_session_maintenance(false)
|
94
|
+
save_without_session_maintenance(:validate => false)
|
95
95
|
end
|
96
|
-
|
96
|
+
|
97
97
|
# A convenience method based on the disable_perishable_token_maintenance configuration option.
|
98
98
|
def disable_perishable_token_maintenance?
|
99
99
|
self.class.disable_perishable_token_maintenance == true
|
@@ -53,7 +53,7 @@ module Authlogic
|
|
53
53
|
# Same as reset_persistence_token, but then saves the record.
|
54
54
|
def reset_persistence_token!
|
55
55
|
reset_persistence_token
|
56
|
-
save_without_session_maintenance(false)
|
56
|
+
save_without_session_maintenance(:validate => false)
|
57
57
|
end
|
58
58
|
alias_method :forget!, :reset_persistence_token!
|
59
59
|
|
@@ -48,25 +48,12 @@ module Authlogic
|
|
48
48
|
end
|
49
49
|
alias_method :session_ids=, :session_ids
|
50
50
|
|
51
|
-
# In some cases, you can use a different namespace for the session class. If you want to use a model
|
52
|
-
# to control access in a namespace and edit it in another namespace, you can define the session class
|
53
|
-
# namespace here so authlogic knows where to find it without problems.
|
54
|
-
#
|
55
|
-
# * <tt>Default:</tt> nil
|
56
|
-
# * <tt>Accepts:</tt> Strings
|
57
|
-
def session_class_namespace(value = nil)
|
58
|
-
rw_config(:session_class_namespace, value, nil)
|
59
|
-
end
|
60
|
-
alias_method :session_class_namespace=, :session_class_namespace
|
61
|
-
|
62
51
|
# The name of the associated session class. This is inferred by the name of the model.
|
63
52
|
#
|
64
53
|
# * <tt>Default:</tt> "#{klass.name}Session".constantize
|
65
54
|
# * <tt>Accepts:</tt> Class
|
66
55
|
def session_class(value = nil)
|
67
|
-
|
68
|
-
|
69
|
-
const = ((namespace.nil? ? "" : "#{namespace}::") + "#{base_class.name}Session").constantize rescue nil
|
56
|
+
const = "#{base_class.name}Session".constantize rescue nil
|
70
57
|
rw_config(:session_class, value, const)
|
71
58
|
end
|
72
59
|
alias_method :session_class=, :session_class
|
@@ -149,4 +136,4 @@ module Authlogic
|
|
149
136
|
end
|
150
137
|
end
|
151
138
|
end
|
152
|
-
end
|
139
|
+
end
|
@@ -23,7 +23,7 @@ module Authlogic
|
|
23
23
|
#
|
24
24
|
# * <tt>session_class:</tt> default: "#{name}Session",
|
25
25
|
# This is the related session class.
|
26
|
-
#
|
26
|
+
#
|
27
27
|
# * <tt>relationship_name:</tt> default: options[:session_class].klass_name.underscore.pluralize,
|
28
28
|
# This is the name of the relationship you want to use to scope everything. For example an Account has many Users. There should be a relationship
|
29
29
|
# called :users that you defined with a has_many. The reason we use the relationship is so you don't have to repeat yourself. The relatonship
|
@@ -42,14 +42,13 @@ module Authlogic
|
|
42
42
|
options[:relationship_name] ||= options[:session_class].klass_name.underscore.pluralize
|
43
43
|
class_eval <<-"end_eval", __FILE__, __LINE__
|
44
44
|
def #{name}
|
45
|
-
find_options = #{options[:find_options].inspect} || #{options[:relationship_name]}.
|
46
|
-
find_options.delete_if { |key, value| ![:conditions, :include, :joins].include?(key.to_sym) || value.nil? }
|
45
|
+
find_options = #{options[:find_options].inspect} || #{options[:relationship_name]}.scoped
|
47
46
|
@#{name} ||= Authlogic::AuthenticatesMany::Association.new(#{options[:session_class]}, find_options, #{options[:scope_cookies] ? "self.class.model_name.underscore + '_' + self.send(self.class.primary_key).to_s" : "nil"})
|
48
47
|
end
|
49
48
|
end_eval
|
50
49
|
end
|
51
50
|
end
|
52
|
-
|
51
|
+
|
53
52
|
::ActiveRecord::Base.extend(Base) if defined?(::ActiveRecord)
|
54
53
|
end
|
55
54
|
end
|
data/lib/authlogic/regex.rb
CHANGED
@@ -9,18 +9,17 @@ module Authlogic
|
|
9
9
|
# by reading this website: http://www.regular-expressions.info/email.html, which is an excellent resource
|
10
10
|
# for regular expressions.
|
11
11
|
def self.email
|
12
|
-
@email_regex
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
12
|
+
return @email_regex if @email_regex
|
13
|
+
email_name_regex = '[A-Z0-9_\.%\+\-\']+'
|
14
|
+
domain_head_regex = '(?:[A-Z0-9\-]+\.)+'
|
15
|
+
domain_tld_regex = '(?:[A-Z]{2,4}|museum|travel)'
|
16
|
+
@email_regex = /^#{email_name_regex}@#{domain_head_regex}#{domain_tld_regex}$/i
|
18
17
|
end
|
19
|
-
|
18
|
+
|
20
19
|
# A simple regular expression that only allows for letters, numbers, spaces, and .-_@. Just a standard login / username
|
21
20
|
# regular expression.
|
22
21
|
def self.login
|
23
|
-
/\A\w[\w\.+\-_@ ]
|
22
|
+
/\A\w[\w\.+\-_@ ]+$/
|
24
23
|
end
|
25
24
|
end
|
26
|
-
end
|
25
|
+
end
|
@@ -40,12 +40,20 @@ module Authlogic
|
|
40
40
|
|
41
41
|
# For rails >= 3.0
|
42
42
|
def model_name
|
43
|
-
if defined?(::ActiveModel
|
43
|
+
if defined?(::ActiveModel)
|
44
44
|
::ActiveModel::Name.new(self)
|
45
45
|
else
|
46
46
|
::ActiveSupport::ModelName.new(self.to_s)
|
47
47
|
end
|
48
48
|
end
|
49
|
+
|
50
|
+
def i18n_scope
|
51
|
+
I18n.scope
|
52
|
+
end
|
53
|
+
|
54
|
+
def lookup_ancestors
|
55
|
+
ancestors.select { |x| x.respond_to?(:model_name) }
|
56
|
+
end
|
49
57
|
end
|
50
58
|
|
51
59
|
module InstanceMethods
|
@@ -92,7 +92,7 @@ module Authlogic
|
|
92
92
|
|
93
93
|
def save_record(alternate_record = nil)
|
94
94
|
r = alternate_record || record
|
95
|
-
r.save_without_session_maintenance(false) if r && r.changed? && !r.readonly?
|
95
|
+
r.save_without_session_maintenance(:validate => false) if r && r.changed? && !r.readonly?
|
96
96
|
end
|
97
97
|
end
|
98
98
|
end
|
@@ -11,7 +11,7 @@ module Authlogic
|
|
11
11
|
after_destroy :destroy_cookie
|
12
12
|
end
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
# Configuration for the cookie feature set.
|
16
16
|
module Config
|
17
17
|
# The name of the cookie or the key in the cookies hash. Be sure and use a unique name. If you have multiple sessions and they use the same cookie it will cause problems.
|
@@ -19,7 +19,7 @@ module Authlogic
|
|
19
19
|
#
|
20
20
|
# session = UserSession.new
|
21
21
|
# session.cookie_key => "user_credentials"
|
22
|
-
#
|
22
|
+
#
|
23
23
|
# session = UserSession.new(:super_high_secret)
|
24
24
|
# session.cookie_key => "super_high_secret_user_credentials"
|
25
25
|
#
|
@@ -29,7 +29,7 @@ module Authlogic
|
|
29
29
|
rw_config(:cookie_key, value, "#{guessed_klass_name.underscore}_credentials")
|
30
30
|
end
|
31
31
|
alias_method :cookie_key=, :cookie_key
|
32
|
-
|
32
|
+
|
33
33
|
# If sessions should be remembered by default or not.
|
34
34
|
#
|
35
35
|
# * <tt>Default:</tt> false
|
@@ -38,7 +38,7 @@ module Authlogic
|
|
38
38
|
rw_config(:remember_me, value, false)
|
39
39
|
end
|
40
40
|
alias_method :remember_me=, :remember_me
|
41
|
-
|
41
|
+
|
42
42
|
# The length of time until the cookie expires.
|
43
43
|
#
|
44
44
|
# * <tt>Default:</tt> 3.months
|
@@ -66,7 +66,7 @@ module Authlogic
|
|
66
66
|
end
|
67
67
|
alias_method :httponly=, :httponly
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
# The methods available for an Authlogic::Session::Base object that make up the cookie feature set.
|
71
71
|
module InstanceMethods
|
72
72
|
# Allows you to set the remember_me option when passing credentials.
|
@@ -81,29 +81,29 @@ module Authlogic
|
|
81
81
|
self.remember_me = r if !r.nil?
|
82
82
|
end
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
# Is the cookie going to expire after the session is over, or will it stick around?
|
86
86
|
def remember_me
|
87
87
|
return @remember_me if defined?(@remember_me)
|
88
88
|
@remember_me = self.class.remember_me
|
89
89
|
end
|
90
|
-
|
90
|
+
|
91
91
|
# 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".
|
92
92
|
def remember_me=(value)
|
93
93
|
@remember_me = value
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
96
|
# See remember_me
|
97
97
|
def remember_me?
|
98
98
|
remember_me == true || remember_me == "true" || remember_me == "1"
|
99
99
|
end
|
100
|
-
|
100
|
+
|
101
101
|
# How long to remember the user if remember_me is true. This is based on the class level configuration: remember_me_for
|
102
102
|
def remember_me_for
|
103
103
|
return unless remember_me?
|
104
104
|
self.class.remember_me_for
|
105
105
|
end
|
106
|
-
|
106
|
+
|
107
107
|
# When to expire the cookie. See remember_me_for configuration option to change this.
|
108
108
|
def remember_me_until
|
109
109
|
return unless remember_me?
|
@@ -146,15 +146,15 @@ module Authlogic
|
|
146
146
|
def cookie_key
|
147
147
|
build_key(self.class.cookie_key)
|
148
148
|
end
|
149
|
-
|
149
|
+
|
150
150
|
def cookie_credentials
|
151
151
|
controller.cookies[cookie_key] && controller.cookies[cookie_key].split("::")
|
152
152
|
end
|
153
|
-
|
153
|
+
|
154
154
|
# Tries to validate the session from information in the cookie
|
155
155
|
def persist_by_cookie
|
156
156
|
persistence_token, record_id = cookie_credentials
|
157
|
-
if !persistence_token.
|
157
|
+
if !persistence_token.nil?
|
158
158
|
record = record_id.nil? ? search_for_record("find_by_persistence_token", persistence_token) : search_for_record("find_by_#{klass.primary_key}", record_id)
|
159
159
|
self.unauthorized_record = record if record && record.persistence_token == persistence_token
|
160
160
|
valid?
|
@@ -162,7 +162,7 @@ module Authlogic
|
|
162
162
|
false
|
163
163
|
end
|
164
164
|
end
|
165
|
-
|
165
|
+
|
166
166
|
def save_cookie
|
167
167
|
controller.cookies[cookie_key] = {
|
168
168
|
:value => "#{record.persistence_token}::#{record.send(record.class.primary_key)}",
|
@@ -172,7 +172,7 @@ module Authlogic
|
|
172
172
|
:domain => controller.cookie_domain
|
173
173
|
}
|
174
174
|
end
|
175
|
-
|
175
|
+
|
176
176
|
def destroy_cookie
|
177
177
|
controller.cookies.delete cookie_key, :domain => controller.cookie_domain
|
178
178
|
end
|