authlogic 3.4.6 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/ISSUE_TEMPLATE.md +13 -0
- data/.github/triage.md +87 -0
- data/.gitignore +4 -0
- data/.rubocop.yml +127 -0
- data/.rubocop_todo.yml +65 -0
- data/.travis.yml +18 -10
- data/CHANGELOG.md +156 -6
- data/CONTRIBUTING.md +71 -3
- data/Gemfile +2 -2
- data/README.md +386 -0
- data/Rakefile +13 -7
- data/UPGRADING.md +22 -0
- data/authlogic.gemspec +33 -22
- data/lib/authlogic.rb +60 -52
- data/lib/authlogic/acts_as_authentic/base.rb +40 -26
- data/lib/authlogic/acts_as_authentic/email.rb +96 -32
- data/lib/authlogic/acts_as_authentic/logged_in_status.rb +36 -12
- data/lib/authlogic/acts_as_authentic/login.rb +114 -49
- data/lib/authlogic/acts_as_authentic/magic_columns.rb +17 -6
- data/lib/authlogic/acts_as_authentic/password.rb +296 -139
- data/lib/authlogic/acts_as_authentic/perishable_token.rb +34 -20
- data/lib/authlogic/acts_as_authentic/persistence_token.rb +20 -24
- data/lib/authlogic/acts_as_authentic/queries/find_with_case.rb +67 -0
- data/lib/authlogic/acts_as_authentic/restful_authentication.rb +68 -23
- data/lib/authlogic/acts_as_authentic/session_maintenance.rb +128 -85
- data/lib/authlogic/acts_as_authentic/single_access_token.rb +41 -25
- data/lib/authlogic/acts_as_authentic/validations_scope.rb +8 -8
- data/lib/authlogic/authenticates_many/association.rb +22 -14
- data/lib/authlogic/authenticates_many/base.rb +35 -16
- data/lib/authlogic/config.rb +10 -10
- data/lib/authlogic/controller_adapters/abstract_adapter.rb +40 -12
- data/lib/authlogic/controller_adapters/rack_adapter.rb +15 -8
- data/lib/authlogic/controller_adapters/rails_adapter.rb +42 -22
- data/lib/authlogic/controller_adapters/sinatra_adapter.rb +3 -3
- data/lib/authlogic/crypto_providers.rb +91 -0
- data/lib/authlogic/crypto_providers/aes256.rb +42 -14
- data/lib/authlogic/crypto_providers/bcrypt.rb +35 -20
- data/lib/authlogic/crypto_providers/md5.rb +11 -9
- data/lib/authlogic/crypto_providers/scrypt.rb +26 -13
- data/lib/authlogic/crypto_providers/sha1.rb +14 -8
- data/lib/authlogic/crypto_providers/sha256.rb +16 -12
- data/lib/authlogic/crypto_providers/sha512.rb +8 -24
- data/lib/authlogic/crypto_providers/wordpress.rb +44 -15
- data/lib/authlogic/i18n.rb +33 -20
- data/lib/authlogic/i18n/translator.rb +1 -1
- data/lib/authlogic/random.rb +12 -29
- data/lib/authlogic/regex.rb +59 -27
- data/lib/authlogic/session/activation.rb +36 -23
- data/lib/authlogic/session/active_record_trickery.rb +13 -10
- data/lib/authlogic/session/base.rb +20 -8
- data/lib/authlogic/session/brute_force_protection.rb +87 -56
- data/lib/authlogic/session/callbacks.rb +99 -49
- data/lib/authlogic/session/cookies.rb +128 -59
- data/lib/authlogic/session/existence.rb +29 -19
- data/lib/authlogic/session/foundation.rb +70 -16
- data/lib/authlogic/session/http_auth.rb +39 -31
- data/lib/authlogic/session/id.rb +27 -15
- data/lib/authlogic/session/klass.rb +17 -13
- data/lib/authlogic/session/magic_columns.rb +78 -59
- data/lib/authlogic/session/magic_states.rb +50 -27
- data/lib/authlogic/session/params.rb +79 -50
- data/lib/authlogic/session/password.rb +197 -118
- data/lib/authlogic/session/perishable_token.rb +12 -6
- data/lib/authlogic/session/persistence.rb +20 -14
- data/lib/authlogic/session/priority_record.rb +20 -16
- data/lib/authlogic/session/scopes.rb +63 -33
- data/lib/authlogic/session/session.rb +40 -25
- data/lib/authlogic/session/timeout.rb +51 -34
- data/lib/authlogic/session/unauthorized_record.rb +24 -18
- data/lib/authlogic/session/validation.rb +32 -21
- data/lib/authlogic/test_case.rb +123 -35
- data/lib/authlogic/test_case/mock_controller.rb +14 -13
- data/lib/authlogic/test_case/mock_cookie_jar.rb +14 -5
- data/lib/authlogic/test_case/mock_logger.rb +1 -1
- data/lib/authlogic/test_case/mock_request.rb +9 -4
- data/lib/authlogic/test_case/rails_request_adapter.rb +8 -7
- data/lib/authlogic/version.rb +21 -0
- data/test/acts_as_authentic_test/base_test.rb +1 -1
- data/test/acts_as_authentic_test/email_test.rb +80 -63
- data/test/acts_as_authentic_test/logged_in_status_test.rb +14 -8
- data/test/acts_as_authentic_test/login_test.rb +91 -49
- data/test/acts_as_authentic_test/magic_columns_test.rb +13 -13
- data/test/acts_as_authentic_test/password_test.rb +82 -60
- data/test/acts_as_authentic_test/perishable_token_test.rb +31 -25
- data/test/acts_as_authentic_test/persistence_token_test.rb +9 -5
- data/test/acts_as_authentic_test/restful_authentication_test.rb +18 -9
- data/test/acts_as_authentic_test/session_maintenance_test.rb +86 -22
- data/test/acts_as_authentic_test/single_access_test.rb +15 -15
- data/test/adapter_test.rb +21 -0
- data/test/authenticates_many_test.rb +26 -11
- data/test/config_test.rb +9 -9
- data/test/crypto_provider_test/aes256_test.rb +3 -3
- data/test/crypto_provider_test/bcrypt_test.rb +1 -1
- data/test/crypto_provider_test/scrypt_test.rb +2 -2
- data/test/crypto_provider_test/sha1_test.rb +4 -4
- data/test/crypto_provider_test/sha256_test.rb +2 -2
- data/test/crypto_provider_test/sha512_test.rb +3 -3
- data/test/crypto_provider_test/wordpress_test.rb +24 -0
- data/test/gemfiles/Gemfile.rails-4.2.x +2 -2
- data/test/gemfiles/Gemfile.rails-5.0.x +6 -0
- data/test/gemfiles/Gemfile.rails-5.1.x +6 -0
- data/test/gemfiles/Gemfile.rails-5.2.x +6 -0
- data/test/gemfiles/Gemfile.rails-master +6 -0
- data/test/i18n_test.rb +9 -9
- data/test/libs/affiliate.rb +2 -2
- data/test/libs/company.rb +4 -4
- data/test/libs/employee.rb +2 -2
- data/test/libs/employee_session.rb +1 -1
- data/test/libs/ldaper.rb +1 -1
- data/test/libs/project.rb +1 -1
- data/test/libs/user_session.rb +2 -2
- data/test/random_test.rb +9 -38
- data/test/session_test/activation_test.rb +7 -7
- data/test/session_test/active_record_trickery_test.rb +9 -6
- data/test/session_test/brute_force_protection_test.rb +26 -21
- data/test/session_test/callbacks_test.rb +10 -4
- data/test/session_test/cookies_test.rb +54 -20
- data/test/session_test/existence_test.rb +45 -23
- data/test/session_test/foundation_test.rb +17 -1
- data/test/session_test/http_auth_test.rb +11 -12
- data/test/session_test/id_test.rb +3 -3
- data/test/session_test/klass_test.rb +2 -2
- data/test/session_test/magic_columns_test.rb +15 -17
- data/test/session_test/magic_states_test.rb +17 -19
- data/test/session_test/params_test.rb +26 -20
- data/test/session_test/password_test.rb +11 -12
- data/test/session_test/perishability_test.rb +5 -5
- data/test/session_test/persistence_test.rb +4 -3
- data/test/session_test/scopes_test.rb +15 -9
- data/test/session_test/session_test.rb +7 -6
- data/test/session_test/timeout_test.rb +16 -14
- data/test/session_test/unauthorized_record_test.rb +3 -3
- data/test/session_test/validation_test.rb +5 -5
- data/test/test_helper.rb +115 -49
- metadata +107 -36
- data/README.rdoc +0 -232
- 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/Rakefile
CHANGED
@@ -1,13 +1,19 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler"
|
3
3
|
|
4
4
|
Bundler.setup
|
5
5
|
|
6
|
-
require
|
6
|
+
require "rake/testtask"
|
7
7
|
Rake::TestTask.new(:test) do |test|
|
8
|
-
test.libs <<
|
9
|
-
test.pattern =
|
10
|
-
test.verbose =
|
8
|
+
test.libs << "test"
|
9
|
+
test.pattern = "test/**/*_test.rb"
|
10
|
+
test.verbose = false
|
11
|
+
|
12
|
+
# Set interpreter warning level to 2 (verbose)
|
13
|
+
test.ruby_opts += ["-W2"]
|
11
14
|
end
|
12
15
|
|
13
|
-
|
16
|
+
require "rubocop/rake_task"
|
17
|
+
RuboCop::RakeTask.new
|
18
|
+
|
19
|
+
task default: %i[rubocop test]
|
data/UPGRADING.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Upgrading Authlogic
|
2
|
+
|
3
|
+
Supplemental instructions to complement CHANGELOG.md.
|
4
|
+
|
5
|
+
## 3.4.0
|
6
|
+
|
7
|
+
In version 3.4.0, released 2014-03-03, the default crypto_provider was changed
|
8
|
+
from *Sha512* to *SCrypt*.
|
9
|
+
|
10
|
+
If you never set a crypto_provider and are upgrading, your passwords will break
|
11
|
+
unless you specify `Sha512`.
|
12
|
+
|
13
|
+
``` ruby
|
14
|
+
c.crypto_provider = Authlogic::CryptoProviders::Sha512
|
15
|
+
```
|
16
|
+
|
17
|
+
And if you want to automatically upgrade from *Sha512* to *SCrypt* as users login:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
c.transition_from_crypto_providers = [Authlogic::CryptoProviders::Sha512]
|
21
|
+
c.crypto_provider = Authlogic::CryptoProviders::SCrypt
|
22
|
+
```
|
data/authlogic.gemspec
CHANGED
@@ -1,27 +1,38 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require "English"
|
2
|
+
$LOAD_PATH.push File.expand_path("lib", __dir__)
|
3
|
+
require "authlogic/version"
|
3
4
|
|
4
|
-
Gem::Specification.new do |s|
|
5
|
-
s.name
|
6
|
-
s.version
|
7
|
-
s.platform
|
8
|
-
s.authors
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
::Gem::Specification.new do |s|
|
6
|
+
s.name = "authlogic"
|
7
|
+
s.version = ::Authlogic.gem_version.to_s
|
8
|
+
s.platform = ::Gem::Platform::RUBY
|
9
|
+
s.authors = [
|
10
|
+
"Ben Johnson",
|
11
|
+
"Tieg Zaharia",
|
12
|
+
"Jared Beck"
|
13
|
+
]
|
14
|
+
s.email = [
|
15
|
+
"bjohnson@binarylogic.com",
|
16
|
+
"tieg.zaharia@gmail.com",
|
17
|
+
"jared@jaredbeck.com"
|
18
|
+
]
|
19
|
+
s.homepage = "http://github.com/binarylogic/authlogic"
|
20
|
+
s.summary = "A clean, simple, and unobtrusive ruby authentication solution."
|
21
|
+
s.license = "MIT"
|
13
22
|
|
14
|
-
s.
|
23
|
+
s.required_ruby_version = ">= 2.2.0"
|
24
|
+
s.add_dependency "activerecord", [">= 4.2", "< 5.3"]
|
25
|
+
s.add_dependency "activesupport", [">= 4.2", "< 5.3"]
|
26
|
+
s.add_dependency "request_store", "~> 1.0"
|
27
|
+
s.add_dependency "scrypt", ">= 1.2", "< 4.0"
|
28
|
+
s.add_development_dependency "bcrypt", "~> 3.1"
|
29
|
+
s.add_development_dependency "byebug", "~> 10.0"
|
30
|
+
s.add_development_dependency "minitest-reporters", "~> 1.3"
|
31
|
+
s.add_development_dependency "rubocop", "~> 0.58.1"
|
32
|
+
s.add_development_dependency "timecop", "~> 0.7"
|
15
33
|
|
16
|
-
s.
|
17
|
-
s.
|
18
|
-
s.
|
19
|
-
s.add_dependency 'scrypt', '>= 1.2', '< 3.0'
|
20
|
-
s.add_development_dependency 'bcrypt', '~> 3.1'
|
21
|
-
s.add_development_dependency 'timecop', '~> 0.7'
|
22
|
-
|
23
|
-
s.files = `git ls-files`.split("\n")
|
24
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
25
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
34
|
+
s.files = `git ls-files`.split("\n")
|
35
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
36
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
26
37
|
s.require_paths = ["lib"]
|
27
38
|
end
|
data/lib/authlogic.rb
CHANGED
@@ -1,59 +1,67 @@
|
|
1
|
+
# Authlogic uses ActiveSupport's core extensions like `strip_heredoc` and
|
2
|
+
# `squish`. ActiveRecord does not `require` these exensions, so we must.
|
3
|
+
#
|
4
|
+
# It's possible that we could save a few milliseconds by loading only the
|
5
|
+
# specific core extensions we need, but `all.rb` is simpler. We can revisit this
|
6
|
+
# decision if it becomes a problem.
|
7
|
+
require "active_support/all"
|
8
|
+
|
1
9
|
require "active_record"
|
2
10
|
|
3
11
|
path = File.dirname(__FILE__) + "/authlogic/"
|
4
12
|
|
5
13
|
[
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
14
|
+
"i18n",
|
15
|
+
"random",
|
16
|
+
"regex",
|
17
|
+
"config",
|
18
|
+
|
19
|
+
"controller_adapters/abstract_adapter",
|
20
|
+
|
21
|
+
"crypto_providers",
|
22
|
+
|
23
|
+
"authenticates_many/base",
|
24
|
+
"authenticates_many/association",
|
25
|
+
|
26
|
+
"acts_as_authentic/email",
|
27
|
+
"acts_as_authentic/logged_in_status",
|
28
|
+
"acts_as_authentic/login",
|
29
|
+
"acts_as_authentic/magic_columns",
|
30
|
+
"acts_as_authentic/password",
|
31
|
+
"acts_as_authentic/perishable_token",
|
32
|
+
"acts_as_authentic/persistence_token",
|
33
|
+
"acts_as_authentic/restful_authentication",
|
34
|
+
"acts_as_authentic/session_maintenance",
|
35
|
+
"acts_as_authentic/single_access_token",
|
36
|
+
"acts_as_authentic/validations_scope",
|
37
|
+
"acts_as_authentic/base",
|
38
|
+
|
39
|
+
"session/activation",
|
40
|
+
"session/active_record_trickery",
|
41
|
+
"session/brute_force_protection",
|
42
|
+
"session/callbacks",
|
43
|
+
"session/cookies",
|
44
|
+
"session/existence",
|
45
|
+
"session/foundation",
|
46
|
+
"session/http_auth",
|
47
|
+
"session/id",
|
48
|
+
"session/klass",
|
49
|
+
"session/magic_columns",
|
50
|
+
"session/magic_states",
|
51
|
+
"session/params",
|
52
|
+
"session/password",
|
53
|
+
"session/perishable_token",
|
54
|
+
"session/persistence",
|
55
|
+
"session/priority_record",
|
56
|
+
"session/scopes",
|
57
|
+
"session/session",
|
58
|
+
"session/timeout",
|
59
|
+
"session/unauthorized_record",
|
60
|
+
"session/validation",
|
61
|
+
"session/base"
|
54
62
|
].each do |library|
|
55
|
-
|
56
|
-
|
63
|
+
require path + library
|
64
|
+
end
|
57
65
|
|
58
|
-
require path + "controller_adapters/rails_adapter" if defined?(
|
59
|
-
require path + "controller_adapters/sinatra_adapter" if defined?(
|
66
|
+
require path + "controller_adapters/rails_adapter" if defined?(Rails)
|
67
|
+
require path + "controller_adapters/sinatra_adapter" if defined?(Sinatra)
|
@@ -11,9 +11,11 @@ module Authlogic
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
+
# The primary configuration of a model (often, `User`) for use with
|
15
|
+
# authlogic. These methods become class methods of ::ActiveRecord::Base.
|
14
16
|
module Config
|
15
|
-
# This includes a lot of helpful methods for authenticating records
|
16
|
-
# To use it just do:
|
17
|
+
# This includes a lot of helpful methods for authenticating records
|
18
|
+
# which the Authlogic::Session module relies on. To use it just do:
|
17
19
|
#
|
18
20
|
# class User < ActiveRecord::Base
|
19
21
|
# acts_as_authentic
|
@@ -26,14 +28,16 @@ module Authlogic
|
|
26
28
|
# end
|
27
29
|
#
|
28
30
|
# See the various sub modules for the configuration they provide.
|
29
|
-
def acts_as_authentic(unsupported_options = nil
|
31
|
+
def acts_as_authentic(unsupported_options = nil)
|
30
32
|
# Stop all configuration if the DB is not set up
|
31
|
-
return
|
33
|
+
return unless db_setup?
|
32
34
|
|
33
|
-
|
35
|
+
unless unsupported_options.nil?
|
34
36
|
raise ArgumentError.new(
|
35
|
-
"You are using the old v1.X.X configuration method for
|
36
|
-
|
37
|
+
"You are using the old v1.X.X configuration method for " \
|
38
|
+
"Authlogic. Instead of passing a hash of configuration " \
|
39
|
+
"options to acts_as_authentic, pass a block: " \
|
40
|
+
"acts_as_authentic { |c| c.my_option = my_value }"
|
37
41
|
)
|
38
42
|
end
|
39
43
|
|
@@ -41,12 +45,15 @@ module Authlogic
|
|
41
45
|
acts_as_authentic_modules.each { |mod| include mod }
|
42
46
|
end
|
43
47
|
|
44
|
-
# Since this part of Authlogic deals with another class, ActiveRecord,
|
45
|
-
# in ActiveRecord itself. A lot of
|
46
|
-
#
|
47
|
-
#
|
48
|
+
# Since this part of Authlogic deals with another class, ActiveRecord,
|
49
|
+
# we can't just start including things in ActiveRecord itself. A lot of
|
50
|
+
# these module includes need to be triggered by the acts_as_authentic
|
51
|
+
# method call. For example, you don't want to start adding in email
|
52
|
+
# validations and what not into a model that has nothing to do with
|
53
|
+
# Authlogic.
|
48
54
|
#
|
49
|
-
# That being said, this is your tool for extending Authlogic and
|
55
|
+
# That being said, this is your tool for extending Authlogic and
|
56
|
+
# "hooking" into the acts_as_authentic call.
|
50
57
|
def add_acts_as_authentic_module(mod, action = :append)
|
51
58
|
modules = acts_as_authentic_modules.clone
|
52
59
|
case action
|
@@ -59,7 +66,8 @@ module Authlogic
|
|
59
66
|
self.acts_as_authentic_modules = modules
|
60
67
|
end
|
61
68
|
|
62
|
-
# This is the same as add_acts_as_authentic_module, except that it
|
69
|
+
# This is the same as add_acts_as_authentic_module, except that it
|
70
|
+
# removes the module from the list.
|
63
71
|
def remove_acts_as_authentic_module(mod)
|
64
72
|
modules = acts_as_authentic_modules.clone
|
65
73
|
modules.delete(mod)
|
@@ -67,21 +75,24 @@ module Authlogic
|
|
67
75
|
end
|
68
76
|
|
69
77
|
private
|
70
|
-
def db_setup?
|
71
|
-
begin
|
72
|
-
column_names
|
73
|
-
true
|
74
|
-
rescue Exception
|
75
|
-
false
|
76
|
-
end
|
77
|
-
end
|
78
78
|
|
79
|
-
|
80
|
-
|
81
|
-
|
79
|
+
def db_setup?
|
80
|
+
column_names
|
81
|
+
true
|
82
|
+
rescue StandardError
|
83
|
+
false
|
84
|
+
end
|
85
|
+
|
86
|
+
def first_column_to_exist(*columns_to_check)
|
87
|
+
if db_setup?
|
88
|
+
columns_to_check.each do |column_name|
|
89
|
+
if column_names.include?(column_name.to_s)
|
90
|
+
return column_name.to_sym
|
91
|
+
end
|
82
92
|
end
|
83
|
-
columns_to_check.first && columns_to_check.first.to_sym
|
84
93
|
end
|
94
|
+
columns_to_check.first && columns_to_check.first.to_sym
|
95
|
+
end
|
85
96
|
end
|
86
97
|
end
|
87
98
|
end
|
@@ -95,8 +106,11 @@ end
|
|
95
106
|
::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::Password
|
96
107
|
::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::PerishableToken
|
97
108
|
::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::PersistenceToken
|
109
|
+
|
110
|
+
# RestfulAuthentication is deprecated. See comments in
|
111
|
+
# acts_as_authentic/restful_authentication.rb
|
98
112
|
::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::RestfulAuthentication
|
113
|
+
|
99
114
|
::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::SessionMaintenance
|
100
115
|
::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::SingleAccessToken
|
101
116
|
::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::ValidationsScope
|
102
|
-
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module Authlogic
|
2
2
|
module ActsAsAuthentic
|
3
|
-
# Sometimes models won't have an explicit "login" or "username" field.
|
4
|
-
#
|
5
|
-
#
|
6
|
-
# worry
|
3
|
+
# Sometimes models won't have an explicit "login" or "username" field.
|
4
|
+
# Instead they want to use the email field. In this case, authlogic provides
|
5
|
+
# validations to make sure the email submited is actually a valid email.
|
6
|
+
# Don't worry, if you do have a login or username field, Authlogic will
|
7
|
+
# still validate your email field. One less thing you have to worry about.
|
7
8
|
module Email
|
8
9
|
def self.included(klass)
|
9
10
|
klass.class_eval do
|
@@ -32,67 +33,130 @@ module Authlogic
|
|
32
33
|
end
|
33
34
|
alias_method :validate_email_field=, :validate_email_field
|
34
35
|
|
35
|
-
# A hash of options for the validates_length_of call for the email
|
36
|
+
# A hash of options for the validates_length_of call for the email
|
37
|
+
# field. Allows you to change this however you want.
|
36
38
|
#
|
37
|
-
# <b>Keep in mind this is ruby. I wanted to keep this as flexible as
|
38
|
-
#
|
39
|
-
#
|
39
|
+
# <b>Keep in mind this is ruby. I wanted to keep this as flexible as
|
40
|
+
# possible, so you can completely replace the hash or merge options into
|
41
|
+
# it. Checkout the convenience function
|
42
|
+
# merge_validates_length_of_email_field_options to merge options.</b>
|
40
43
|
#
|
41
44
|
# * <tt>Default:</tt> {:maximum => 100}
|
42
45
|
# * <tt>Accepts:</tt> Hash of options accepted by validates_length_of
|
43
46
|
def validates_length_of_email_field_options(value = nil)
|
44
|
-
rw_config(:validates_length_of_email_field_options, value,
|
47
|
+
rw_config(:validates_length_of_email_field_options, value, maximum: 100)
|
45
48
|
end
|
46
|
-
alias_method
|
49
|
+
alias_method(
|
50
|
+
:validates_length_of_email_field_options=,
|
51
|
+
:validates_length_of_email_field_options
|
52
|
+
)
|
47
53
|
|
48
|
-
# A convenience function to merge options into the
|
54
|
+
# A convenience function to merge options into the
|
55
|
+
# validates_length_of_email_field_options. So instead of:
|
49
56
|
#
|
50
|
-
# self.validates_length_of_email_field_options =
|
57
|
+
# self.validates_length_of_email_field_options =
|
58
|
+
# validates_length_of_email_field_options.merge(:my_option => my_value)
|
51
59
|
#
|
52
60
|
# You can do this:
|
53
61
|
#
|
54
62
|
# merge_validates_length_of_email_field_options :my_option => my_value
|
55
63
|
def merge_validates_length_of_email_field_options(options = {})
|
56
|
-
self.validates_length_of_email_field_options =
|
64
|
+
self.validates_length_of_email_field_options =
|
65
|
+
validates_length_of_email_field_options.merge(options)
|
57
66
|
end
|
58
67
|
|
59
|
-
# A hash of options for the validates_format_of call for the email
|
68
|
+
# A hash of options for the validates_format_of call for the email
|
69
|
+
# field. Allows you to change this however you want.
|
60
70
|
#
|
61
|
-
# <b>Keep in mind this is ruby. I wanted to keep this as flexible as
|
62
|
-
#
|
63
|
-
#
|
71
|
+
# <b>Keep in mind this is ruby. I wanted to keep this as flexible as
|
72
|
+
# possible, so you can completely replace the hash or merge options into
|
73
|
+
# it. Checkout the convenience function
|
74
|
+
# merge_validates_format_of_email_field_options to merge options.</b>
|
75
|
+
#
|
76
|
+
# To validate international email addresses, enable the provided
|
77
|
+
# alternate regex:
|
78
|
+
#
|
79
|
+
# ```
|
80
|
+
# validates_format_of_email_field_options(
|
81
|
+
# with: Authlogic::Regex.email_nonascii
|
82
|
+
# )
|
83
|
+
# ```
|
64
84
|
#
|
65
|
-
#
|
66
|
-
#
|
85
|
+
# * <tt>Default:</tt>
|
86
|
+
#
|
87
|
+
# {
|
88
|
+
# :with => Authlogic::Regex.email,
|
89
|
+
# :message => Proc.new {
|
90
|
+
# I18n.t(
|
91
|
+
# 'error_messages.email_invalid',
|
92
|
+
# :default => "should look like an email address."
|
93
|
+
# )
|
94
|
+
# }
|
95
|
+
# }
|
67
96
|
#
|
68
|
-
# * <tt>Default:</tt> {:with => Authlogic::Regex.email, :message => Proc.new {I18n.t('error_messages.email_invalid', :default => "should look like an email address.")}}
|
69
97
|
# * <tt>Accepts:</tt> Hash of options accepted by validates_format_of
|
70
98
|
def validates_format_of_email_field_options(value = nil)
|
71
|
-
rw_config(
|
99
|
+
rw_config(
|
100
|
+
:validates_format_of_email_field_options,
|
101
|
+
value,
|
102
|
+
with: Authlogic::Regex::EMAIL,
|
103
|
+
message: proc do
|
104
|
+
I18n.t(
|
105
|
+
"error_messages.email_invalid",
|
106
|
+
default: "should look like an email address."
|
107
|
+
)
|
108
|
+
end
|
109
|
+
)
|
72
110
|
end
|
73
|
-
alias_method
|
111
|
+
alias_method(
|
112
|
+
:validates_format_of_email_field_options=,
|
113
|
+
:validates_format_of_email_field_options
|
114
|
+
)
|
74
115
|
|
75
|
-
# See merge_validates_length_of_email_field_options. The same thing
|
116
|
+
# See merge_validates_length_of_email_field_options. The same thing
|
117
|
+
# except for validates_format_of_email_field_options.
|
76
118
|
def merge_validates_format_of_email_field_options(options = {})
|
77
|
-
self.validates_format_of_email_field_options =
|
119
|
+
self.validates_format_of_email_field_options =
|
120
|
+
validates_format_of_email_field_options.merge(options)
|
78
121
|
end
|
79
122
|
|
80
|
-
# A hash of options for the validates_uniqueness_of call for the email
|
123
|
+
# A hash of options for the validates_uniqueness_of call for the email
|
124
|
+
# field. Allows you to change this however you want.
|
81
125
|
#
|
82
|
-
# <b>Keep in mind this is ruby. I wanted to keep this as flexible as
|
83
|
-
#
|
126
|
+
# <b>Keep in mind this is ruby. I wanted to keep this as flexible as
|
127
|
+
# possible, so you can completely replace the hash or merge options into
|
128
|
+
# it. Checkout the convenience function
|
129
|
+
# merge_validates_uniqueness_of_email_field_options to merge
|
84
130
|
# options.</b>
|
85
131
|
#
|
86
|
-
# * <tt>Default:</tt>
|
132
|
+
# * <tt>Default:</tt>
|
133
|
+
#
|
134
|
+
# {
|
135
|
+
# :case_sensitive => false,
|
136
|
+
# :scope => validations_scope,
|
137
|
+
# :if => "#{email_field}_changed?".to_sym
|
138
|
+
# }
|
139
|
+
#
|
87
140
|
# * <tt>Accepts:</tt> Hash of options accepted by validates_uniqueness_of
|
88
141
|
def validates_uniqueness_of_email_field_options(value = nil)
|
89
|
-
rw_config(
|
142
|
+
rw_config(
|
143
|
+
:validates_uniqueness_of_email_field_options,
|
144
|
+
value,
|
145
|
+
case_sensitive: false,
|
146
|
+
scope: validations_scope,
|
147
|
+
if: "#{email_field}_changed?".to_sym
|
148
|
+
)
|
90
149
|
end
|
91
|
-
alias_method
|
150
|
+
alias_method(
|
151
|
+
:validates_uniqueness_of_email_field_options=,
|
152
|
+
:validates_uniqueness_of_email_field_options
|
153
|
+
)
|
92
154
|
|
93
|
-
# See merge_validates_length_of_email_field_options. The same thing
|
155
|
+
# See merge_validates_length_of_email_field_options. The same thing
|
156
|
+
# except for validates_uniqueness_of_email_field_options.
|
94
157
|
def merge_validates_uniqueness_of_email_field_options(options = {})
|
95
|
-
self.validates_uniqueness_of_email_field_options =
|
158
|
+
self.validates_uniqueness_of_email_field_options =
|
159
|
+
validates_uniqueness_of_email_field_options.merge(options)
|
96
160
|
end
|
97
161
|
end
|
98
162
|
|