authlogic 3.8.0 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/authlogic/acts_as_authentic/base.rb +33 -36
- data/lib/authlogic/acts_as_authentic/email.rb +8 -141
- data/lib/authlogic/acts_as_authentic/logged_in_status.rb +17 -10
- data/lib/authlogic/acts_as_authentic/login.rb +14 -165
- data/lib/authlogic/acts_as_authentic/magic_columns.rb +13 -10
- data/lib/authlogic/acts_as_authentic/password.rb +186 -254
- data/lib/authlogic/acts_as_authentic/perishable_token.rb +30 -22
- data/lib/authlogic/acts_as_authentic/persistence_token.rb +19 -18
- data/lib/authlogic/acts_as_authentic/queries/case_sensitivity.rb +53 -0
- data/lib/authlogic/acts_as_authentic/queries/find_with_case.rb +83 -0
- data/lib/authlogic/acts_as_authentic/session_maintenance.rb +94 -62
- data/lib/authlogic/acts_as_authentic/single_access_token.rb +28 -14
- data/lib/authlogic/config.rb +29 -10
- data/lib/authlogic/controller_adapters/abstract_adapter.rb +43 -13
- data/lib/authlogic/controller_adapters/rack_adapter.rb +11 -5
- data/lib/authlogic/controller_adapters/rails_adapter.rb +11 -29
- data/lib/authlogic/controller_adapters/sinatra_adapter.rb +8 -2
- data/lib/authlogic/cookie_credentials.rb +63 -0
- data/lib/authlogic/crypto_providers/bcrypt.rb +24 -18
- data/lib/authlogic/crypto_providers/md5/v2.rb +35 -0
- data/lib/authlogic/crypto_providers/md5.rb +8 -6
- data/lib/authlogic/crypto_providers/scrypt.rb +24 -17
- data/lib/authlogic/crypto_providers/sha1/v2.rb +41 -0
- data/lib/authlogic/crypto_providers/sha1.rb +12 -5
- data/lib/authlogic/crypto_providers/sha256/v2.rb +58 -0
- data/lib/authlogic/crypto_providers/sha256.rb +18 -9
- data/lib/authlogic/crypto_providers/sha512/v2.rb +39 -0
- data/lib/authlogic/crypto_providers/sha512.rb +9 -26
- data/lib/authlogic/crypto_providers.rb +77 -1
- data/lib/authlogic/errors.rb +35 -0
- data/lib/authlogic/i18n/translator.rb +4 -1
- data/lib/authlogic/i18n.rb +29 -20
- data/lib/authlogic/random.rb +12 -28
- data/lib/authlogic/session/base.rb +2087 -33
- data/lib/authlogic/session/magic_column/assigns_last_request_at.rb +46 -0
- data/lib/authlogic/test_case/mock_controller.rb +7 -4
- data/lib/authlogic/test_case/mock_cookie_jar.rb +19 -3
- data/lib/authlogic/test_case/mock_logger.rb +2 -0
- data/lib/authlogic/test_case/mock_request.rb +8 -3
- data/lib/authlogic/test_case/rails_request_adapter.rb +5 -2
- data/lib/authlogic/test_case.rb +74 -2
- data/lib/authlogic/version.rb +22 -0
- data/lib/authlogic.rb +33 -54
- metadata +208 -234
- data/.github/ISSUE_TEMPLATE.md +0 -13
- data/.gitignore +0 -14
- data/.rubocop.yml +0 -33
- data/.rubocop_todo.yml +0 -391
- data/.travis.yml +0 -48
- data/CHANGELOG.md +0 -5
- data/CONTRIBUTING.md +0 -60
- data/Gemfile +0 -5
- data/LICENSE +0 -20
- data/README.md +0 -294
- data/Rakefile +0 -21
- data/authlogic.gemspec +0 -27
- data/lib/authlogic/acts_as_authentic/restful_authentication.rb +0 -70
- data/lib/authlogic/acts_as_authentic/validations_scope.rb +0 -32
- data/lib/authlogic/authenticates_many/association.rb +0 -50
- data/lib/authlogic/authenticates_many/base.rb +0 -65
- data/lib/authlogic/crypto_providers/aes256.rb +0 -66
- data/lib/authlogic/crypto_providers/wordpress.rb +0 -43
- data/lib/authlogic/regex.rb +0 -48
- data/lib/authlogic/session/activation.rb +0 -70
- data/lib/authlogic/session/active_record_trickery.rb +0 -61
- data/lib/authlogic/session/brute_force_protection.rb +0 -120
- data/lib/authlogic/session/callbacks.rb +0 -105
- data/lib/authlogic/session/cookies.rb +0 -244
- data/lib/authlogic/session/existence.rb +0 -93
- data/lib/authlogic/session/foundation.rb +0 -55
- data/lib/authlogic/session/http_auth.rb +0 -100
- data/lib/authlogic/session/id.rb +0 -48
- data/lib/authlogic/session/klass.rb +0 -70
- data/lib/authlogic/session/magic_columns.rb +0 -116
- data/lib/authlogic/session/magic_states.rb +0 -76
- data/lib/authlogic/session/params.rb +0 -116
- data/lib/authlogic/session/password.rb +0 -308
- data/lib/authlogic/session/perishable_token.rb +0 -23
- data/lib/authlogic/session/persistence.rb +0 -71
- data/lib/authlogic/session/priority_record.rb +0 -35
- data/lib/authlogic/session/scopes.rb +0 -119
- data/lib/authlogic/session/session.rb +0 -67
- data/lib/authlogic/session/timeout.rb +0 -103
- data/lib/authlogic/session/unauthorized_record.rb +0 -51
- data/lib/authlogic/session/validation.rb +0 -93
- data/test/acts_as_authentic_test/base_test.rb +0 -25
- data/test/acts_as_authentic_test/email_test.rb +0 -240
- data/test/acts_as_authentic_test/logged_in_status_test.rb +0 -62
- data/test/acts_as_authentic_test/login_test.rb +0 -156
- data/test/acts_as_authentic_test/magic_columns_test.rb +0 -27
- data/test/acts_as_authentic_test/password_test.rb +0 -249
- data/test/acts_as_authentic_test/perishable_token_test.rb +0 -90
- data/test/acts_as_authentic_test/persistence_token_test.rb +0 -56
- data/test/acts_as_authentic_test/restful_authentication_test.rb +0 -37
- data/test/acts_as_authentic_test/session_maintenance_test.rb +0 -96
- data/test/acts_as_authentic_test/single_access_test.rb +0 -44
- data/test/authenticates_many_test.rb +0 -31
- data/test/config_test.rb +0 -36
- data/test/crypto_provider_test/aes256_test.rb +0 -14
- data/test/crypto_provider_test/bcrypt_test.rb +0 -14
- data/test/crypto_provider_test/scrypt_test.rb +0 -14
- data/test/crypto_provider_test/sha1_test.rb +0 -23
- data/test/crypto_provider_test/sha256_test.rb +0 -14
- data/test/crypto_provider_test/sha512_test.rb +0 -14
- data/test/fixtures/companies.yml +0 -5
- data/test/fixtures/employees.yml +0 -17
- data/test/fixtures/projects.yml +0 -3
- data/test/fixtures/users.yml +0 -41
- data/test/gemfiles/Gemfile.rails-3.2.x +0 -7
- data/test/gemfiles/Gemfile.rails-4.0.x +0 -7
- data/test/gemfiles/Gemfile.rails-4.1.x +0 -7
- data/test/gemfiles/Gemfile.rails-4.2.x +0 -7
- data/test/gemfiles/Gemfile.rails-5.0.x +0 -6
- data/test/gemfiles/Gemfile.rails-5.1.x +0 -6
- data/test/gemfiles/Gemfile.rails-5.2.x +0 -6
- data/test/i18n/lol.yml +0 -4
- data/test/i18n_test.rb +0 -33
- data/test/libs/affiliate.rb +0 -7
- data/test/libs/company.rb +0 -6
- data/test/libs/employee.rb +0 -7
- data/test/libs/employee_session.rb +0 -2
- data/test/libs/ldaper.rb +0 -3
- data/test/libs/project.rb +0 -3
- data/test/libs/user.rb +0 -7
- data/test/libs/user_session.rb +0 -25
- data/test/random_test.rb +0 -43
- data/test/session_test/activation_test.rb +0 -43
- data/test/session_test/active_record_trickery_test.rb +0 -75
- data/test/session_test/brute_force_protection_test.rb +0 -108
- data/test/session_test/callbacks_test.rb +0 -34
- data/test/session_test/cookies_test.rb +0 -201
- data/test/session_test/credentials_test.rb +0 -0
- data/test/session_test/existence_test.rb +0 -75
- data/test/session_test/foundation_test.rb +0 -6
- data/test/session_test/http_auth_test.rb +0 -56
- data/test/session_test/id_test.rb +0 -17
- data/test/session_test/klass_test.rb +0 -40
- data/test/session_test/magic_columns_test.rb +0 -62
- data/test/session_test/magic_states_test.rb +0 -58
- data/test/session_test/params_test.rb +0 -53
- data/test/session_test/password_test.rb +0 -105
- data/test/session_test/perishability_test.rb +0 -15
- data/test/session_test/persistence_test.rb +0 -32
- data/test/session_test/scopes_test.rb +0 -60
- data/test/session_test/session_test.rb +0 -78
- data/test/session_test/timeout_test.rb +0 -82
- data/test/session_test/unauthorized_record_test.rb +0 -13
- data/test/session_test/validation_test.rb +0 -23
- data/test/test_helper.rb +0 -233
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 755961398552a88cf3761088e4521e71e243249b3a131632e281679d723c82fe
|
4
|
+
data.tar.gz: 2b739ad482ecdaad8218065a4c03882e730c86825bc7140691e451fc26032815
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 52e998e1210ac287f2bc91d01d2afba9416f5b0eee54cff13d89c6c9affdd2ff2a88ac1a80e78ce100c2a43dcbcf777a5f22dd3d72ff3571bc69c5242a89d97c
|
7
|
+
data.tar.gz: 6152232cf873d2c9be4fa24584b3d8bf8013f95ae58a8117f4494c3a6632df814e36b85d02c67efc0e2b73849a43333c0b9bcf9cb1d379f10587147aa69f808e
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Authlogic
|
2
4
|
module ActsAsAuthentic
|
3
5
|
# Provides the base functionality for acts_as_authentic
|
@@ -11,11 +13,13 @@ module Authlogic
|
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
16
|
+
# The primary configuration of a model (often, `User`) for use with
|
17
|
+
# authlogic. These methods become class methods of ::ActiveRecord::Base.
|
14
18
|
module Config
|
15
|
-
# This includes a lot of helpful methods for authenticating records
|
16
|
-
# To use it just do:
|
19
|
+
# This includes a lot of helpful methods for authenticating records
|
20
|
+
# which the Authlogic::Session module relies on. To use it just do:
|
17
21
|
#
|
18
|
-
# class User <
|
22
|
+
# class User < ApplicationRecord
|
19
23
|
# acts_as_authentic
|
20
24
|
# end
|
21
25
|
#
|
@@ -26,29 +30,21 @@ module Authlogic
|
|
26
30
|
# end
|
27
31
|
#
|
28
32
|
# See the various sub modules for the configuration they provide.
|
29
|
-
def acts_as_authentic
|
30
|
-
|
31
|
-
return if !db_setup?
|
32
|
-
|
33
|
-
if !unsupported_options.nil?
|
34
|
-
raise ArgumentError.new(
|
35
|
-
"You are using the old v1.X.X configuration method for " \
|
36
|
-
"Authlogic. Instead of passing a hash of configuration " \
|
37
|
-
"options to acts_as_authentic, pass a block: " \
|
38
|
-
"acts_as_authentic { |c| c.my_option = my_value }"
|
39
|
-
)
|
40
|
-
end
|
41
|
-
|
33
|
+
def acts_as_authentic
|
34
|
+
return unless db_setup?
|
42
35
|
yield self if block_given?
|
43
36
|
acts_as_authentic_modules.each { |mod| include mod }
|
44
37
|
end
|
45
38
|
|
46
|
-
# Since this part of Authlogic deals with another class, ActiveRecord,
|
47
|
-
# in ActiveRecord itself. A lot of
|
48
|
-
#
|
49
|
-
#
|
39
|
+
# Since this part of Authlogic deals with another class, ActiveRecord,
|
40
|
+
# we can't just start including things in ActiveRecord itself. A lot of
|
41
|
+
# these module includes need to be triggered by the acts_as_authentic
|
42
|
+
# method call. For example, you don't want to start adding in email
|
43
|
+
# validations and what not into a model that has nothing to do with
|
44
|
+
# Authlogic.
|
50
45
|
#
|
51
|
-
# That being said, this is your tool for extending Authlogic and
|
46
|
+
# That being said, this is your tool for extending Authlogic and
|
47
|
+
# "hooking" into the acts_as_authentic call.
|
52
48
|
def add_acts_as_authentic_module(mod, action = :append)
|
53
49
|
modules = acts_as_authentic_modules.clone
|
54
50
|
case action
|
@@ -61,7 +57,8 @@ module Authlogic
|
|
61
57
|
self.acts_as_authentic_modules = modules
|
62
58
|
end
|
63
59
|
|
64
|
-
# This is the same as add_acts_as_authentic_module, except that it
|
60
|
+
# This is the same as add_acts_as_authentic_module, except that it
|
61
|
+
# removes the module from the list.
|
65
62
|
def remove_acts_as_authentic_module(mod)
|
66
63
|
modules = acts_as_authentic_modules.clone
|
67
64
|
modules.delete(mod)
|
@@ -70,21 +67,23 @@ module Authlogic
|
|
70
67
|
|
71
68
|
private
|
72
69
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
end
|
80
|
-
end
|
70
|
+
def db_setup?
|
71
|
+
column_names
|
72
|
+
true
|
73
|
+
rescue StandardError
|
74
|
+
false
|
75
|
+
end
|
81
76
|
|
82
|
-
|
83
|
-
|
84
|
-
|
77
|
+
def first_column_to_exist(*columns_to_check)
|
78
|
+
if db_setup?
|
79
|
+
columns_to_check.each do |column_name|
|
80
|
+
if column_names.include?(column_name.to_s)
|
81
|
+
return column_name.to_sym
|
82
|
+
end
|
85
83
|
end
|
86
|
-
columns_to_check.first && columns_to_check.first.to_sym
|
87
84
|
end
|
85
|
+
columns_to_check.first&.to_sym
|
86
|
+
end
|
88
87
|
end
|
89
88
|
end
|
90
89
|
end
|
@@ -98,7 +97,5 @@ end
|
|
98
97
|
::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::Password
|
99
98
|
::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::PerishableToken
|
100
99
|
::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::PersistenceToken
|
101
|
-
::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::RestfulAuthentication
|
102
100
|
::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::SessionMaintenance
|
103
101
|
::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::SingleAccessToken
|
104
|
-
::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::ValidationsScope
|
@@ -1,14 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Authlogic
|
2
4
|
module ActsAsAuthentic
|
3
|
-
# Sometimes models won't have an explicit "login" or "username" field.
|
4
|
-
#
|
5
|
-
#
|
6
|
-
# worry
|
5
|
+
# Sometimes models won't have an explicit "login" or "username" field.
|
6
|
+
# Instead they want to use the email field. In this case, authlogic provides
|
7
|
+
# validations to make sure the email submited is actually a valid email.
|
8
|
+
# Don't worry, if you do have a login or username field, Authlogic will
|
9
|
+
# still validate your email field. One less thing you have to worry about.
|
7
10
|
module Email
|
8
11
|
def self.included(klass)
|
9
12
|
klass.class_eval do
|
10
13
|
extend Config
|
11
|
-
add_acts_as_authentic_module(Methods)
|
12
14
|
end
|
13
15
|
end
|
14
16
|
|
@@ -21,142 +23,7 @@ module Authlogic
|
|
21
23
|
def email_field(value = nil)
|
22
24
|
rw_config(:email_field, value, first_column_to_exist(nil, :email, :email_address))
|
23
25
|
end
|
24
|
-
|
25
|
-
|
26
|
-
# Toggles validating the email field or not.
|
27
|
-
#
|
28
|
-
# * <tt>Default:</tt> true
|
29
|
-
# * <tt>Accepts:</tt> Boolean
|
30
|
-
def validate_email_field(value = nil)
|
31
|
-
rw_config(:validate_email_field, value, true)
|
32
|
-
end
|
33
|
-
alias_method :validate_email_field=, :validate_email_field
|
34
|
-
|
35
|
-
# A hash of options for the validates_length_of call for the email field. Allows you to change this however you want.
|
36
|
-
#
|
37
|
-
# <b>Keep in mind this is ruby. I wanted to keep this as flexible as possible, so you can completely replace the hash or
|
38
|
-
# merge options into it. Checkout the convenience function merge_validates_length_of_email_field_options to merge
|
39
|
-
# options.</b>
|
40
|
-
#
|
41
|
-
# * <tt>Default:</tt> {:maximum => 100}
|
42
|
-
# * <tt>Accepts:</tt> Hash of options accepted by validates_length_of
|
43
|
-
def validates_length_of_email_field_options(value = nil)
|
44
|
-
rw_config(:validates_length_of_email_field_options, value, { :maximum => 100 })
|
45
|
-
end
|
46
|
-
alias_method :validates_length_of_email_field_options=, :validates_length_of_email_field_options
|
47
|
-
|
48
|
-
# A convenience function to merge options into the validates_length_of_email_field_options. So instead of:
|
49
|
-
#
|
50
|
-
# self.validates_length_of_email_field_options = validates_length_of_email_field_options.merge(:my_option => my_value)
|
51
|
-
#
|
52
|
-
# You can do this:
|
53
|
-
#
|
54
|
-
# merge_validates_length_of_email_field_options :my_option => my_value
|
55
|
-
def merge_validates_length_of_email_field_options(options = {})
|
56
|
-
self.validates_length_of_email_field_options = validates_length_of_email_field_options.merge(options)
|
57
|
-
end
|
58
|
-
|
59
|
-
# A hash of options for the validates_format_of call for the email
|
60
|
-
# field. Allows you to change this however you want.
|
61
|
-
#
|
62
|
-
# <b>Keep in mind this is ruby. I wanted to keep this as flexible as
|
63
|
-
# possible, so you can completely replace the hash or merge options into
|
64
|
-
# it. Checkout the convenience function
|
65
|
-
# merge_validates_format_of_email_field_options to merge options.</b>
|
66
|
-
#
|
67
|
-
# To validate international email addresses, enable the provided
|
68
|
-
# alternate regex:
|
69
|
-
#
|
70
|
-
# * <tt>validates_format_of_email_field_options({:with => Authlogic::Regex.email_nonascii})</tt>
|
71
|
-
#
|
72
|
-
# * <tt>Default:</tt>
|
73
|
-
#
|
74
|
-
# {
|
75
|
-
# :with => Authlogic::Regex.email,
|
76
|
-
# :message => Proc.new {
|
77
|
-
# I18n.t(
|
78
|
-
# 'error_messages.email_invalid',
|
79
|
-
# :default => "should look like an email address."
|
80
|
-
# )
|
81
|
-
# }
|
82
|
-
# }
|
83
|
-
#
|
84
|
-
# * <tt>Accepts:</tt> Hash of options accepted by validates_format_of
|
85
|
-
def validates_format_of_email_field_options(value = nil)
|
86
|
-
rw_config(
|
87
|
-
:validates_format_of_email_field_options,
|
88
|
-
value,
|
89
|
-
{
|
90
|
-
:with => Authlogic::Regex.email,
|
91
|
-
:message => Proc.new do
|
92
|
-
I18n.t(
|
93
|
-
'error_messages.email_invalid',
|
94
|
-
:default => "should look like an email address."
|
95
|
-
)
|
96
|
-
end
|
97
|
-
}
|
98
|
-
)
|
99
|
-
end
|
100
|
-
alias_method :validates_format_of_email_field_options=, :validates_format_of_email_field_options
|
101
|
-
|
102
|
-
# See merge_validates_length_of_email_field_options. The same thing except for validates_format_of_email_field_options.
|
103
|
-
def merge_validates_format_of_email_field_options(options = {})
|
104
|
-
self.validates_format_of_email_field_options = validates_format_of_email_field_options.merge(options)
|
105
|
-
end
|
106
|
-
|
107
|
-
# A hash of options for the validates_uniqueness_of call for the email
|
108
|
-
# field. Allows you to change this however you want.
|
109
|
-
#
|
110
|
-
# <b>Keep in mind this is ruby. I wanted to keep this as flexible as
|
111
|
-
# possible, so you can completely replace the hash or merge options into
|
112
|
-
# it. Checkout the convenience function
|
113
|
-
# merge_validates_uniqueness_of_email_field_options to merge
|
114
|
-
# options.</b>
|
115
|
-
#
|
116
|
-
# * <tt>Default:</tt>
|
117
|
-
#
|
118
|
-
# {
|
119
|
-
# :case_sensitive => false,
|
120
|
-
# :scope => validations_scope,
|
121
|
-
# :if => "#{email_field}_changed?".to_sym
|
122
|
-
# }
|
123
|
-
#
|
124
|
-
# * <tt>Accepts:</tt> Hash of options accepted by validates_uniqueness_of
|
125
|
-
def validates_uniqueness_of_email_field_options(value = nil)
|
126
|
-
rw_config(
|
127
|
-
:validates_uniqueness_of_email_field_options,
|
128
|
-
value,
|
129
|
-
{
|
130
|
-
:case_sensitive => false,
|
131
|
-
:scope => validations_scope,
|
132
|
-
:if => "#{email_field}_changed?".to_sym
|
133
|
-
}
|
134
|
-
)
|
135
|
-
end
|
136
|
-
alias_method(
|
137
|
-
:validates_uniqueness_of_email_field_options=,
|
138
|
-
:validates_uniqueness_of_email_field_options
|
139
|
-
)
|
140
|
-
|
141
|
-
# See merge_validates_length_of_email_field_options. The same thing
|
142
|
-
# except for validates_uniqueness_of_email_field_options.
|
143
|
-
def merge_validates_uniqueness_of_email_field_options(options = {})
|
144
|
-
self.validates_uniqueness_of_email_field_options =
|
145
|
-
validates_uniqueness_of_email_field_options.merge(options)
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
# All methods relating to the email field
|
150
|
-
module Methods
|
151
|
-
def self.included(klass)
|
152
|
-
klass.class_eval do
|
153
|
-
if validate_email_field && email_field
|
154
|
-
validates_length_of email_field, validates_length_of_email_field_options
|
155
|
-
validates_format_of email_field, validates_format_of_email_field_options
|
156
|
-
validates_uniqueness_of email_field, validates_uniqueness_of_email_field_options
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
26
|
+
alias email_field= email_field
|
160
27
|
end
|
161
28
|
end
|
162
29
|
end
|
@@ -1,9 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Authlogic
|
2
4
|
module ActsAsAuthentic
|
3
|
-
# Since web applications are stateless there is not sure fire way to tell if
|
4
|
-
# from the database perspective. The best way to
|
5
|
-
#
|
6
|
-
#
|
5
|
+
# Since web applications are stateless there is not sure fire way to tell if
|
6
|
+
# a user is logged in or not, from the database perspective. The best way to
|
7
|
+
# do this is to provide a "timeout" based on inactivity. So if that user is
|
8
|
+
# inactive for a certain amount of time we assume they are logged out.
|
9
|
+
# That's what this module is all about.
|
7
10
|
module LoggedInStatus
|
8
11
|
def self.included(klass)
|
9
12
|
klass.class_eval do
|
@@ -21,13 +24,13 @@ module Authlogic
|
|
21
24
|
def logged_in_timeout(value = nil)
|
22
25
|
rw_config(:logged_in_timeout, (!value.nil? && value.to_i) || value, 10.minutes.to_i)
|
23
26
|
end
|
24
|
-
|
27
|
+
alias logged_in_timeout= logged_in_timeout
|
25
28
|
end
|
26
29
|
|
27
30
|
# All methods for the logged in status feature seat.
|
28
31
|
module Methods
|
29
32
|
def self.included(klass)
|
30
|
-
return
|
33
|
+
return unless klass.column_names.include?("last_request_at")
|
31
34
|
|
32
35
|
klass.class_eval do
|
33
36
|
include InstanceMethods
|
@@ -52,11 +55,15 @@ module Authlogic
|
|
52
55
|
end
|
53
56
|
end
|
54
57
|
|
58
|
+
# :nodoc:
|
55
59
|
module InstanceMethods
|
56
60
|
# Returns true if the last_request_at > logged_in_timeout.
|
57
61
|
def logged_in?
|
58
62
|
unless respond_to?(:last_request_at)
|
59
|
-
raise
|
63
|
+
raise(
|
64
|
+
"Can not determine the records login state because " \
|
65
|
+
"there is no last_request_at column"
|
66
|
+
)
|
60
67
|
end
|
61
68
|
!last_request_at.nil? && last_request_at > logged_in_timeout.seconds.ago
|
62
69
|
end
|
@@ -68,9 +75,9 @@ module Authlogic
|
|
68
75
|
|
69
76
|
private
|
70
77
|
|
71
|
-
|
72
|
-
|
73
|
-
|
78
|
+
def logged_in_timeout
|
79
|
+
self.class.logged_in_timeout
|
80
|
+
end
|
74
81
|
end
|
75
82
|
end
|
76
83
|
end
|
@@ -1,3 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "authlogic/acts_as_authentic/queries/case_sensitivity"
|
4
|
+
require "authlogic/acts_as_authentic/queries/find_with_case"
|
5
|
+
|
1
6
|
module Authlogic
|
2
7
|
module ActsAsAuthentic
|
3
8
|
# Handles everything related to the login field.
|
@@ -5,7 +10,6 @@ module Authlogic
|
|
5
10
|
def self.included(klass)
|
6
11
|
klass.class_eval do
|
7
12
|
extend Config
|
8
|
-
add_acts_as_authentic_module(Methods)
|
9
13
|
end
|
10
14
|
end
|
11
15
|
|
@@ -18,128 +22,7 @@ module Authlogic
|
|
18
22
|
def login_field(value = nil)
|
19
23
|
rw_config(:login_field, value, first_column_to_exist(nil, :login, :username))
|
20
24
|
end
|
21
|
-
|
22
|
-
|
23
|
-
# Whether or not to validate the login field
|
24
|
-
#
|
25
|
-
# * <tt>Default:</tt> true
|
26
|
-
# * <tt>Accepts:</tt> Boolean
|
27
|
-
def validate_login_field(value = nil)
|
28
|
-
rw_config(:validate_login_field, value, true)
|
29
|
-
end
|
30
|
-
alias_method :validate_login_field=, :validate_login_field
|
31
|
-
|
32
|
-
# A hash of options for the validates_length_of call for the login
|
33
|
-
# field. Allows you to change this however you want.
|
34
|
-
#
|
35
|
-
# <b>Keep in mind this is ruby. I wanted to keep this as flexible as
|
36
|
-
# possible, so you can completely replace the hash or merge options into
|
37
|
-
# it. Checkout the convenience function
|
38
|
-
# merge_validates_length_of_login_field_options to merge options.</b>
|
39
|
-
#
|
40
|
-
# * <tt>Default:</tt> {:within => 3..100}
|
41
|
-
# * <tt>Accepts:</tt> Hash of options accepted by validates_length_of
|
42
|
-
def validates_length_of_login_field_options(value = nil)
|
43
|
-
rw_config(:validates_length_of_login_field_options, value, { :within => 3..100 })
|
44
|
-
end
|
45
|
-
alias_method :validates_length_of_login_field_options=, :validates_length_of_login_field_options
|
46
|
-
|
47
|
-
# A convenience function to merge options into the
|
48
|
-
# validates_length_of_login_field_options. So instead of:
|
49
|
-
#
|
50
|
-
# self.validates_length_of_login_field_options =
|
51
|
-
# validates_length_of_login_field_options.merge(:my_option => my_value)
|
52
|
-
#
|
53
|
-
# You can do this:
|
54
|
-
#
|
55
|
-
# merge_validates_length_of_login_field_options :my_option => my_value
|
56
|
-
def merge_validates_length_of_login_field_options(options = {})
|
57
|
-
self.validates_length_of_login_field_options = validates_length_of_login_field_options.merge(options)
|
58
|
-
end
|
59
|
-
|
60
|
-
# A hash of options for the validates_format_of call for the login
|
61
|
-
# field. Allows you to change this however you want.
|
62
|
-
#
|
63
|
-
# <b>Keep in mind this is ruby. I wanted to keep this as flexible as
|
64
|
-
# possible, so you can completely replace the hash or merge options into
|
65
|
-
# it. Checkout the convenience function
|
66
|
-
# merge_validates_format_of_login_field_options to merge options.</b>
|
67
|
-
#
|
68
|
-
# * <tt>Default:</tt>
|
69
|
-
#
|
70
|
-
# {
|
71
|
-
# :with => Authlogic::Regex.login,
|
72
|
-
# :message => lambda {
|
73
|
-
# I18n.t(
|
74
|
-
# 'error_messages.login_invalid',
|
75
|
-
# :default => "should use only letters, numbers, spaces, and .-_@+ please."
|
76
|
-
# )
|
77
|
-
# }
|
78
|
-
# }
|
79
|
-
#
|
80
|
-
# * <tt>Accepts:</tt> Hash of options accepted by validates_format_of
|
81
|
-
def validates_format_of_login_field_options(value = nil)
|
82
|
-
rw_config(
|
83
|
-
:validates_format_of_login_field_options,
|
84
|
-
value,
|
85
|
-
{
|
86
|
-
:with => Authlogic::Regex.login,
|
87
|
-
:message => proc do
|
88
|
-
I18n.t(
|
89
|
-
'error_messages.login_invalid',
|
90
|
-
:default => "should use only letters, numbers, spaces, and .-_@+ please."
|
91
|
-
)
|
92
|
-
end
|
93
|
-
}
|
94
|
-
)
|
95
|
-
end
|
96
|
-
alias_method :validates_format_of_login_field_options=, :validates_format_of_login_field_options
|
97
|
-
|
98
|
-
# See merge_validates_length_of_login_field_options. The same thing,
|
99
|
-
# except for validates_format_of_login_field_options
|
100
|
-
def merge_validates_format_of_login_field_options(options = {})
|
101
|
-
self.validates_format_of_login_field_options = validates_format_of_login_field_options.merge(options)
|
102
|
-
end
|
103
|
-
|
104
|
-
# A hash of options for the validates_uniqueness_of call for the login
|
105
|
-
# field. Allows you to change this however you want.
|
106
|
-
#
|
107
|
-
# <b>Keep in mind this is ruby. I wanted to keep this as flexible as
|
108
|
-
# possible, so you can completely replace the hash or merge options into
|
109
|
-
# it. Checkout the convenience function
|
110
|
-
# merge_validates_format_of_login_field_options to merge options.</b>
|
111
|
-
#
|
112
|
-
# * <tt>Default:</tt>
|
113
|
-
#
|
114
|
-
# {
|
115
|
-
# :case_sensitive => false,
|
116
|
-
# :scope => validations_scope,
|
117
|
-
# :if => "#{login_field}_changed?".to_sym
|
118
|
-
# }
|
119
|
-
#
|
120
|
-
# * <tt>Accepts:</tt> Hash of options accepted by validates_uniqueness_of
|
121
|
-
def validates_uniqueness_of_login_field_options(value = nil)
|
122
|
-
rw_config(
|
123
|
-
:validates_uniqueness_of_login_field_options,
|
124
|
-
value,
|
125
|
-
{
|
126
|
-
:case_sensitive => false,
|
127
|
-
:scope => validations_scope,
|
128
|
-
:if => "#{login_field}_changed?".to_sym
|
129
|
-
}
|
130
|
-
)
|
131
|
-
end
|
132
|
-
alias_method(
|
133
|
-
:validates_uniqueness_of_login_field_options=,
|
134
|
-
:validates_uniqueness_of_login_field_options
|
135
|
-
)
|
136
|
-
|
137
|
-
# See merge_validates_length_of_login_field_options. The same thing,
|
138
|
-
# except for validates_uniqueness_of_login_field_options
|
139
|
-
def merge_validates_uniqueness_of_login_field_options(options = {})
|
140
|
-
self.validates_uniqueness_of_login_field_options =
|
141
|
-
validates_uniqueness_of_login_field_options.merge(options)
|
142
|
-
end
|
25
|
+
alias login_field= login_field
|
143
26
|
|
144
27
|
# This method allows you to find a record with the given login. If you
|
145
28
|
# notice, with Active Record you have the UniquenessValidator class.
|
@@ -160,53 +43,19 @@ module Authlogic
|
|
160
43
|
# The above also applies for using email as your login, except that you
|
161
44
|
# need to set the :case_sensitive in
|
162
45
|
# validates_uniqueness_of_email_field_options to false.
|
46
|
+
#
|
47
|
+
# @api public
|
163
48
|
def find_by_smart_case_login_field(login)
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
find_with_case(email_field, login, validates_uniqueness_of_email_field_options[:case_sensitive] != false)
|
168
|
-
end
|
49
|
+
field = login_field || email_field
|
50
|
+
sensitive = Queries::CaseSensitivity.new(self, field).sensitive?
|
51
|
+
find_with_case(field, login, sensitive)
|
169
52
|
end
|
170
53
|
|
171
54
|
private
|
172
55
|
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
relation = if not sensitivity
|
177
|
-
connection.case_insensitive_comparison(arel_table, field.to_s, columns_hash[field.to_s], value)
|
178
|
-
elsif ar_gem_version >= Gem::Version.new('5.0')
|
179
|
-
connection.case_sensitive_comparison(arel_table, field.to_s, columns_hash[field.to_s], value)
|
180
|
-
else
|
181
|
-
if ar_gem_version < Gem::Version.new('4.2')
|
182
|
-
value = connection.case_sensitive_modifier(value)
|
183
|
-
else
|
184
|
-
value = connection.case_sensitive_modifier(value, field.to_s)
|
185
|
-
end
|
186
|
-
arel_table[field.to_s].eq(value)
|
187
|
-
end
|
188
|
-
|
189
|
-
# bind value in rails 5
|
190
|
-
if ar_gem_version >= Gem::Version.new('5')
|
191
|
-
bind = ActiveRecord::Relation::QueryAttribute.new(field.to_s, value, ActiveRecord::Type::Value.new)
|
192
|
-
where(relation, bind).first
|
193
|
-
else
|
194
|
-
where(relation).first
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
# All methods relating to the login field
|
200
|
-
module Methods
|
201
|
-
# Adds in various validations, modules, etc.
|
202
|
-
def self.included(klass)
|
203
|
-
klass.class_eval do
|
204
|
-
if validate_login_field && login_field
|
205
|
-
validates_length_of login_field, validates_length_of_login_field_options
|
206
|
-
validates_format_of login_field, validates_format_of_login_field_options
|
207
|
-
validates_uniqueness_of login_field, validates_uniqueness_of_login_field_options
|
208
|
-
end
|
209
|
-
end
|
56
|
+
# @api private
|
57
|
+
def find_with_case(field, value, sensitive)
|
58
|
+
Queries::FindWithCase.new(self, field, value, sensitive).execute
|
210
59
|
end
|
211
60
|
end
|
212
61
|
end
|
@@ -1,9 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Authlogic
|
2
4
|
module ActsAsAuthentic
|
3
|
-
# Magic columns are like ActiveRecord's created_at and updated_at columns.
|
4
|
-
# "magically" maintained for you. Authlogic has the same thing, but
|
5
|
-
# maintained on the session side. Please see
|
6
|
-
# details. This module merely adds validations for
|
5
|
+
# Magic columns are like ActiveRecord's created_at and updated_at columns.
|
6
|
+
# They are "magically" maintained for you. Authlogic has the same thing, but
|
7
|
+
# these are maintained on the session side. Please see "Magic Columns" in
|
8
|
+
# `Session::Base` for more details. This module merely adds validations for
|
9
|
+
# the magic columns if they exist.
|
7
10
|
module MagicColumns
|
8
11
|
def self.included(klass)
|
9
12
|
klass.class_eval do
|
@@ -17,15 +20,15 @@ module Authlogic
|
|
17
20
|
klass.class_eval do
|
18
21
|
if column_names.include?("login_count")
|
19
22
|
validates_numericality_of :login_count,
|
20
|
-
:
|
21
|
-
:
|
22
|
-
:
|
23
|
+
only_integer: true,
|
24
|
+
greater_than_or_equal_to: 0,
|
25
|
+
allow_nil: true
|
23
26
|
end
|
24
27
|
if column_names.include?("failed_login_count")
|
25
28
|
validates_numericality_of :failed_login_count,
|
26
|
-
:
|
27
|
-
:
|
28
|
-
:
|
29
|
+
only_integer: true,
|
30
|
+
greater_than_or_equal_to: 0,
|
31
|
+
allow_nil: true
|
29
32
|
end
|
30
33
|
end
|
31
34
|
end
|