authlogic 1.2.2 → 1.3.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.

@@ -1,4 +1,11 @@
1
- == 1.2.2 released 2008-11-19
1
+ == 1.3.0 released 2008-11-20
2
+
3
+ * BREAKS BACKWARDS COMPATIBILITY: changed the confirm_password field to password_confirmation for acts_as_authentic, since the rails validates_confirmation_of handles creating this attribute.
4
+ * BREAKS BACKWARDS COMPATIBILITY: Cleaned up all of the validation configuration for acts_as_authentic, as well as the documentation that goes with it, you can accomplish the same things as before, but this is much more flexible and much more organized.
5
+ * Got rid of simple delegator for the abstract controller, apparently this has performance issues.
6
+ * Cleaned up validations to assume ActiveRecord dirty attributes are present, I think this is a safe assumption.
7
+
8
+ == 1.2.2 released 2008-11-20
2
9
 
3
10
  * Added allow_blank_login_and_password_field and allow_blank_email_field options to acts_as_authentic, which allows you to have alternative logins, such as OpenID
4
11
  * In the session Authlogic now also stores the record id. We use this id to find the record and then check the token against the record, thus allowing for quicker database lookups, while getting the same security.
data/Manifest CHANGED
@@ -21,7 +21,6 @@ lib/authlogic/session/callbacks.rb
21
21
  lib/authlogic/session/config.rb
22
22
  lib/authlogic/session/cookies.rb
23
23
  lib/authlogic/session/errors.rb
24
- lib/authlogic/session/openid.rb
25
24
  lib/authlogic/session/params.rb
26
25
  lib/authlogic/session/perishability.rb
27
26
  lib/authlogic/session/scopes.rb
@@ -73,7 +73,8 @@ Authlogic makes this a reality. This is just the tip of the ice berg. Keep readi
73
73
  * <b>Documentation:</b> http://authlogic.rubyforge.org
74
74
  * <b>Tutorial: Authlogic basic setup:</b> http://www.binarylogic.com/2008/11/3/tutorial-authlogic-basic-setup
75
75
  * <b>Tutorial: Reset passwords with Authlogic the RESTful way:</b> http://www.binarylogic.com/2008/11/16/tutorial-reset-passwords-with-authlogic
76
- * <b>Live example of the setup tutorial above (with source):</b> http://authlogic_example.binarylogic.com
76
+ * <b>Tutorial: Using OpenID with Authlogic:</b> http://www.binarylogic.com/2008/11/21/tutorial-using-openid-with-authlogic
77
+ * <b>Live example of the setup tutorial above (with source):</b> http://authlogicexample.binarylogic.com
77
78
  * <b>Bugs / feature suggestions:</b> http://binarylogic.lighthouseapp.com/projects/18752-authlogic
78
79
 
79
80
  == Install and use
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{authlogic}
5
- s.version = "1.2.2"
5
+ s.version = "1.3.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Ben Johnson of Binary Logic"]
9
- s.date = %q{2008-11-20}
9
+ s.date = %q{2008-11-21}
10
10
  s.description = %q{A clean, simple, and unobtrusive ruby authentication solution.}
11
11
  s.email = %q{bjohnson@binarylogic.com}
