authlogic 3.4.6 → 3.5.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 +4 -4
- data/.gitignore +2 -0
- data/.rubocop.yml +33 -0
- data/.rubocop_todo.yml +427 -0
- data/.travis.yml +24 -3
- data/CHANGELOG.md +9 -2
- data/CONTRIBUTING.md +40 -1
- data/Gemfile +1 -1
- data/README.md +295 -0
- data/Rakefile +10 -2
- data/authlogic.gemspec +6 -5
- data/lib/authlogic.rb +2 -2
- data/lib/authlogic/acts_as_authentic/base.rb +2 -2
- data/lib/authlogic/acts_as_authentic/email.rb +59 -14
- data/lib/authlogic/acts_as_authentic/logged_in_status.rb +4 -3
- data/lib/authlogic/acts_as_authentic/login.rb +62 -12
- data/lib/authlogic/acts_as_authentic/magic_columns.rb +17 -6
- data/lib/authlogic/acts_as_authentic/password.rb +107 -53
- data/lib/authlogic/acts_as_authentic/persistence_token.rb +10 -9
- data/lib/authlogic/acts_as_authentic/restful_authentication.rb +2 -0
- data/lib/authlogic/acts_as_authentic/session_maintenance.rb +48 -35
- data/lib/authlogic/acts_as_authentic/single_access_token.rb +19 -15
- data/lib/authlogic/acts_as_authentic/validations_scope.rb +2 -2
- data/lib/authlogic/authenticates_many/association.rb +6 -5
- data/lib/authlogic/authenticates_many/base.rb +22 -12
- data/lib/authlogic/config.rb +2 -1
- data/lib/authlogic/controller_adapters/abstract_adapter.rb +2 -1
- data/lib/authlogic/controller_adapters/rack_adapter.rb +3 -4
- data/lib/authlogic/controller_adapters/rails_adapter.rb +26 -14
- data/lib/authlogic/controller_adapters/sinatra_adapter.rb +1 -1
- data/lib/authlogic/crypto_providers/aes256.rb +16 -12
- data/lib/authlogic/crypto_providers/bcrypt.rb +10 -4
- data/lib/authlogic/crypto_providers/md5.rb +7 -7
- data/lib/authlogic/crypto_providers/scrypt.rb +10 -2
- data/lib/authlogic/crypto_providers/sha1.rb +3 -3
- data/lib/authlogic/crypto_providers/sha256.rb +3 -3
- data/lib/authlogic/crypto_providers/sha512.rb +4 -4
- data/lib/authlogic/crypto_providers/wordpress.rb +13 -13
- data/lib/authlogic/i18n.rb +22 -16
- data/lib/authlogic/i18n/translator.rb +1 -1
- data/lib/authlogic/random.rb +13 -12
- data/lib/authlogic/regex.rb +3 -3
- data/lib/authlogic/session/activation.rb +7 -6
- data/lib/authlogic/session/active_record_trickery.rb +1 -2
- data/lib/authlogic/session/base.rb +7 -6
- data/lib/authlogic/session/brute_force_protection.rb +58 -34
- data/lib/authlogic/session/callbacks.rb +16 -12
- data/lib/authlogic/session/cookies.rb +29 -14
- data/lib/authlogic/session/existence.rb +10 -10
- data/lib/authlogic/session/foundation.rb +11 -7
- data/lib/authlogic/session/http_auth.rb +6 -5
- data/lib/authlogic/session/id.rb +5 -4
- data/lib/authlogic/session/klass.rb +2 -1
- data/lib/authlogic/session/magic_columns.rb +21 -14
- data/lib/authlogic/session/magic_states.rb +25 -14
- data/lib/authlogic/session/params.rb +41 -26
- data/lib/authlogic/session/password.rb +62 -40
- data/lib/authlogic/session/perishable_token.rb +3 -2
- data/lib/authlogic/session/persistence.rb +3 -3
- data/lib/authlogic/session/priority_record.rb +5 -4
- data/lib/authlogic/session/scopes.rb +20 -9
- data/lib/authlogic/session/session.rb +9 -4
- data/lib/authlogic/session/timeout.rb +40 -23
- data/lib/authlogic/session/unauthorized_record.rb +6 -5
- data/lib/authlogic/session/validation.rb +18 -9
- data/lib/authlogic/test_case.rb +2 -2
- data/lib/authlogic/test_case/mock_controller.rb +9 -9
- data/lib/authlogic/test_case/mock_cookie_jar.rb +2 -2
- data/lib/authlogic/test_case/mock_logger.rb +1 -1
- data/lib/authlogic/test_case/mock_request.rb +2 -1
- data/lib/authlogic/test_case/rails_request_adapter.rb +5 -5
- data/test/acts_as_authentic_test/email_test.rb +29 -17
- data/test/acts_as_authentic_test/logged_in_status_test.rb +9 -3
- data/test/acts_as_authentic_test/login_test.rb +47 -13
- data/test/acts_as_authentic_test/magic_columns_test.rb +4 -4
- data/test/acts_as_authentic_test/password_test.rb +31 -21
- data/test/acts_as_authentic_test/perishable_token_test.rb +15 -15
- data/test/acts_as_authentic_test/session_maintenance_test.rb +20 -13
- data/test/acts_as_authentic_test/single_access_test.rb +8 -8
- data/test/authenticates_many_test.rb +4 -4
- data/test/crypto_provider_test/aes256_test.rb +2 -2
- data/test/crypto_provider_test/scrypt_test.rb +1 -1
- data/test/crypto_provider_test/sha1_test.rb +3 -3
- data/test/crypto_provider_test/sha256_test.rb +1 -1
- data/test/crypto_provider_test/sha512_test.rb +2 -2
- data/test/gemfiles/Gemfile.rails-3.2.x +2 -2
- data/test/gemfiles/Gemfile.rails-5.0.x +6 -0
- data/test/i18n_test.rb +5 -5
- data/test/libs/affiliate.rb +2 -2
- data/test/libs/company.rb +1 -1
- 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/random_test.rb +5 -4
- data/test/session_test/activation_test.rb +5 -5
- data/test/session_test/active_record_trickery_test.rb +7 -5
- data/test/session_test/cookies_test.rb +8 -6
- data/test/session_test/existence_test.rb +19 -13
- data/test/session_test/http_auth_test.rb +0 -3
- data/test/session_test/id_test.rb +2 -2
- data/test/session_test/klass_test.rb +1 -1
- data/test/session_test/magic_columns_test.rb +0 -3
- data/test/session_test/magic_states_test.rb +11 -11
- data/test/session_test/params_test.rb +10 -10
- data/test/session_test/password_test.rb +4 -5
- data/test/session_test/perishability_test.rb +3 -3
- data/test/session_test/scopes_test.rb +8 -8
- data/test/session_test/session_test.rb +5 -4
- data/test/session_test/timeout_test.rb +8 -8
- data/test/session_test/unauthorized_record_test.rb +2 -2
- data/test/session_test/validation_test.rb +3 -3
- data/test/test_helper.rb +9 -5
- metadata +54 -24
- data/README.rdoc +0 -232
@@ -37,7 +37,6 @@ module Authlogic
|
|
37
37
|
# end
|
38
38
|
#
|
39
39
|
class RackAdapter < AbstractAdapter
|
40
|
-
|
41
40
|
def initialize(env)
|
42
41
|
# We use the Rack::Request object as the controller object.
|
43
42
|
# For this to work, we have to add some glue.
|
@@ -45,6 +44,7 @@ module Authlogic
|
|
45
44
|
|
46
45
|
request.instance_eval do
|
47
46
|
def request; self; end
|
47
|
+
|
48
48
|
def remote_ip; self.ip; end
|
49
49
|
end
|
50
50
|
|
@@ -55,9 +55,8 @@ module Authlogic
|
|
55
55
|
# Rack Requests stores cookies with not just the value, but also with flags and expire information in the hash.
|
56
56
|
# Authlogic does not like this, so we drop everything except the cookie value
|
57
57
|
def cookies
|
58
|
-
controller.cookies.map{|key, value_hash| {key => value_hash[:value]} }.inject(:merge) || {}
|
58
|
+
controller.cookies.map { |key, value_hash| { key => value_hash[:value] } }.inject(:merge) || {}
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
62
|
-
|
63
|
-
end
|
62
|
+
end
|
@@ -6,39 +6,51 @@ module Authlogic
|
|
6
6
|
# provides. Similar to how ActiveRecord has an adapter for MySQL, PostgreSQL, SQLite, etc.
|
7
7
|
class RailsAdapter < AbstractAdapter
|
8
8
|
class AuthlogicLoadedTooLateError < StandardError; end
|
9
|
-
|
9
|
+
|
10
10
|
def authenticate_with_http_basic(&block)
|
11
11
|
controller.authenticate_with_http_basic(&block)
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def cookies
|
15
15
|
controller.send(:cookies)
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def cookie_domain
|
19
19
|
@cookie_domain_key ||= Rails::VERSION::STRING >= '2.3' ? :domain : :session_domain
|
20
20
|
controller.request.session_options[@cookie_domain_key]
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def request_content_type
|
24
24
|
request.format.to_s
|
25
25
|
end
|
26
|
-
|
27
|
-
# Lets Authlogic know about the controller object via a before filter, AKA
|
26
|
+
|
27
|
+
# Lets Authlogic know about the controller object via a before filter, AKA
|
28
|
+
# "activates" authlogic.
|
28
29
|
module RailsImplementation
|
29
30
|
def self.included(klass) # :nodoc:
|
30
31
|
if defined?(::ApplicationController)
|
31
|
-
raise AuthlogicLoadedTooLateError.new(
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
raise AuthlogicLoadedTooLateError.new(
|
33
|
+
<<-EOS.strip_heredoc
|
34
|
+
Authlogic is trying to add a callback to ActionController::Base but
|
35
|
+
ApplicationController has already been loaded, so the callback won't
|
36
|
+
be copied into your application. Generally this is due to another gem or
|
37
|
+
plugin requiring your ApplicationController prematurely, such as the
|
38
|
+
resource_controller plugin. Please require Authlogic first, before these
|
39
|
+
other gems / plugins.
|
40
|
+
EOS
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
# In Rails 4.0.2, the *_filter methods were renamed to *_action.
|
45
|
+
if klass.respond_to? :prepend_before_action
|
46
|
+
klass.prepend_before_action :activate_authlogic
|
47
|
+
else
|
48
|
+
klass.prepend_before_filter :activate_authlogic
|
36
49
|
end
|
37
|
-
|
38
|
-
klass.prepend_before_filter :activate_authlogic
|
39
50
|
end
|
40
|
-
|
51
|
+
|
41
52
|
private
|
53
|
+
|
42
54
|
def activate_authlogic
|
43
55
|
Authlogic::Session::Base.controller = RailsAdapter.new(self)
|
44
56
|
end
|
@@ -2,28 +2,31 @@ require "openssl"
|
|
2
2
|
|
3
3
|
module Authlogic
|
4
4
|
module CryptoProviders
|
5
|
-
# This encryption method is reversible if you have the supplied key. So in order to
|
6
|
-
#
|
5
|
+
# This encryption method is reversible if you have the supplied key. So in order to
|
6
|
+
# use this encryption method you must supply it with a key first. In an initializer,
|
7
|
+
# or before your application initializes, you should do the following:
|
7
8
|
#
|
8
|
-
# Authlogic::CryptoProviders::AES256.key = "my really long and unique key,
|
9
|
+
# Authlogic::CryptoProviders::AES256.key = "my really long and unique key, preferably a bunch of random characters"
|
9
10
|
#
|
10
|
-
# My final comment is that this is a strong encryption method, but its main weakness
|
11
|
-
#
|
11
|
+
# My final comment is that this is a strong encryption method, but its main weakness
|
12
|
+
# is that it's reversible. If you do not need to reverse the hash then you should
|
13
|
+
# consider Sha512 or BCrypt instead.
|
12
14
|
#
|
13
|
-
# Keep your key in a safe place, some even say the key should be stored on a separate
|
14
|
-
# This won't hurt performance because the only time it will try and access the
|
15
|
-
#
|
16
|
-
#
|
15
|
+
# Keep your key in a safe place, some even say the key should be stored on a separate
|
16
|
+
# server. This won't hurt performance because the only time it will try and access the
|
17
|
+
# key on the separate server is during initialization, which only happens once. The
|
18
|
+
# reasoning behind this is if someone does compromise your server they won't have the
|
19
|
+
# key also. Basically, you don't want to store the key with the lock.
|
17
20
|
class AES256
|
18
21
|
class << self
|
19
22
|
attr_writer :key
|
20
|
-
|
23
|
+
|
21
24
|
def encrypt(*tokens)
|
22
25
|
aes.encrypt
|
23
26
|
aes.key = @key
|
24
27
|
[aes.update(tokens.join) + aes.final].pack("m").chomp
|
25
28
|
end
|
26
|
-
|
29
|
+
|
27
30
|
def matches?(crypted, *tokens)
|
28
31
|
aes.decrypt
|
29
32
|
aes.key = @key
|
@@ -31,8 +34,9 @@ module Authlogic
|
|
31
34
|
rescue OpenSSL::CipherError
|
32
35
|
false
|
33
36
|
end
|
34
|
-
|
37
|
+
|
35
38
|
private
|
39
|
+
|
36
40
|
def aes
|
37
41
|
raise ArgumentError.new("You must provide a key like #{name}.key = my_key before using the #{name}") if @key.blank?
|
38
42
|
@aes ||= OpenSSL::Cipher::Cipher.new("AES-256-ECB")
|
@@ -45,8 +45,11 @@ module Authlogic
|
|
45
45
|
# You are good to go!
|
46
46
|
class BCrypt
|
47
47
|
class << self
|
48
|
-
# This is the :cost option for the BCrpyt library. The higher the cost
|
49
|
-
#
|
48
|
+
# This is the :cost option for the BCrpyt library. The higher the cost
|
49
|
+
# the more secure it is and the longer is take the generate a hash. By
|
50
|
+
# default this is 10. Set this to any value >= the engine's minimum
|
51
|
+
# (currently 4), play around with it to get that perfect balance between
|
52
|
+
# security and performance.
|
50
53
|
def cost
|
51
54
|
@cost ||= 10
|
52
55
|
end
|
@@ -63,14 +66,16 @@ module Authlogic
|
|
63
66
|
::BCrypt::Password.create(join_tokens(tokens), :cost => cost)
|
64
67
|
end
|
65
68
|
|
66
|
-
# Does the hash match the tokens? Uses the same tokens that were used to
|
69
|
+
# Does the hash match the tokens? Uses the same tokens that were used to
|
70
|
+
# encrypt.
|
67
71
|
def matches?(hash, *tokens)
|
68
72
|
hash = new_from_hash(hash)
|
69
73
|
return false if hash.blank?
|
70
74
|
hash == join_tokens(tokens)
|
71
75
|
end
|
72
76
|
|
73
|
-
# This method is used as a flag to tell Authlogic to "resave" the
|
77
|
+
# This method is used as a flag to tell Authlogic to "resave" the
|
78
|
+
# password upon a successful login, using the new cost
|
74
79
|
def cost_matches?(hash)
|
75
80
|
hash = new_from_hash(hash)
|
76
81
|
if hash.blank?
|
@@ -81,6 +86,7 @@ module Authlogic
|
|
81
86
|
end
|
82
87
|
|
83
88
|
private
|
89
|
+
|
84
90
|
def join_tokens(tokens)
|
85
91
|
tokens.flatten.join
|
86
92
|
end
|
@@ -1,29 +1,29 @@
|
|
1
1
|
require "digest/md5"
|
2
|
-
|
2
|
+
|
3
3
|
module Authlogic
|
4
4
|
module CryptoProviders
|
5
|
-
# This class was made for the users transitioning from md5 based systems.
|
6
|
-
# I highly discourage using this crypto provider as it superbly inferior
|
5
|
+
# This class was made for the users transitioning from md5 based systems.
|
6
|
+
# I highly discourage using this crypto provider as it superbly inferior
|
7
7
|
# to your other options.
|
8
8
|
#
|
9
9
|
# Please use any other provider offered by Authlogic.
|
10
10
|
class MD5
|
11
11
|
class << self
|
12
12
|
attr_accessor :join_token
|
13
|
-
|
13
|
+
|
14
14
|
# The number of times to loop through the encryption.
|
15
15
|
def stretches
|
16
16
|
@stretches ||= 1
|
17
17
|
end
|
18
18
|
attr_writer :stretches
|
19
|
-
|
19
|
+
|
20
20
|
# Turns your raw password into a MD5 hash.
|
21
21
|
def encrypt(*tokens)
|
22
22
|
digest = tokens.flatten.join(join_token)
|
23
23
|
stretches.times { digest = Digest::MD5.hexdigest(digest) }
|
24
24
|
digest
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
# Does the crypted password match the tokens? Uses the same tokens that were used to encrypt.
|
28
28
|
def matches?(crypted, *tokens)
|
29
29
|
encrypt(*tokens) == crypted
|
@@ -31,4 +31,4 @@ module Authlogic
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
34
|
-
end
|
34
|
+
end
|
@@ -19,7 +19,7 @@ module Authlogic
|
|
19
19
|
# end
|
20
20
|
class SCrypt
|
21
21
|
class << self
|
22
|
-
DEFAULTS = {:key_len => 32, :salt_size => 8, :max_time => 0.2, :max_mem => 1024 * 1024, :max_memfrac => 0.5}
|
22
|
+
DEFAULTS = { :key_len => 32, :salt_size => 8, :max_time => 0.2, :max_mem => 1024 * 1024, :max_memfrac => 0.5 }
|
23
23
|
|
24
24
|
attr_writer :key_len, :salt_size, :max_time, :max_mem, :max_memfrac
|
25
25
|
# Key length - length in bytes of generated key, from 16 to 512.
|
@@ -49,7 +49,14 @@ module Authlogic
|
|
49
49
|
|
50
50
|
# Creates an SCrypt hash for the password passed.
|
51
51
|
def encrypt(*tokens)
|
52
|
-
::SCrypt::Password.create(
|
52
|
+
::SCrypt::Password.create(
|
53
|
+
join_tokens(tokens),
|
54
|
+
:key_len => key_len,
|
55
|
+
:salt_size => salt_size,
|
56
|
+
:max_mem => max_mem,
|
57
|
+
:max_memfrac => max_memfrac,
|
58
|
+
:max_time => max_time
|
59
|
+
)
|
53
60
|
end
|
54
61
|
|
55
62
|
# Does the hash match the tokens? Uses the same tokens that were used to encrypt.
|
@@ -60,6 +67,7 @@ module Authlogic
|
|
60
67
|
end
|
61
68
|
|
62
69
|
private
|
70
|
+
|
63
71
|
def join_tokens(tokens)
|
64
72
|
tokens.flatten.join
|
65
73
|
end
|
@@ -10,13 +10,13 @@ module Authlogic
|
|
10
10
|
@join_token ||= "--"
|
11
11
|
end
|
12
12
|
attr_writer :join_token
|
13
|
-
|
13
|
+
|
14
14
|
# The number of times to loop through the encryption. This is ten because that is what restful_authentication defaults to.
|
15
15
|
def stretches
|
16
16
|
@stretches ||= 10
|
17
17
|
end
|
18
18
|
attr_writer :stretches
|
19
|
-
|
19
|
+
|
20
20
|
# Turns your raw password into a Sha1 hash.
|
21
21
|
def encrypt(*tokens)
|
22
22
|
tokens = tokens.flatten
|
@@ -24,7 +24,7 @@ module Authlogic
|
|
24
24
|
stretches.times { digest = Digest::SHA1.hexdigest([digest, *tokens].join(join_token)) }
|
25
25
|
digest
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
# Does the crypted password match the tokens? Uses the same tokens that were used to encrypt.
|
29
29
|
def matches?(crypted, *tokens)
|
30
30
|
encrypt(*tokens) == crypted
|
@@ -26,20 +26,20 @@ module Authlogic
|
|
26
26
|
class Sha256
|
27
27
|
class << self
|
28
28
|
attr_accessor :join_token
|
29
|
-
|
29
|
+
|
30
30
|
# The number of times to loop through the encryption.
|
31
31
|
def stretches
|
32
32
|
@stretches ||= 20
|
33
33
|
end
|
34
34
|
attr_writer :stretches
|
35
|
-
|
35
|
+
|
36
36
|
# Turns your raw password into a Sha256 hash.
|
37
37
|
def encrypt(*tokens)
|
38
38
|
digest = tokens.flatten.join(join_token)
|
39
39
|
stretches.times { digest = Digest::SHA256.hexdigest(digest) }
|
40
40
|
digest
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
# Does the crypted password match the tokens? Uses the same tokens that were used to encrypt.
|
44
44
|
def matches?(crypted, *tokens)
|
45
45
|
encrypt(*tokens) == crypted
|
@@ -26,20 +26,20 @@ module Authlogic
|
|
26
26
|
class Sha512
|
27
27
|
class << self
|
28
28
|
attr_accessor :join_token
|
29
|
-
|
29
|
+
|
30
30
|
# The number of times to loop through the encryption. This is twenty because that is what restful_authentication defaults to.
|
31
31
|
def stretches
|
32
32
|
@stretches ||= 20
|
33
33
|
end
|
34
34
|
attr_writer :stretches
|
35
|
-
|
35
|
+
|
36
36
|
# Turns your raw password into a Sha512 hash.
|
37
37
|
def encrypt(*tokens)
|
38
38
|
digest = tokens.flatten.join(join_token)
|
39
39
|
stretches.times { digest = Digest::SHA512.hexdigest(digest) }
|
40
40
|
digest
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
# Does the crypted password match the tokens? Uses the same tokens that were used to encrypt.
|
44
44
|
def matches?(crypted, *tokens)
|
45
45
|
encrypt(*tokens) == crypted
|
@@ -47,4 +47,4 @@ module Authlogic
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
50
|
-
end
|
50
|
+
end
|
@@ -3,37 +3,37 @@ module Authlogic
|
|
3
3
|
module CryptoProviders
|
4
4
|
class Wordpress
|
5
5
|
class << self
|
6
|
-
ITOA64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
|
6
|
+
ITOA64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
|
7
7
|
|
8
8
|
def matches?(crypted, *tokens)
|
9
|
-
stretches = 1 << ITOA64.index(crypted[3,1])
|
10
|
-
plain, salt = *tokens
|
11
|
-
hashed = Digest::MD5.digest(salt+plain)
|
9
|
+
stretches = 1 << ITOA64.index(crypted[3, 1])
|
10
|
+
plain, salt = *tokens
|
11
|
+
hashed = Digest::MD5.digest(salt + plain)
|
12
12
|
stretches.times do |i|
|
13
|
-
hashed = Digest::MD5.digest(hashed+plain)
|
13
|
+
hashed = Digest::MD5.digest(hashed + plain)
|
14
14
|
end
|
15
|
-
crypted[0,12]+encode_64(hashed, 16) == crypted
|
15
|
+
crypted[0, 12] + encode_64(hashed, 16) == crypted
|
16
16
|
end
|
17
17
|
|
18
18
|
def encode_64(input, length)
|
19
|
-
output = ""
|
19
|
+
output = ""
|
20
20
|
i = 0
|
21
21
|
while i < length
|
22
|
-
value = input[i]
|
23
|
-
i+=1
|
22
|
+
value = input[i]
|
23
|
+
i += 1
|
24
24
|
break if value.nil?
|
25
25
|
output += ITOA64[value & 0x3f, 1]
|
26
26
|
value |= input[i] << 8 if i < length
|
27
27
|
output += ITOA64[(value >> 6) & 0x3f, 1]
|
28
28
|
|
29
|
-
i+=1
|
29
|
+
i += 1
|
30
30
|
break if i >= length
|
31
31
|
value |= input[i] << 16 if i < length
|
32
|
-
output += ITOA64[(value >> 12) & 0x3f,1]
|
32
|
+
output += ITOA64[(value >> 12) & 0x3f, 1]
|
33
33
|
|
34
|
-
i+=1
|
34
|
+
i += 1
|
35
35
|
break if i >= length
|
36
|
-
output += ITOA64[(value >> 18) & 0x3f,1]
|
36
|
+
output += ITOA64[(value >> 18) & 0x3f, 1]
|
37
37
|
end
|
38
38
|
output
|
39
39
|
end
|
data/lib/authlogic/i18n.rb
CHANGED
@@ -1,28 +1,32 @@
|
|
1
1
|
require "authlogic/i18n/translator"
|
2
2
|
|
3
3
|
module Authlogic
|
4
|
-
# This class allows any message in Authlogic to use internationalization. In earlier
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
4
|
+
# This class allows any message in Authlogic to use internationalization. In earlier
|
5
|
+
# versions of Authlogic each message was translated via configuration. This cluttered up
|
6
|
+
# the configuration and cluttered up Authlogic. So all translation has been extracted
|
7
|
+
# out into this class. Now all messages pass through this class, making it much easier
|
8
|
+
# to implement in I18n library / plugin you want. Use this as a layer that sits between
|
9
|
+
# Authlogic and whatever I18n library you want to use.
|
8
10
|
#
|
9
|
-
# By default this uses the rails I18n library, if it exists. If it
|
10
|
-
#
|
11
|
+
# By default this uses the rails I18n library, if it exists. If it doesn't exist it just
|
12
|
+
# returns the default English message. The Authlogic I18n class works EXACTLY like the
|
13
|
+
# rails I18n class. This is because the arguments are delegated to this class.
|
11
14
|
#
|
12
15
|
# Here is how all messages are translated internally with Authlogic:
|
13
16
|
#
|
14
17
|
# Authlogic::I18n.t('error_messages.password_invalid', :default => "is invalid")
|
15
18
|
#
|
16
|
-
# If you use a different I18n library just replace the build-in I18n::Translator class
|
19
|
+
# If you use a different I18n library just replace the build-in I18n::Translator class
|
20
|
+
# with your own. For example:
|
17
21
|
#
|
18
22
|
# class MyAuthlogicI18nTranslator
|
19
23
|
# def translate(key, options = {})
|
20
24
|
# # you will have key which will be something like: "error_messages.password_invalid"
|
21
|
-
# # you will also have options[:default], which will be the default
|
25
|
+
# # you will also have options[:default], which will be the default English version of the message
|
22
26
|
# # do whatever you want here with the arguments passed to you.
|
23
27
|
# end
|
24
28
|
# end
|
25
|
-
#
|
29
|
+
#
|
26
30
|
# Authlogic::I18n.translator = MyAuthlogicI18nTranslator.new
|
27
31
|
#
|
28
32
|
# That it's! Here is a complete list of the keys that are passed. Just define these however you wish:
|
@@ -31,7 +35,7 @@ module Authlogic
|
|
31
35
|
# error_messages:
|
32
36
|
# login_blank: can not be blank
|
33
37
|
# login_not_found: is not valid
|
34
|
-
# login_invalid: should use only letters, numbers, spaces, and .-_
|
38
|
+
# login_invalid: should use only letters, numbers, spaces, and .-_@+ please.
|
35
39
|
# consecutive_failed_logins_limit_exceeded: Consecutive failed logins limit exceeded, account is disabled.
|
36
40
|
# email_invalid: should look like an email address.
|
37
41
|
# email_invalid_international: should look like an international email address.
|
@@ -53,29 +57,31 @@ module Authlogic
|
|
53
57
|
module I18n
|
54
58
|
@@scope = :authlogic
|
55
59
|
@@translator = nil
|
56
|
-
|
60
|
+
|
57
61
|
class << self
|
58
62
|
# Returns the current scope. Defaults to :authlogic
|
59
63
|
def scope
|
60
64
|
@@scope
|
61
65
|
end
|
62
|
-
|
66
|
+
|
63
67
|
# Sets the current scope. Used to set a custom scope.
|
64
68
|
def scope=(scope)
|
65
69
|
@@scope = scope
|
66
70
|
end
|
67
|
-
|
71
|
+
|
68
72
|
# Returns the current translator. Defaults to +Translator+.
|
69
73
|
def translator
|
70
74
|
@@translator ||= Translator.new
|
71
75
|
end
|
72
|
-
|
76
|
+
|
73
77
|
# Sets the current translator. Used to set a custom translator.
|
74
78
|
def translator=(translator)
|
75
79
|
@@translator = translator
|
76
80
|
end
|
77
|
-
|
78
|
-
# All message translation is passed to this method. The first argument is the key
|
81
|
+
|
82
|
+
# All message translation is passed to this method. The first argument is the key
|
83
|
+
# for the message. The second is options, see the rails I18n library for a list of
|
84
|
+
# options used.
|
79
85
|
def translate(key, options = {})
|
80
86
|
translator.translate key, { :scope => I18n.scope }.merge(options)
|
81
87
|
end
|