Permalink
Browse files

Allow options to change if password is optional or not

  • Loading branch information...
1 parent 6ddadfb commit 783e3f2511da3b783b08637f8ec9e719d7a61dd4 @binarylogic committed Nov 30, 2008
View
@@ -1,3 +1,7 @@
+== 1.3.6 released 2008-11-30
+
+* Modified validates_length_of for password so that changing the options and passing an :if can make it optional for OpenID auth.
+
== 1.3.5 released 2008-11-30
* :transition_from_crypto_provider for acts_as_authentic now accepts an array to transition from multiple providers. Which solves the problem of a double transition.
View
@@ -3,6 +3,7 @@ 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/aes256.rb
lib/authlogic/crypto_providers/bcrypt.rb
lib/authlogic/crypto_providers/sha1.rb
lib/authlogic/crypto_providers/sha512.rb
@@ -33,11 +34,14 @@ MIT-LICENSE
Rakefile
README.rdoc
shoulda_macros/authlogic.rb
+test/crypto_provider_tests/aes256_test.rb
+test/crypto_provider_tests/bcrypt_test.rb
+test/crypto_provider_tests/sha1_test.rb
+test/crypto_provider_tests/sha512_test.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
@@ -146,6 +146,10 @@ def first_column_to_exist(*columns_to_check) # :nodoc:
columns_to_check.each { |column_name| return column_name.to_sym if column_names.include?(column_name.to_s) }
columns_to_check.first ? columns_to_check.first.to_sym : nil
end
+
+ def meta_def(name, &block)
+ (class << self; self; end).instance_eval { define_method name, &block }
+ end
def acts_as_authentic_with_config(options = {})
# Stop all configuration if the DB is not set up
@@ -209,12 +213,10 @@ def acts_as_authentic_with_config(options = {})
end
options[:transition_from_crypto_provider] = [options[:transition_from_crypto_provider]].compact unless options[:transition_from_crypto_provider].is_a?(Array)
-
- class_eval <<-"end_eval", __FILE__, __LINE__
- def self.acts_as_authentic_config
- #{options.inspect}
- end
- end_eval
+
+ meta_def :acts_as_authentic_config do
+ options
+ end
acts_as_authentic_without_config(options)
end
@@ -40,9 +40,9 @@ def acts_as_authentic_with_credentials(options = {})
end
if options[:validate_password_field]
- validates_length_of options[:password_field], {:minimum => 4}.merge(options[:password_field_validates_length_of_options].merge(:if => "validate_#{options[:password_field]}?".to_sym))
- validates_confirmation_of options[:password_field], options[:password_field_validates_confirmation_of_options].merge(:if => "validate_#{options[:password_field]}?".to_sym)
- validates_presence_of "#{options[:password_field]}_confirmation", :if => "validate_#{options[:password_field]}?".to_sym
+ validates_length_of options[:password_field], {:minimum => 4, :if => "new_record?".to_sym}.merge(options[:password_field_validates_length_of_options])
+ validates_confirmation_of options[:password_field], options[:password_field_validates_confirmation_of_options].merge(:if => "#{options[:password_salt_field]}_changed?".to_sym)
+ validates_presence_of "#{options[:password_field]}_confirmation", :if => "#{options[:password_salt_field]}_changed?".to_sym
end
if options[:validate_email_field] && options[:email_field]
@@ -113,10 +113,6 @@ def reset_#{options[:password_field]}!
end
alias_method :randomize_password!, :reset_password!
- def validate_#{options[:password_field]}?
- new_record? || #{options[:crypted_password_field]}_changed?
- end
-
private
def encrypt_arguments(raw_password, arguments_type = nil)
case arguments_type
View
@@ -0,0 +1,5 @@
+class User < ActiveRecord::Base
+ acts_as_authentic
+ belongs_to :company
+ has_and_belongs_to_many :projects
+end
@@ -103,6 +103,14 @@ def test_transition_from_restful_authentication
assert_equal [Authlogic::CryptoProviders::Sha1], User.acts_as_authentic_config[:transition_from_crypto_provider]
end
+ # Need to finish this when I can figure out the best way to implement "transactions" for ruby constants inbetween tests
+ def test_password_field_validation_options
+ #User.acts_as_authentic(:password_field_validates_length_of_options => {:if => Proc.new { |user| false }})
+ #user = User.new
+ #assert !user.save!
+ #assert !user.errors.on(:password)
+ end
+
private
def get_default_configuration
@default_configuration = User.acts_as_authentic_config
View
@@ -7,6 +7,7 @@
require File.dirname(__FILE__) + '/libs/mock_request'
require File.dirname(__FILE__) + '/libs/mock_cookie_jar'
require File.dirname(__FILE__) + '/libs/mock_controller'
+require File.dirname(__FILE__) + '/libs/user'
ActiveRecord::Schema.verbose = false
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
@@ -87,12 +88,6 @@ class Company < ActiveRecord::Base
has_many :users, :dependent => :destroy
end
-class User < ActiveRecord::Base
- acts_as_authentic
- belongs_to :company
- has_and_belongs_to_many :projects
-end
-
Authlogic::CryptoProviders::AES256.key = "myafdsfddddddddddddddddddddddddddddddddddddddddddddddd"
class Employee < ActiveRecord::Base

0 comments on commit 783e3f2

Please sign in to comment.