12
- s.extra_rdoc_files = ["CHANGELOG.rdoc", "lib/authlogic/controller_adapters/abstract_adapter.rb", "lib/authlogic/controller_adapters/merb_adapter.rb", "lib/authlogic/controller_adapters/rails_adapter.rb", "lib/authlogic/crypto_providers/sha1.rb", "lib/authlogic/crypto_providers/sha512.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/config.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/credentials.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/logged_in.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/perishability.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/persistence.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/session_maintenance.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/single_access.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic.rb", "lib/authlogic/orm_adapters/active_record_adapter/authenticates_many.rb", "lib/authlogic/session/active_record_trickery.rb", "lib/authlogic/session/authenticates_many_association.rb", "lib/authlogic/session/base.rb", "lib/authlogic/session/callbacks.rb", "lib/authlogic/session/config.rb", "lib/authlogic/session/cookies.rb", "lib/authlogic/session/errors.rb", "lib/authlogic/session/openid.rb", "lib/authlogic/session/params.rb", "lib/authlogic/session/perishability.rb", "lib/authlogic/session/scopes.rb", "lib/authlogic/session/session.rb", "lib/authlogic/version.rb", "lib/authlogic.rb", "README.rdoc"]
13
- s.files = ["CHANGELOG.rdoc", "init.rb", "lib/authlogic/controller_adapters/abstract_adapter.rb", "lib/authlogic/controller_adapters/merb_adapter.rb", "lib/authlogic/controller_adapters/rails_adapter.rb", "lib/authlogic/crypto_providers/sha1.rb", "lib/authlogic/crypto_providers/sha512.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/config.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/credentials.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/logged_in.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/perishability.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/persistence.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/session_maintenance.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/single_access.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic.rb", "lib/authlogic/orm_adapters/active_record_adapter/authenticates_many.rb", "lib/authlogic/session/active_record_trickery.rb", "lib/authlogic/session/authenticates_many_association.rb", "lib/authlogic/session/base.rb", "lib/authlogic/session/callbacks.rb", "lib/authlogic/session/config.rb", "lib/authlogic/session/cookies.rb", "lib/authlogic/session/errors.rb", "lib/authlogic/session/openid.rb", "lib/authlogic/session/params.rb", "lib/authlogic/session/perishability.rb", "lib/authlogic/session/scopes.rb", "lib/authlogic/session/session.rb", "lib/authlogic/version.rb", "lib/authlogic.rb", "Manifest", "MIT-LICENSE", "Rakefile", "README.rdoc", "shoulda_macros/authlogic.rb", "test/fixtures/companies.yml", "test/fixtures/employees.yml", "test/fixtures/projects.yml", "test/fixtures/users.yml", "test/libs/aes128_crypto_provider.rb", "test/libs/mock_controller.rb", "test/libs/mock_cookie_jar.rb", "test/libs/mock_request.rb", "test/libs/ordered_hash.rb", "test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/config_test.rb", "test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/credentials_test.rb", "test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/logged_in_test.rb", "test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/perishability_test.rb", "test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/persistence_test.rb", "test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/session_maintenance_test.rb", "test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/single_access_test.rb", "test/orm_adapters_tests/active_record_adapter_tests/authenticates_many_test.rb", "test/session_tests/active_record_trickery_test.rb", "test/session_tests/authenticates_many_association_test.rb", "test/session_tests/base_test.rb", "test/session_tests/config_test.rb", "test/session_tests/cookies_test.rb", "test/session_tests/params_test.rb", "test/session_tests/perishability_test.rb", "test/session_tests/scopes_test.rb", "test/session_tests/session_test.rb", "test/test_helper.rb", "authlogic.gemspec"]
12
+ s.extra_rdoc_files = ["CHANGELOG.rdoc", "lib/authlogic/controller_adapters/abstract_adapter.rb", "lib/authlogic/controller_adapters/merb_adapter.rb", "lib/authlogic/controller_adapters/rails_adapter.rb", "lib/authlogic/crypto_providers/sha1.rb", "lib/authlogic/crypto_providers/sha512.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/config.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/credentials.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/logged_in.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/perishability.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/persistence.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/session_maintenance.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/single_access.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic.rb", "lib/authlogic/orm_adapters/active_record_adapter/authenticates_many.rb", "lib/authlogic/session/active_record_trickery.rb", "lib/authlogic/session/authenticates_many_association.rb", "lib/authlogic/session/base.rb", "lib/authlogic/session/callbacks.rb", "lib/authlogic/session/config.rb", "lib/authlogic/session/cookies.rb", "lib/authlogic/session/errors.rb", "lib/authlogic/session/params.rb", "lib/authlogic/session/perishability.rb", "lib/authlogic/session/scopes.rb", "lib/authlogic/session/session.rb", "lib/authlogic/version.rb", "lib/authlogic.rb", "README.rdoc"]
13
+ s.files = ["CHANGELOG.rdoc", "init.rb", "lib/authlogic/controller_adapters/abstract_adapter.rb", "lib/authlogic/controller_adapters/merb_adapter.rb", "lib/authlogic/controller_adapters/rails_adapter.rb", "lib/authlogic/crypto_providers/sha1.rb", "lib/authlogic/crypto_providers/sha512.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/config.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/credentials.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/logged_in.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/perishability.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/persistence.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/session_maintenance.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/single_access.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic.rb", "lib/authlogic/orm_adapters/active_record_adapter/authenticates_many.rb", "lib/authlogic/session/active_record_trickery.rb", "lib/authlogic/session/authenticates_many_association.rb", "lib/authlogic/session/base.rb", "lib/authlogic/session/callbacks.rb", "lib/authlogic/session/config.rb", "lib/authlogic/session/cookies.rb", "lib/authlogic/session/errors.rb", "lib/authlogic/session/params.rb", "lib/authlogic/session/perishability.rb", "lib/authlogic/session/scopes.rb", "lib/authlogic/session/session.rb", "lib/authlogic/version.rb", "lib/authlogic.rb", "Manifest", "MIT-LICENSE", "Rakefile", "README.rdoc", "shoulda_macros/authlogic.rb", "test/fixtures/companies.yml", "test/fixtures/employees.yml", "test/fixtures/projects.yml", "test/fixtures/users.yml", "test/libs/aes128_crypto_provider.rb", "test/libs/mock_controller.rb", "test/libs/mock_cookie_jar.rb", "test/libs/mock_request.rb", "test/libs/ordered_hash.rb", "test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/config_test.rb", "test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/credentials_test.rb", "test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/logged_in_test.rb", "test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/perishability_test.rb", "test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/persistence_test.rb", "test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/session_maintenance_test.rb", "test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/single_access_test.rb", "test/orm_adapters_tests/active_record_adapter_tests/authenticates_many_test.rb", "test/session_tests/active_record_trickery_test.rb", "test/session_tests/authenticates_many_association_test.rb", "test/session_tests/base_test.rb", "test/session_tests/config_test.rb", "test/session_tests/cookies_test.rb", "test/session_tests/params_test.rb", "test/session_tests/perishability_test.rb", "test/session_tests/scopes_test.rb", "test/session_tests/session_test.rb", "test/test_helper.rb", "authlogic.gemspec"]
14
14
  s.has_rdoc = true
15
15
  s.homepage = %q{http://github.com/binarylogic/authlogic}
16
16
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Authlogic", "--main", "README.rdoc"]
@@ -1,10 +1,17 @@
1
1
  module Authlogic
2
2
  module ControllerAdapters # :nodoc:
3
3
  # = Abstract Adapter
4
+ #
4
5
  # Allows you to use Authlogic in any framework you want, not just rails. See tha RailsAdapter for an example of how to adapter Authlogic to work with your framework.
5
- class AbstractAdapter < SimpleDelegator
6
+ class AbstractAdapter
7
+ attr_accessor :controller
8
+
9
+ def initialize(controller)
10
+ self.controller = controller
11
+ end
12
+
6
13
  def authenticate_with_http_basic(&block)
7
- @auth = Rack::Auth::Basic::Request.new(__getobj__.request.env)
14
+ @auth = Rack::Auth::Basic::Request.new(controller.request.env)
8
15
  if @auth.provided? and @auth.basic?
9
16
  block.call(*@auth.credentials)
10
17
  else
@@ -12,9 +19,30 @@ module Authlogic
12
19
  end
13
20
  end
14
21
 
22
+ def cookies
23
+ controller.cookies
24
+ end
25
+
26
+ def params
27
+ controller.params
28
+ end
29
+
30
+ def request
31
+ controller.request
32
+ end
33
+
15
34
  def request_content_type
16
35
  request.content_type
17
36
  end
37
+
38
+ def session
39
+ controller.session
40
+ end
41
+
42
+ private
43
+ def method_missing(id, *args, &block)
44
+ controller.send(id, *args, &block)
45
+ end
18
46
  end
19
47
  end
20
48
  end
@@ -5,11 +5,11 @@ module Authlogic
5
5
  # provides. Similar to how ActiveRecord has an adapter for MySQL, PostgreSQL, SQLite, etc.
6
6
  class RailsAdapter < AbstractAdapter
7
7
  def authenticate_with_http_basic(&block)
8
- __getobj__.authenticate_with_http_basic(&block)
8
+ controller.authenticate_with_http_basic(&block)
9
9
  end
10
10
 
11
11
  def cookies
12
- __getobj__.send(:cookies)
12
+ controller.send(:cookies)
13
13
  end
14
14
 
15
15
  def request_content_type
@@ -14,7 +14,7 @@ module Authlogic
14
14
  #
15
15
  # * <tt>acts_as_authentic_config</tt> - returns a hash of the acts_as_authentic configuration, including the defaults
16
16
  #
17
- # === Options
17
+ # === General Options
18
18
  #
19
19
  # * <tt>session_class</tt> - default: "#{name}Session",
20
20
  # This is the related session class. A lot of the configuration will be based off of the configuration values of this class.
@@ -22,9 +22,6 @@ module Authlogic
22
22
  # * <tt>crypto_provider</tt> - default: Authlogic::CryptoProviders::Sha512,
23
23
  # This is the class that provides your encryption. By default Authlogic provides its own crypto provider that uses Sha512 encrypton.
24
24
  #
25
- # * <tt>validate_fields</tt> - default: true,
26
- # Tells Authlogic if it should validate ANY of the fields: login_field, email_field, and password_field. If set to false, no validations will be set for any of these fields.
27
- #
28
25
  # * <tt>login_field</tt> - default: :login, :username, or :email, depending on which column is present, if none are present defaults to :login
29
26
  # The name of the field used for logging in. Only specify if you aren't using any of the defaults.
30
27
  #
@@ -32,56 +29,24 @@ module Authlogic
32
29
  # Tells authlogic how to validation the field, what regex to use, etc. If the field name is email it will automatically use :email,
33
30
  # otherwise it uses :login.
34
31
  #
35
- # * <tt>validate_login_field</tt> - default: true,
36
- # Tells authlogic if it should validate the :login_field. If set to false, no validations will be set for this field at all.
37
- #
38
- # * <tt>login_field_regex</tt> - default: if :login_field_type is :email then typical email regex, otherwise typical login regex.
39
- # This is used in validates_format_of for the :login_field.
40
- #
41
- # * <tt>login_field_regex_failed_message</tt> - the message to use when the validates_format_of for the login field fails. This depends on if you are
42
- # performing :email or :login regex.
32
+ # * <tt>password_field</tt> - default: :password,
33
+ # This is the name of the field to set the password, *NOT* the field the encrypted password is stored. Defaults the what the configuration
34
+ #
35
+ # * <tt>crypted_password_field</tt> - default: :crypted_password, :encrypted_password, :password_hash, :pw_hash, depends on which columns are present, if none are present defaults to nil
36
+ # The name of the database field where your encrypted password is stored.
43
37
  #
44
- # * <tt>allow_blank_login_and_password_fields</tt> - default: false,
45
- # Tells authlogic if it should allow blank values for the login and password. This is useful is you provide alternate authentication methods, such as OpenID.
38
+ # * <tt>password_salt_field</tt> - default: :password_salt, :pw_salt, or :salt, depending on which column is present, defaults to :password_salt if none are present,
39
+ # This is the name of the field in your database that stores your password salt.
46
40
  #
47
41
  # * <tt>email_field</tt> - default: :email, depending on if it is present, if :email is not present defaults to nil
48
42
  # The name of the field used to store the email address. Only specify this if you arent using this as your :login_field.
49
- #
50
- # * <tt>validate_email_field</tt> - default: true,
51
- # Tells Authlogic if it should validate the email field. If set to false, no validations will be set for this field at all.
52
- #
53
- # * <tt>email_field_regex</tt> - default: type email regex
54
- # This is used in validates_format_of for the :email_field.
55
- #
56
- # * <tt>email_field_regex_failed_message</tt> - the message to use when the validates_format_of for the email field fails.
57
- #
58
- # * <tt>allow_blank_email_field</tt> - default: false,
59
- # Tells Authlogic if it should allow blank values for the email address.
60
- #
61
- # * <tt>change_single_access_token_with_password</tt> - default: false,
62
- # When a user changes their password do you want the single access token to change as well? That's what this configuration option is all about.
63
43
  #
64
44
  # * <tt>single_access_token_field</tt> - default: :single_access_token, :feed_token, or :feeds_token, depending on which column is present, if none are present defaults to nil
65
45
  # This is the name of the field to login with single access, mainly used for private feed access. Only specify if the name of the field is different
66
46
  # then the defaults. See the "Single Access" section in the README for more details on how single access works.
67
47
  #
68
- # * <tt>password_field</tt> - default: :password,
69
- # This is the name of the field to set the password, *NOT* the field the encrypted password is stored. Defaults the what the configuration
70
- #
71
- # * <tt>validate_password_field</tt> - default: :password,
72
- # Tells authlogic if it should validate the :password_field. If set to false, no validations will be set for this field at all.
73
- #
74
- # * <tt>password_blank_message</tt> - default: "can not be blank",
75
- # The error message used when the password is left blank.
76
- #
77
- # * <tt>confirm_password_did_not_match_message</tt> - default: "did not match",
78
- # The error message used when the confirm password does not match the password
79
- #
80
- # * <tt>crypted_password_field</tt> - default: :crypted_password, :encrypted_password, :password_hash, :pw_hash, depends on which columns are present, if none are present defaults to nil
81
- # The name of the database field where your encrypted password is stored.
82
- #
83
- # * <tt>password_salt_field</tt> - default: :password_salt, :pw_salt, or :salt, depending on which column is present, defaults to :password_salt if none are present,
84
- # This is the name of the field in your database that stores your password salt.
48
+ # * <tt>change_single_access_token_with_password</tt> - default: false,
49
+ # When a user changes their password do you want the single access token to change as well? That's what this configuration option is all about.
85
50
  #
86
51
  # * <tt>perishable_token_field</tt> - default: :perishable_token, :password_reset_token, :pw_reset_token, :reset_password_token, or :reset_pw_token, depending on which column is present, if none are present defaults to nil
87
52
  # This is the name of the field in your database that stores your perishable token. The token you should use to confirm your users or allow a password reset. Authlogic takes care
@@ -98,9 +63,6 @@ module Authlogic
98
63
  # session. This way you have complete control of when sessions expire and you don't have to change passwords to expire sessions. This also
99
64
  # ensures that stale sessions can not be persisted. By stale, I mean sessions that are logged in using an outdated password.
100
65
  #
101
- # * <tt>scope</tt> - default: nil,
102
- # This scopes validations. If all of your users belong to an account you might want to scope everything to the account. Just pass :account_id
103
- #
104
66
  # * <tt>logged_in_timeout</tt> - default: 10.minutes,
105
67
  # This is a nifty feature to tell if a user is logged in or not. It's based on activity. So if the user in inactive longer than
106
68
  # the value passed here they are assumed "logged out". This uses the last_request_at field, this field must be present for this option to take effect.
@@ -110,6 +72,60 @@ module Authlogic
110
72
  # Should be an array of ids. See the Authlogic::Session documentation for information on ids. The order is important.
111
73
  # The first id should be your main session, the session they need to log into first. This is generally nil. When you don't specify an id
112
74
  # in your session you are really just inexplicitly saying you want to use the id of nil.
75
+ #
76
+ # === Validation Options
77
+ #
78
+ # * <tt>validate_fields</tt> - default: true,
79
+ # Tells Authlogic if it should validate ANY of the fields: login_field, email_field, and password_field. If set to false, no validations will be set for any of these fields.
80
+ #
81
+ # * <tt>validate_login_field</tt> - default: true,
82
+ # Tells authlogic if it should validate the :login_field. If set to false, no validations will be set for this field at all.
83
+ #
84
+ # * <tt>validate_email_field</tt> - default: true,
85
+ # Tells Authlogic if it should validate the email field. If set to false, no validations will be set for this field at all.
86
+ #
87
+ # * <tt>validate_password_field</tt> - default: :password,
88
+ # Tells authlogic if it should validate the :password_field. If set to false, no validations will be set for this field at all.
89
+ #
90
+ # * <tt>scope</tt> - default: nil,
91
+ # This scopes validations. If all of your users belong to an account you might want to scope everything to the account. Just pass :account_id
92
+ #
93
+ # * <tt>validation_options</tt> - default: {},
94
+ # Options to pass to ALL validations. These are the options ActiveRecord supplies with their validation methods, see the ActiveRecord documentation for more details.
95
+ #
96
+ # * <tt>login_field_validation_options</tt> - default: {},
97
+ # The same as :validation_options but these are only applied to validations that pertain to the :login_field
98
+ #
99
+ # * <tt>login_field_validates_length_of_options</tt> - default: :login_field_type == :email ? {:within => 6..100} : {:within => 2..100},
100
+ # These options are applied to the validates_length_of call for the :login_field
101
+ #
102
+ # * <tt>login_field_validates_format_of_options</tt> - default: :login_field_type == :email ? {:with => standard_email_regex, :message => "should look like an email address."} : {:with => standard_login_regex, :message => "should use only letters, numbers, spaces, and .-_@ please."},
103
+ # These options are applied to the validates_format_of call for the :login_field
104
+ #
105
+ # * <tt>login_field_validates_uniqueness_of_options</tt> - default: {:allow_blank => true},
106
+ # These options are applied to the validates_uniqueness_of call for the :login_field, the :allow_blank => true just prevents the error message when you have options login fields
107
+ # such as an OpenID field. The other validations will make sure the field is not actaully blank.
108
+ #
109
+ # * <tt>password_field_validation_options</tt> - default: {},
110
+ # The same as :validation_options but these are only applied to validations that pertain to the :password_field
111
+ #
112
+ # * <tt>password_field_validates_presence_of_options</tt> - default: {:on => :create},
113
+ # These options are applied to the validates_presence_of call for the :password_field
114
+ #
115
+ # * <tt>login_field_validates_confirmation_of_options</tt> - default: {},
116
+ # These options are applied to the validates_confirmation_of call for the :password_field
117
+ #
118
+ # * <tt>email_field_validation_options</tt> - default: {},
119
+ # The same as :validation_options but these are only applied to validations that pertain to the :email_field
120
+ #
121
+ # * <tt>email_field_validates_length_of_options</tt> - default: same as :login_field if :login_field_type == :email,
122
+ # These options are applied to the validates_length_of call for the :email_field
123
+ #
124
+ # * <tt>email_field_validates_format_of_options</tt> - default: same as :login_field if :login_field_type == :email,
125
+ # These options are applied to the validates_format_of call for the :email_field
126
+ #
127
+ # * <tt>email_field_validates_uniqueness_of_options</tt> - default: same as :login_field if :login_field_type == :email,
128
+ # These options are applied to the validates_uniqueness_of call for the :email_field
113
129
  module Config
114
130
  def first_column_to_exist(*columns_to_check) # :nodoc:
115
131
  columns_to_check.each { |column_name| return column_name.to_sym if column_names.include?(column_name.to_s) }
@@ -124,39 +140,17 @@ module Authlogic
124
140
  return
125
141
  end
126
142
 
143
+ # Base configuration
127
144
  options[:session_class] ||= "#{name}Session"
128
145
  options[:crypto_provider] ||= CryptoProviders::Sha512
129
- options[:validate_fields] = true unless options.key?(:validate_fields)
130
146
  options[:login_field] ||= first_column_to_exist(:login, :username, :email)
131
147
  options[:login_field_type] ||= options[:login_field] == :email ? :email : :login
132
- options[:validate_login_field] = true unless options.key?(:validate_login_field)
133
- options[:email_field] = first_column_to_exist(nil, :email) unless options.key?(:email_field)
134
- options[:email_field] = nil if options[:email_field] == options[:login_field]
135
- options[:validate_email_field] = true unless options.key?(:validate_email_field)
136
- options[:allow_blank_login_and_password]
137
-
138
- email_name_regex = '[\w\.%\+\-]+'
139
- domain_head_regex = '(?:[A-Z0-9\-]+\.)+'
140
- domain_tld_regex = '(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|jobs|museum)'
141
- options[:email_field_regex] ||= /\A#{email_name_regex}@#{domain_head_regex}#{domain_tld_regex}\z/i
142
- options[:email_field_regex_failed_message] ||= "should look like an email address."
143
-
144
- case options[:login_field_type]
145
- when :email
146
- options[:login_field_regex] ||= options[:email_field_regex]
147
- options[:login_field_regex_failed_message] ||= options[:email_field_regex_failed_message]
148
- else
149
- options[:login_field_regex] ||= /\A\w[\w\.\-_@ ]+\z/
150
- options[:login_field_regex_failed_message] ||= "should use only letters, numbers, spaces, and .-_@ please."
151
- end
152
-
153
148
  options[:password_field] ||= :password
154
- options[:validate_password_field] = true unless options.key?(:validate_password_field)
155
-
156
- options[:password_blank_message] ||= "can not be blank"
157
- options[:confirm_password_did_not_match_message] ||= "did not match"
158
149
  options[:crypted_password_field] ||= first_column_to_exist(:crypted_password, :encrypted_password, :password_hash, :pw_hash)
159
150
  options[:password_salt_field] ||= first_column_to_exist(:password_salt, :pw_salt, :salt)
151
+
152
+ options[:email_field] = first_column_to_exist(nil, :email) unless options.key?(:email_field)
153
+ options[:email_field] = nil if options[:email_field] == options[:login_field]
160
154
  options[:persistence_token_field] ||= options[:remember_token_field] || first_column_to_exist(:persistence_token, :remember_token, :cookie_token)
161
155
  options[:single_access_token_field] ||= first_column_to_exist(nil, :single_access_token, :feed_token, :feeds_token)
162
156
  options[:perishable_token_field] ||= options[:password_reset_token_field] || first_column_to_exist(nil, :perishable_token, :password_reset_token, :pw_reset_token, :reset_password_token, :reset_pw_token, :activation_token)
@@ -165,6 +159,30 @@ module Authlogic
165
159
  options[:logged_in_timeout] ||= 10.minutes
166
160
  options[:logged_in_timeout] = options[:logged_in_timeout].to_i
167
161
  options[:session_ids] ||= [nil]
162
+
163
+ # Validation configuration
164
+ options[:validate_fields] = true unless options.key?(:validate_fields)
165
+ options[:validate_login_field] = true unless options.key?(:validate_login_field)
166
+ options[:validate_password_field] = true unless options.key?(:validate_password_field)
167
+ options[:validate_email_field] = true unless options.key?(:validate_email_field)
168
+
169
+ options[:validation_options] ||= {}
170
+
171
+ [:login, :password, :email].each do |field_name|
172
+ field_key = "#{field_name}_field_validation_options".to_sym
173
+ options[field_key] = options[:validation_options].merge(options[field_key] || {})
174
+
175
+ validation_types = field_name == :password ? [:presence, :confirmation] : [:length, :format, :uniqueness]
176
+ validation_types.each do |validation_type|
177
+ validation_key = "#{field_name}_field_validates_#{validation_type}_of_options".to_sym
178
+ options[validation_key] = options[field_key].merge(options[validation_key] || {})
179
+ end
180
+ end
181
+
182
+ if options[:scope]
183
+ options[:login_field_validates_uniqueness_of_options][:scope] ||= options[:scope]
184
+ options[:email_field_validation_uniqueness_of_options][:scope] ||= options[:scope]
185
+ end
168
186
 
169
187
  class_eval <<-"end_eval", __FILE__, __LINE__
170
188
  def self.acts_as_authentic_config
@@ -21,30 +21,40 @@ module Authlogic
21
21
  acts_as_authentic_without_credentials(options)
22
22
 
23
23
  if options[:validate_fields]
24
+ email_name_regex = '[\w\.%\+\-]+'
25
+ domain_head_regex = '(?:[A-Z0-9\-]+\.)+'
26
+ domain_tld_regex = '(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|jobs|museum)'
27
+ email_field_regex ||= /\A#{email_name_regex}@#{domain_head_regex}#{domain_tld_regex}\z/i
28
+
24
29
  if options[:validate_login_field]
25
30
  case options[:login_field_type]
26
31
  when :email
27
- validates_length_of options[:login_field], :within => 6..100, :allow_blank => options[:allow_blank_login_and_password_fields]
28
- validates_format_of options[:login_field], :with => options[:login_field_regex], :message => options[:login_field_regex_failed_message], :allow_blank => options[:allow_blank_login_and_password_fields]
32
+ validates_length_of options[:login_field], {:within => 6..100}.merge(options[:login_field_validates_length_of_options])
33
+ validates_format_of options[:login_field], {:with => email_field_regex, :message => "should look like an email address."}.merge(options[:login_field_validates_length_of_options])
29
34
  else
30
- validates_length_of options[:login_field], :within => 2..100, :allow_blank => options[:allow_blank_login_and_password_fields]
31
- validates_format_of options[:login_field], :with => options[:login_field_regex], :message => options[:login_field_regex_failed_message], :allow_blank => options[:allow_blank_login_and_password_fields]
35
+ validates_length_of options[:login_field], {:within => 2..100}.merge(options[:login_field_validates_length_of_options])
36
+ validates_format_of options[:login_field], {:with => /\A\w[\w\.\-_@ ]+\z/, :message => "should use only letters, numbers, spaces, and .-_@ please."}.merge(options[:login_field_validates_format_of_options])
32
37
  end
33
38
 
34
- validates_uniqueness_of options[:login_field], :scope => options[:scope], :allow_blank => options[:allow_blank_login_and_password_fields], :if => Proc.new { |record| (record.respond_to?("#{options[:login_field]}_changed?") && record.send("#{options[:login_field]}_changed?")) || !record.respond_to?("#{options[:login_field]}_changed?") }
39
+ validates_uniqueness_of options[:login_field], {:allow_blank => true}.merge(options[:login_field_validates_uniqueness_of_options].merge(:if => "#{options[:login_field]}_changed?".to_sym))
35
40
  end
36
41
 
37
- if options[:validate_email_field] && options[:email_field]
38
- validates_length_of options[:email_field], :within => 6..100, :allow_blank => options[:allow_blank_email_field]
39
- validates_format_of options[:email_field], :with => options[:email_field_regex], :message => options[:email_field_regex_failed_message], :allow_blank => options[:allow_blank_email_field]
40
- validates_uniqueness_of options[:email_field], :scope => options[:scope], :allow_blank => options[:allow_blank_email_field], :if => Proc.new { |record| (record.respond_to?("#{options[:email_field]}_changed?") && record.send("#{options[:email_field]}_changed?")) || !record.respond_to?("#{options[:email_field]}_changed?") }
42
+ if options[:validate_password_field]
43
+ validates_presence_of options[:password_field], {:on => :create}.merge(options[:password_field_validates_presence_of_options])
44
+
45
+
46
+ validates_confirmation_of options[:password_field], options[:password_field_validates_confirmation_of_options].merge(:if => "#{options[:crypted_password_field]}_changed?".to_sym)
47
+ validates_presence_of "#{options[:password_field]}_confirmation", :if => "#{options[:crypted_password_field]}_changed?"
41
48
  end
42
49
 
43
- validate :validate_password if options[:validate_password_field]
50
+ if options[:validate_email_field] && options[:email_field]
51
+ validates_length_of options[:email_field], {:within => 6..100}.merge(options[:email_field_validates_length_of_options])
52
+ validates_format_of options[:email_field], {:with => email_field_regex, :message => "should look like an email address."}.merge(options[:email_field_validates_format_of_options])
53
+ validates_uniqueness_of options[:email_field], options[:email_field_validates_uniqueness_of_options].merge(:if => "#{options[:email_field]}_changed?".to_sym)
54
+ end
44
55
  end
45
56
 
46
- attr_writer "confirm_#{options[:password_field]}"
47
- attr_accessor "tried_to_set_#{options[:password_field]}"
57
+ attr_reader options[:password_field]
48
58
 
49
59
  class_eval <<-"end_eval", __FILE__, __LINE__
50
60
  def self.friendly_unique_token
@@ -56,7 +66,6 @@ module Authlogic
56
66
 
57
67
  def #{options[:password_field]}=(pass)
58
68
  return if pass.blank?
59
- self.tried_to_set_#{options[:password_field]} = true
60
69
  @#{options[:password_field]} = pass
61
70
  self.#{options[:password_salt_field]} = self.class.unique_token
62
71
  self.#{options[:crypted_password_field]} = #{options[:crypto_provider]}.encrypt(@#{options[:password_field]} + #{options[:password_salt_field]})
@@ -68,13 +77,10 @@ module Authlogic
68
77
  (!#{options[:crypto_provider]}.respond_to?(:decrypt) && #{options[:crypto_provider]}.encrypt(attempted_password + #{options[:password_salt_field]}) == #{options[:crypted_password_field]})
69
78
  end
70
79
 
71
- def #{options[:password_field]}; end
72
- def confirm_#{options[:password_field]}; end
73
-
74
80
  def reset_#{options[:password_field]}
75
81
  friendly_token = self.class.friendly_unique_token
76
82
  self.#{options[:password_field]} = friendly_token
77
- self.confirm_#{options[:password_field]} = friendly_token
83
+ self.#{options[:password_field]}_confirmation = friendly_token
78
84
  end
79
85
  alias_method :randomize_password, :reset_password
80
86
 
@@ -83,23 +89,6 @@ module Authlogic
83
89
  save_without_session_maintenance(false)
84
90
  end
85
91
  alias_method :randomize_password!, :reset_password!
86
-
87
- protected
88
- def tried_to_set_password?
89
- tried_to_set_password == true
90
- end
91
-
92
- def validate_password
93
- return if #{options[:allow_blank_login_and_password_fields].inspect} && @#{options[:password_field]}.blank? && @confirm_#{options[:password_field]}.blank?
94
-
95
- if new_record? || tried_to_set_#{options[:password_field]}?
96
- if @#{options[:password_field]}.blank?
97
- errors.add(:#{options[:password_field]}, #{options[:password_blank_message].inspect})
98
- else
99
- errors.add(:confirm_#{options[:password_field]}, #{options[:confirm_password_did_not_match_message].inspect}) if @confirm_#{options[:password_field]} != @#{options[:password_field]}
100
- end
101
- end
102
- end
103
92
  end_eval
104
93
  end
105
94
  end
@@ -24,7 +24,7 @@ module Authlogic
24
24
  return if options[:perishable_token_field].blank?
25
25
 
26
26
  class_eval <<-"end_eval", __FILE__, __LINE__
27
- validates_uniqueness_of :#{options[:perishable_token_field]}, :if => Proc.new { |record| (record.respond_to?("#{options[:perishable_token_field]}_changed?") && record.send("#{options[:perishable_token_field]}_changed?")) || !record.respond_to?("#{options[:perishable_token_field]}_changed?") }
27
+ validates_uniqueness_of :#{options[:perishable_token_field]}, :if => :#{options[:perishable_token_field]}_changed?
28
28
 
29
29
  before_validation :reset_#{options[:perishable_token_field]}
30
30
 
@@ -22,7 +22,7 @@ module Authlogic
22
22
  def acts_as_authentic_with_persistence(options = {})
23
23
  acts_as_authentic_without_persistence(options)
24
24
 
25
- validates_uniqueness_of options[:persistence_token_field], :if => Proc.new { |record| (record.respond_to?("#{options[:persistence_token_field]}_changed?") && record.send("#{options[:persistence_token_field]}_changed?")) || !record.respond_to?("#{options[:persistence_token_field]}_changed?") }
25
+ validates_uniqueness_of options[:persistence_token_field], :if => "#{options[:persistence_token_field]}_changed?".to_sym
26
26
 
27
27
  def forget_all!
28
28
  # Paginate these to save on memory
@@ -22,7 +22,7 @@ module Authlogic
22
22
  return if options[:single_access_token_field].blank?
23
23
 
24
24
  class_eval <<-"end_eval", __FILE__, __LINE__
25
- validates_uniqueness_of :#{options[:single_access_token_field]}, :if => Proc.new { |record| (record.respond_to?("#{options[:single_access_token_field]}_changed?") && record.send("#{options[:single_access_token_field]}_changed?")) || !record.respond_to?("#{options[:single_access_token_field]}_changed?") }
25
+ validates_uniqueness_of :#{options[:single_access_token_field]}, :if => :#{options[:single_access_token_field]}_changed?
26
26
 
27
27
  before_validation :set_#{options[:single_access_token_field]}_field
28
28
 
@@ -43,8 +43,8 @@ module Authlogic # :nodoc:
43
43
  end
44
44
 
45
45
  MAJOR = 1
46
- MINOR = 2
47
- TINY = 2
46
+ MINOR = 3
47
+ TINY = 0
48
48
 
49
49
  # The current version as a Version instance
50
50
  CURRENT = new(MAJOR, MINOR, TINY)
@@ -12,31 +12,37 @@ module ORMAdaptersTests
12
12
 
13
13
  def test_acts_as_authentic_config
14
14
  default_config = {
15
- :confirm_password_did_not_match_message => "did not match",
16
- :single_access_token_field => :single_access_token,
17
- :login_field_regex => /\A\w[\w\.\-_@ ]+\z/,
18
15
  :session_ids => [nil],
19
- :login_field_regex_failed_message => "should use only letters, numbers, spaces, and .-_@ please.",
20
- :persistence_token_field => :persistence_token,
21
- :password_field => :password,
22
- :logged_in_timeout => 600,
23
- :password_salt_field => :password_salt,
24
- :perishable_token_valid_for => 600,
25
- :perishable_token_field => :perishable_token,
26
- :login_field_type => :login,
27
- :crypto_provider => Authlogic::CryptoProviders::Sha512,
28
- :password_blank_message => "can not be blank",
29
- :crypted_password_field => :crypted_password,
30
- :session_class => "UserSession",
31
- :login_field => :login,
32
- :email_field => :email,
33
- :email_field_regex => /\A[\w\.%\+\-]+@(?:[A-Z0-9\-]+\.)+(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|jobs|museum)\z/i,
34
- :email_field_regex_failed_message=>"should look like an email address.",
35
- :validate_fields => true,
36
- :validate_login_field => true,
37
- :validate_email_field => true,
38
- :validate_password_field => true
39
- }
16
+ :email_field_validates_length_of_options => {},
17
+ :logged_in_timeout => 600,
18
+ :validate_password_field => true,
19
+ :login_field_validates_length_of_options => {},
20
+ :password_field_validation_options => {},
21
+ :login_field_type => :login,
22
+ :email_field_validates_format_of_options => {},
23
+ :crypted_password_field => :crypted_password,
24
+ :password_salt_field => :password_salt,
25
+ :login_field_validates_format_of_options => {},
26
+ :email_field_validation_options => {},
27
+ :crypto_provider => Authlogic::CryptoProviders::Sha512,
28
+ :persistence_token_field => :persistence_token,
29
+ :email_field_validates_uniqueness_of_options => {},
30
+ :session_class => "UserSession",
31
+ :single_access_token_field => :single_access_token,
32
+ :login_field_validates_uniqueness_of_options => {},
33
+ :validate_fields => true,
34
+ :login_field => :login,
35
+ :perishable_token_valid_for => 600,
36
+ :password_field_validates_presence_of_options => {},
37
+ :password_field => :password,
38
+ :validate_login_field => true,
39
+ :email_field => :email,
40
+ :perishable_token_field => :perishable_token,
41
+ :password_field_validates_confirmation_of_options => {},
42
+ :validate_email_field => true,
43
+ :validation_options => {},
44
+ :login_field_validation_options => {}
45
+ }
40
46
  assert_equal default_config, User.acts_as_authentic_config
41
47
  end
42
48
  end
@@ -38,15 +38,14 @@ module ORMAdaptersTests
38
38
  user.password = "my pass"
39
39
  assert !user.valid?
40
40
  assert !user.errors.on(:password)
41
- assert user.errors.on(:confirm_password)
41
+ assert user.errors.on(:password_confirmation)
42
42
 
43
- user.confirm_password = "my pizass"
43
+ user.password_confirmation = "my pizass"
44
44
  assert !user.valid?
45
- assert !user.errors.on(:password)
46
- assert user.errors.on(:confirm_password)
45
+ assert user.errors.on(:password)
47
46
  assert user.errors.on(:email)
48
47
 
49
- user.confirm_password = "my pass"
48
+ user.password_confirmation = "my pass"
50
49
  assert !user.valid?
51
50
  assert user.errors.on(:email)
52
51
 
@@ -61,7 +60,7 @@ module ORMAdaptersTests
61
60
  def test_employee_validations
62
61
  employee = Employee.new
63
62
  employee.password = "pass"
64
- employee.confirm_password = "pass"
63
+ employee.password_confirmation = "pass"
65
64
 
66
65
  assert !employee.valid?
67
66
  assert employee.errors.on(:email)
@@ -95,15 +94,13 @@ module ORMAdaptersTests
95
94
  assert user.crypted_password
96
95
  assert user.password_salt
97
96
  assert user.persistence_token
98
- assert_equal true, user.tried_to_set_password
99
- assert_nil user.password
97
+ assert_equal "sillywilly", user.password
100
98
 
101
99
  employee = Employee.new
102
100
  employee.password = "awesome"
103
101
  assert employee.crypted_password
104
102
  assert employee.persistence_token
105
- assert_equal true, employee.tried_to_set_password
106
- assert_nil employee.password
103
+ assert_equal "awesome", employee.password
107
104
  end
108
105
 
109
106
  def test_valid_password
@@ -5,7 +5,7 @@ module ORMAdaptersTests
5
5
  module ActsAsAuthenticTests
6
6
  class SessionMaintenanceTest < ActiveSupport::TestCase
7
7
  def test_login_after_create
8
- assert User.create(:login => "awesome", :password => "saweet", :confirm_password => "saweet", :email => "awesome@awesome.com")
8
+ assert User.create(:login => "awesome", :password => "saweet", :password_confirmation => "saweet", :email => "awesome@awesome.com")
9
9
  assert UserSession.find
10
10
  end
11
11
 
@@ -15,7 +15,7 @@ module ORMAdaptersTests
15
15
  old_session_key = @controller.session["user_credentials"]
16
16
  old_cookie_key = @controller.cookies["user_credentials"]
17
17
  ben.password = "newpass"
18
- ben.confirm_password = "newpass"
18
+ ben.password_confirmation = "newpass"
19
19
  ben.save
20
20
  assert @controller.session["user_credentials"]
21
21
  assert @controller.cookies["user_credentials"]
@@ -41,7 +41,7 @@ module ORMAdaptersTests
41
41
  old_cookie_key = @controller.cookies["user_credentials"]
42
42
  zack = users(:zack)
43
43
  zack.password = "newpass"
44
- zack.confirm_password = "newpass"
44
+ zack.password_confirmation = "newpass"
45
45
  zack.save
46
46
  assert_equal @controller.session["user_credentials"], old_session_key
47
47
  assert_equal @controller.cookies["user_credentials"], old_cookie_key
@@ -51,7 +51,7 @@ module ORMAdaptersTests
51
51
  ben = users(:ben)
52
52
  assert !UserSession.find
53
53
  ben.password = "newpass"
54
- ben.confirm_password = "newpass"
54
+ ben.password_confirmation = "newpass"
55
55
  ben.save
56
56
  assert UserSession.find
57
57
  assert_equal ben, UserSession.find.record
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authlogic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Johnson of Binary Logic
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-11-20 00:00:00 -05:00
12
+ date: 2008-11-21 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -61,7 +61,6 @@ extra_rdoc_files:
61
61
  - lib/authlogic/session/config.rb
62
62
  - lib/authlogic/session/cookies.rb
63
63
  - lib/authlogic/session/errors.rb
64
- - lib/authlogic/session/openid.rb
65
64
  - lib/authlogic/session/params.rb
66
65
  - lib/authlogic/session/perishability.rb
67
66
  - lib/authlogic/session/scopes.rb
@@ -93,7 +92,6 @@ files:
93
92
  - lib/authlogic/session/config.rb
94
93
  - lib/authlogic/session/cookies.rb
95
94
  - lib/authlogic/session/errors.rb
96
- - lib/authlogic/session/openid.rb
97
95
  - lib/authlogic/session/params.rb
98
96
  - lib/authlogic/session/perishability.rb
99
97
  - lib/authlogic/session/scopes.rb
@@ -1,17 +0,0 @@
1
- module Authlogic
2
- module Session
3
- # = Session
4
- #
5
- # Handles all parts of authentication that deal with sessions. Such as persisting a session and saving / destroy a session.
6
- module OpenID
7
- def self.included(klass)
8
- klass.class_eval do
9
- attr_accessor :
10
- alias_method_chain :credentials=, :openid
11
- end
12
- end
13
-
14
- # Tries to validate the session from information in the session
15
- def credentials_with_openid=(value)
16
- self.credentials_without_openid
17
- end