diff --git a/README.rdoc b/README.rdoc
index ac5181d0..19f5a33a 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -80,6 +80,8 @@ These modules are for the "session side" of authentication. They create a new do
=== Miscellaneous modules
+Miscellaneous modules that don't really belong solely to either the session or model aspect.
+
* Authlogic::AuthenticatesMany - Responsible for allowing you to scope sessions to a parent record. Similar to a has_many and belongs_to relationship. This lets you do the same thing with sessions.
* Authlogic::CryptoProviders - Contains various encryption algorithms that Authlogic uses, allowing you to choose your encryption method.
* Authlogic::I18n - Acts JUST LIKE the rails I18n library, and provides internationalization to Authlogic.
diff --git a/lib/authlogic.rb b/lib/authlogic.rb
index 28f77248..820dca7f 100644
--- a/lib/authlogic.rb
+++ b/lib/authlogic.rb
@@ -25,11 +25,10 @@
require File.dirname(__FILE__) + "/authlogic/acts_as_authentic/perishable_token"
require File.dirname(__FILE__) + "/authlogic/acts_as_authentic/persistence_token"
require File.dirname(__FILE__) + "/authlogic/acts_as_authentic/restful_authentication"
-require File.dirname(__FILE__) + "/authlogic/acts_as_authentic/scope"
require File.dirname(__FILE__) + "/authlogic/acts_as_authentic/session_maintenance"
require File.dirname(__FILE__) + "/authlogic/acts_as_authentic/single_access_token"
+require File.dirname(__FILE__) + "/authlogic/acts_as_authentic/validations_scope"
require File.dirname(__FILE__) + "/authlogic/acts_as_authentic/base"
-require File.dirname(__FILE__) + "/authlogic/acts_as_authentic/config"
require File.dirname(__FILE__) + "/authlogic/session/activation"
require File.dirname(__FILE__) + "/authlogic/session/active_record_trickery"
diff --git a/lib/authlogic/acts_as_authentic/base.rb b/lib/authlogic/acts_as_authentic/base.rb
index 7435dc72..e73ba457 100644
--- a/lib/authlogic/acts_as_authentic/base.rb
+++ b/lib/authlogic/acts_as_authentic/base.rb
@@ -2,41 +2,83 @@ module Authlogic
module ActsAsAuthentic
# Adds in the acts_as_authentic method to ActiveRecord.
module Base
- # This includes a lot of helpful methods for authenticating records which The Authlogic::Session module relies on.
- # To use it just do:
- #
- # class User < ActiveRecord::Base
- # acts_as_authentic
- # end
- #
- # Configuration is easy:
- #
- # acts_as_authentic do |c|
- # c.my_configuration_option = my_value
- # end
- #
- # See the various sub modules for the configuration they provide.
- def acts_as_authentic(&block)
- cattr_accessor :aaa_config
- c = Config.new(self)
- yield c if block_given?
- self.aaa_config = c
+ def self.included(klass)
+ klass.class_eval do
+ extend Config
+ end
+ end
+
+ module Config
+ # This includes a lot of helpful methods for authenticating records which The Authlogic::Session module relies on.
+ # To use it just do:
+ #
+ # class User < ActiveRecord::Base
+ # acts_as_authentic
+ # end
+ #
+ # Configuration is easy:
+ #
+ # acts_as_authentic do |c|
+ # c.my_configuration_option = my_value
+ # end
+ #
+ # See the various sub modules for the configuration they provide.
+ def acts_as_authentic(&block)
+ yield self if block_given?
+ acts_as_authentic_modules.each { |mod| include mod }
+ end
+
+ def add_acts_as_authentic_module(mod)
+ modules = acts_as_authentic_modules
+ modules << mod
+ modules.uniq!
+ write_inheritable_attribute(:acts_as_authentic_modules, modules)
+ end
+
+ def remove_acts_as_authentic_module(mod)
+ acts_as_authentic_modules.delete(mod)
+ acts_as_authentic_modules
+ end
+
+ private
+ def acts_as_authentic_modules
+ key = :acts_as_authentic_modules
+ inheritable_attributes.include?(key) ? read_inheritable_attribute(key) : []
+ end
- # We need to include these after configuration is set, because some of these module
- # use the configuration when included.
- include Email::Methods
- include LoggedInStatus::Methods
- include Login::Methods
- include MagicColumns::Methods
- include Password::Callbacks
- include Password::Methods
- include PerishableToken::Methods if column_names.include?("perishable_token")
- include PersistenceToken::Methods
- include SessionMaintenance::Methods
- include SingleAccessToken::Methods if column_names.include?("single_access_token")
+ def config(key, value, default_value = nil, read_value = nil)
+ if value == read_value
+ return read_inheritable_attribute(key) if inheritable_attributes.include?(key)
+ write_inheritable_attribute(key, default_value)
+ else
+ write_inheritable_attribute(key, value)
+ end
+ end
+
+ 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
end
end
-
- ::ActiveRecord::Base.extend(Base) if defined?(::ActiveRecord)
+ end
+end
+
+if defined?(::ActiveRecord)
+ module ::ActiveRecord
+ class Base
+ include Authlogic::ActsAsAuthentic::Base
+ include Authlogic::ActsAsAuthentic::Email
+ include Authlogic::ActsAsAuthentic::LoggedInStatus
+ include Authlogic::ActsAsAuthentic::Login
+ include Authlogic::ActsAsAuthentic::MagicColumns
+ include Authlogic::ActsAsAuthentic::Password
+ include Authlogic::ActsAsAuthentic::PerishableToken
+ include Authlogic::ActsAsAuthentic::PersistenceToken
+ include Authlogic::ActsAsAuthentic::RestfulAuthentication
+ include Authlogic::ActsAsAuthentic::SessionMaintenance
+ include Authlogic::ActsAsAuthentic::SingleAccessToken
+ include Authlogic::ActsAsAuthentic::ValidationsScope
+ end
end
end
\ No newline at end of file
diff --git a/lib/authlogic/acts_as_authentic/config.rb b/lib/authlogic/acts_as_authentic/config.rb
deleted file mode 100644
index 1daea91a..00000000
--- a/lib/authlogic/acts_as_authentic/config.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-module Authlogic
- module ActsAsAuthentic
- class Config # :nodoc:
- include Email::Config
- include LoggedInStatus::Config
- include Login::Config
- include Password::Config
- include PerishableToken::Config
- include RestfulAuthentication::Config
- include Scope::Config
- include SessionMaintenance::Config
- include SingleAccessToken::Config
-
- attr_accessor :klass
-
- def initialize(klass)
- self.klass = klass
- end
-
- private
- def config(key, value, default_value = nil, read_value = nil)
- if value == read_value
- v = instance_variable_defined?("@#{key}") ? instance_variable_get("@#{key}") : nil
- return v if !v.nil?
- instance_variable_set("@#{key}", default_value)
- else
- instance_variable_set("@#{key}", value)
- end
- end
-
- def first_column_to_exist(*columns_to_check) # :nodoc:
- columns_to_check.each { |column_name| return column_name.to_sym if klass.column_names.include?(column_name.to_s) }
- columns_to_check.first ? columns_to_check.first.to_sym : nil
- end
- end
- end
-end
\ No newline at end of file
diff --git a/lib/authlogic/acts_as_authentic/email.rb b/lib/authlogic/acts_as_authentic/email.rb
index 418f1fa3..c625edf9 100644
--- a/lib/authlogic/acts_as_authentic/email.rb
+++ b/lib/authlogic/acts_as_authentic/email.rb
@@ -5,6 +5,13 @@ module ActsAsAuthentic
# if you do have a login or username field, Authlogic will still validate your email field. One less thing you have to
# worry about.
module Email
+ def self.included(klass)
+ klass.class_eval do
+ extend Config
+ add_acts_as_authentic_module(Methods)
+ end
+ end
+
# Configuration to modify how Authlogic handles the email field.
module Config
# The name of the field that stores email addresses.
@@ -57,12 +64,10 @@ def email_regex
module Methods
def self.included(klass)
klass.class_eval do
- if aaa_config.validate_email_field
- if aaa_config.email_field
- validates_length_of aaa_config.email_field, aaa_config.validates_length_of_email_field_options
- validates_format_of aaa_config.email_field, aaa_config.validates_format_of_email_field_options
- validates_uniqueness_of aaa_config.email_field, :scope => aaa_config.scope, :if => "#{aaa_config.email_field}_changed?".to_sym
- end
+ if validate_email_field && email_field
+ validates_length_of email_field, validates_length_of_email_field_options
+ validates_format_of email_field, validates_format_of_email_field_options
+ validates_uniqueness_of email_field, :scope => validations_scope, :if => "#{email_field}_changed?".to_sym
end
end
end
diff --git a/lib/authlogic/acts_as_authentic/logged_in_status.rb b/lib/authlogic/acts_as_authentic/logged_in_status.rb
index 3eaf0423..a6b0d58f 100644
--- a/lib/authlogic/acts_as_authentic/logged_in_status.rb
+++ b/lib/authlogic/acts_as_authentic/logged_in_status.rb
@@ -5,6 +5,13 @@ module ActsAsAuthentic
# So if that user is inactive for a certain amount of time we assume they are logged out. That's what this
# module is all about.
module LoggedInStatus
+ def self.included(klass)
+ klass.class_eval do
+ extend Config
+ add_acts_as_authentic_module(Methods)
+ end
+ end
+
# All configuration for the logged in status feature set.
module Config
# The timeout to determine when a user is logged in or not.
@@ -21,21 +28,26 @@ def logged_in_timeout(value = nil)
module Methods
def self.included(klass)
klass.class_eval do
- named_scope :logged_in, lambda { {:conditions => ["last_request_at > ?", aaa_config.logged_in_timeout.seconds.ago]} }
- named_scope :logged_out, lambda { {:conditions => ["last_request_at is NULL or last_request_at <= ?", aaa_config.logged_in_timeout.seconds.ago]} }
+ named_scope :logged_in, lambda { {:conditions => ["last_request_at > ?", logged_in_timeout.seconds.ago]} }
+ named_scope :logged_out, lambda { {:conditions => ["last_request_at is NULL or last_request_at <= ?", logged_in_timeout.seconds.ago]} }
end
end
# Returns true if the last_request_at > logged_in_timeout.
def logged_in?
raise "Can not determine the records login state because there is no last_request_at column" if !respond_to?(:last_request_at)
- !last_request_at.nil? && last_request_at > aaa_config.logged_in_timeout.seconds.ago
+ !last_request_at.nil? && last_request_at > logged_in_timeout.seconds.ago
end
# Opposite of logged_in?
def logged_out?
!logged_in?
end
+
+ private
+ def logged_in_timeout
+ self.class.logged_in_timeout
+ end
end
end
end
diff --git a/lib/authlogic/acts_as_authentic/login.rb b/lib/authlogic/acts_as_authentic/login.rb
index 0bcabff3..80b53cab 100644
--- a/lib/authlogic/acts_as_authentic/login.rb
+++ b/lib/authlogic/acts_as_authentic/login.rb
@@ -2,6 +2,13 @@ module Authlogic
module ActsAsAuthentic
# Handles everything related to the login field.
module Login
+ def self.included(klass)
+ klass.class_eval do
+ extend Config
+ add_acts_as_authentic_module(Methods)
+ end
+ end
+
# Confguration for the login field.
module Config
# The name of the login field in the database.
@@ -27,7 +34,7 @@ def validate_login_field(value = nil)
# * Default: {:within => 6..100}
# * Accepts: Hash of options accepted by validates_length_of
def validates_length_of_login_field_options(value = nil)
- config(:validates_length_of_login_field_options, value, {:within => 6..100})
+ config(:validates_length_of_login_field_options, value, {:within => 3..100})
end
alias_method :validates_length_of_login_field_options=, :validates_length_of_login_field_options
@@ -45,12 +52,10 @@ def validates_format_of_login_field_options(value = nil)
module Methods
def self.included(klass)
klass.class_eval do
- if aaa_config.validate_login_field
- if aaa_config.login_field
- validates_length_of aaa_config.login_field, aaa_config.validates_length_of_login_field_options
- validates_format_of aaa_config.login_field, aaa_config.validates_format_of_login_field_options
- validates_uniqueness_of aaa_config.login_field, :scope => aaa_config.scope, :if => "#{aaa_config.login_field}_changed?".to_sym
- end
+ if validate_login_field && login_field
+ validates_length_of login_field, validates_length_of_login_field_options
+ validates_format_of login_field, validates_format_of_login_field_options
+ validates_uniqueness_of login_field, :scope => validations_scope, :if => "#{login_field}_changed?".to_sym
end
end
end
diff --git a/lib/authlogic/acts_as_authentic/magic_columns.rb b/lib/authlogic/acts_as_authentic/magic_columns.rb
index 23b5d01d..4be1f8eb 100644
--- a/lib/authlogic/acts_as_authentic/magic_columns.rb
+++ b/lib/authlogic/acts_as_authentic/magic_columns.rb
@@ -4,6 +4,12 @@ module ActsAsAuthentic
# you. Authlogic has the same thing, but these are maintained on the session side. Please see Authlogic::Session::MagicColumns
# for more details. This module merely adds validations for the magic columns if they exist.
module MagicColumns
+ def self.included(klass)
+ klass.class_eval do
+ add_acts_as_authentic_module(Methods)
+ end
+ end
+
# Methods relating to the magic columns
module Methods
def self.included(klass)
diff --git a/lib/authlogic/acts_as_authentic/password.rb b/lib/authlogic/acts_as_authentic/password.rb
index be0f7c84..f6ab5f0b 100644
--- a/lib/authlogic/acts_as_authentic/password.rb
+++ b/lib/authlogic/acts_as_authentic/password.rb
@@ -3,6 +3,14 @@ module ActsAsAuthentic
# This module has a lot of neat functionality. It is responsible for encrypting your password, salting it, and verifying it.
# It can also help you transition to a new encryption algorithm. See the Config sub module for configuration options.
module Password
+ def self.included(klass)
+ klass.class_eval do
+ extend Config
+ add_acts_as_authentic_module(Callbacks)
+ add_acts_as_authentic_module(Methods)
+ end
+ end
+
module Config
# The name of the crypted_password field in the database.
#
@@ -101,9 +109,9 @@ def #{method}
module Methods
def self.included(klass)
klass.class_eval do
- if aaa_config.validate_password_field
- validates_confirmation_of :password, aaa_config.validates_confirmation_of_password_field_options
- validates_length_of :password_confirmation, aaa_config.validates_length_of_password_confirmation_field_options
+ if validate_password_field
+ validates_confirmation_of :password, validates_confirmation_of_password_field_options
+ validates_length_of :password_confirmation, validates_length_of_password_confirmation_field_options
end
end
end
@@ -119,29 +127,29 @@ def password=(pass)
return if pass.blank?
before_password_set
@password = pass
- send("#{aaa_config.password_salt_field}=", Authlogic::Random.friendly_token) if aaa_config.password_salt_field
- send("#{aaa_config.crypted_password_field}=", aaa_config.crypto_provider.encrypt(*encrypt_arguments(@password, aaa_config.act_like_restful_authentication ? :restful_authentication : nil)))
+ send("#{password_salt_field}=", Authlogic::Random.friendly_token) if password_salt_field
+ send("#{crypted_password_field}=", crypto_provider.encrypt(*encrypt_arguments(@password, act_like_restful_authentication? ? :restful_authentication : nil)))
after_password_set
end
# Accepts a raw password to determine if it is the correct password or not.
def valid_password?(attempted_password)
- return false if attempted_password.blank? || send(aaa_config.crypted_password_field).blank?
+ return false if attempted_password.blank? || send(crypted_password_field).blank?
before_password_verification
- crypto_providers = [aaa_config.crypto_provider] + aaa_config.transition_from_crypto_providers
+ crypto_providers = [crypto_provider] + transition_from_crypto_providers
crypto_providers.each_with_index do |encryptor, index|
# The arguments_type of for the transitioning from restful_authentication
- arguments_type = (aaa_config.act_like_restful_authentication && index == 0) ||
- (aaa_config.transition_from_restful_authentication && index > 0 && encryptor == Authlogic::CryptoProviders::Sha1) ?
+ arguments_type = (act_like_restful_authentication? && index == 0) ||
+ (transition_from_restful_authentication? && index > 0 && encryptor == Authlogic::CryptoProviders::Sha1) ?
:restful_authentication : nil
- if encryptor.matches?(send(aaa_config.crypted_password_field), *encrypt_arguments(attempted_password, arguments_type))
+ if encryptor.matches?(send(crypted_password_field), *encrypt_arguments(attempted_password, arguments_type))
# If we are transitioning from an older encryption algorithm and the password is still using the old algorithm
# then let's reset the password using the new algorithm. If the algorithm has a cost (BCrypt) and the cost has changed, update the password with
# the new cost.
- if index > 0 || (encryptor.respond_to?(:cost_matches?) && !encryptor.cost_matches?(send(aaa_config.crypted_password_field)))
+ if index > 0 || (encryptor.respond_to?(:cost_matches?) && !encryptor.cost_matches?(send(crypted_password_field)))
self.password = attempted_password
save(false)
end
@@ -172,7 +180,7 @@ def reset_password!
private
def encrypt_arguments(raw_password, arguments_type = nil)
- salt = aaa_config.password_salt_field ? send(aaa_config.password_salt_field) : nil
+ salt = password_salt_field ? send(password_salt_field) : nil
case arguments_type
when :restful_authentication
[REST_AUTH_SITE_KEY, salt, raw_password, REST_AUTH_SITE_KEY].compact
@@ -182,7 +190,23 @@ def encrypt_arguments(raw_password, arguments_type = nil)
end
def require_password_confirmation?
- new_record? || (aaa_config.password_salt_field && send("#{aaa_config.password_salt_field}_changed?")) || send(aaa_config.crypted_password_field).blank?
+ new_record? || (password_salt_field && send("#{password_salt_field}_changed?")) || send(crypted_password_field).blank?
+ end
+
+ def crypted_password_field
+ self.class.crypted_password_field
+ end
+
+ def password_salt_field
+ self.class.password_salt_field
+ end
+
+ def crypto_provider
+ self.class.crypto_provider
+ end
+
+ def transition_from_crypto_providers
+ self.class.transition_from_crypto_providers
end
end
end
diff --git a/lib/authlogic/acts_as_authentic/perishable_token.rb b/lib/authlogic/acts_as_authentic/perishable_token.rb
index f0b83f08..5deac785 100644
--- a/lib/authlogic/acts_as_authentic/perishable_token.rb
+++ b/lib/authlogic/acts_as_authentic/perishable_token.rb
@@ -5,6 +5,13 @@ module ActsAsAuthentic
# use the token and do what they need to do, that token should expire. Don't worry about maintaining this, changing it, or expiring it
# yourself. Authlogic does all of this for you. See the sub modules for all of the tools Authlogic provides to you.
module PerishableToken
+ def self.included(klass)
+ klass.class_eval do
+ extend Config
+ add_acts_as_authentic_module(Methods)
+ end
+ end
+
# Change how the perishable token works.
module Config
# When using the find_using_perishable_token method the token can expire. If the token is expired, no
@@ -32,6 +39,8 @@ def disable_perishable_token_maintenance(value = nil)
# All methods relating to the perishable token.
module Methods
def self.included(klass)
+ return if !klass.column_names.include?("perishable_token")
+
klass.class_eval do
extend ClassMethods
include InstanceMethods
@@ -51,7 +60,7 @@ module ClassMethods
# If you want to use a different timeout value, just pass it as the second parameter:
#
# User.find_using_perishable_token(token, 1.hour)
- def find_using_perishable_token(token, age = aaa_config.perishable_token_valid_for)
+ def find_using_perishable_token(token, age = perishable_token_valid_for)
return if token.blank?
age = age.to_i
@@ -82,7 +91,7 @@ def reset_perishable_token!
# A convenience method based on the disable_perishable_token_maintenance configuration option.
def disable_perishable_token_maintenance?
- aaa_config.disable_perishable_token_maintenance == true
+ self.class.disable_perishable_token_maintenance == true
end
end
end
diff --git a/lib/authlogic/acts_as_authentic/persistence_token.rb b/lib/authlogic/acts_as_authentic/persistence_token.rb
index beb1c1be..0b5ed429 100644
--- a/lib/authlogic/acts_as_authentic/persistence_token.rb
+++ b/lib/authlogic/acts_as_authentic/persistence_token.rb
@@ -3,6 +3,12 @@ module ActsAsAuthentic
# Maintains the persistence token, the token responsible for persisting sessions. This token
# gets stores in the session and the cookie.
module PersistenceToken
+ def self.included(klass)
+ klass.class_eval do
+ add_acts_as_authentic_module(Methods)
+ end
+ end
+
# Methods for the persistence token.
module Methods
def self.included(klass)
diff --git a/lib/authlogic/acts_as_authentic/restful_authentication.rb b/lib/authlogic/acts_as_authentic/restful_authentication.rb
index 57f41f36..26c57f8a 100644
--- a/lib/authlogic/acts_as_authentic/restful_authentication.rb
+++ b/lib/authlogic/acts_as_authentic/restful_authentication.rb
@@ -2,6 +2,13 @@ module Authlogic
module ActsAsAuthentic
# This module is responsible for transitioning existing applications from the restful_authentication plugin.
module RestfulAuthentication
+ def self.included(klass)
+ klass.class_eval do
+ extend Config
+ include InstanceMethods
+ end
+ end
+
module Config
# Switching an existing app to Authlogic from restful_authentication? No problem, just set this true and your users won't know
# anything changed. From your database perspective nothing will change at all. Authlogic will continue to encrypt passwords
@@ -37,6 +44,17 @@ def set_restful_authentication_config
end
end
end
+
+ module InstanceMethods
+ private
+ def act_like_restful_authentication?
+ self.class.act_like_restful_authentication == true
+ end
+
+ def transition_from_restful_authentication?
+ self.class.transition_from_restful_authentication == true
+ end
+ end
end
end
end
\ No newline at end of file
diff --git a/lib/authlogic/acts_as_authentic/session_maintenance.rb b/lib/authlogic/acts_as_authentic/session_maintenance.rb
index 15534f28..3fcfe6b0 100644
--- a/lib/authlogic/acts_as_authentic/session_maintenance.rb
+++ b/lib/authlogic/acts_as_authentic/session_maintenance.rb
@@ -18,6 +18,13 @@ module ActsAsAuthentic
# That's what this module is all about. This will automatically maintain the cookie and session values as
# records are saved.
module SessionMaintenance
+ def self.included(klass)
+ klass.class_eval do
+ extend Config
+ add_acts_as_authentic_module(Methods)
+ end
+ end
+
module Config
# As you may know, authlogic sessions can be separate by id (See Authlogic::Session::Base#id). You can
# specify here what session ids you want auto maintained. By default it is the main session, which has
@@ -35,7 +42,7 @@ def session_ids(value = nil)
# * Default: "#{klass.name}Session".constantize
# * Accepts: Class
def session_class(value = nil)
- config(:session_class, value, "#{klass.name}Session".constantize)
+ config(:session_class, value, "#{name}Session".constantize)
end
alias_method :session_class=, :session_class
end
@@ -45,7 +52,6 @@ def self.included(klass)
klass.class_eval do
before_save :get_session_information, :if => :update_sessions?
before_save :maintain_sessions, :if => :update_sessions?
- attr_accessor
end
end
@@ -67,15 +73,15 @@ def skip_session_maintenance
end
def update_sessions?
- !skip_session_maintenance && aaa_config.session_class.activated? && !aaa_config.session_ids.blank? && persistence_token_changed?
+ !skip_session_maintenance && session_class.activated? && !session_ids.blank? && persistence_token_changed?
end
def get_session_information
# Need to determine if we are completely logged out, or logged in as another user
@_sessions = []
- aaa_config.session_ids.each do |session_id|
- session = aaa_config.session_class.find(session_id, self)
+ session_ids.each do |session_id|
+ session = session_class.find(session_id, self)
@_sessions << session if session && session.record
end
end
@@ -91,8 +97,8 @@ def maintain_sessions
def create_session
# We only want to automatically login into the first session, since this is the main session. The other sessions are sessions
# that need to be created after logging into the main session.
- session_id = aaa_config.session_ids.first
- aaa_config.session_class.create(*[self, self, session_id].compact)
+ session_id = session_ids.first
+ session_class.create!(*[self, self, session_id].compact)
return true
end
@@ -107,6 +113,14 @@ def update_sessions
return true
end
+
+ def session_ids
+ self.class.session_ids
+ end
+
+ def session_class
+ self.class.session_class
+ end
end
end
end
diff --git a/lib/authlogic/acts_as_authentic/single_access_token.rb b/lib/authlogic/acts_as_authentic/single_access_token.rb
index 7ee66fad..83547310 100644
--- a/lib/authlogic/acts_as_authentic/single_access_token.rb
+++ b/lib/authlogic/acts_as_authentic/single_access_token.rb
@@ -3,6 +3,13 @@ module ActsAsAuthentic
# This module is responsible for maintaining the single_access token. For more information the single access token and how to use it,
# see the Authlogic::Session::Params module.
module SingleAccessToken
+ def self.included(klass)
+ klass.class_eval do
+ extend Config
+ add_acts_as_authentic_module(Methods)
+ end
+ end
+
module Config
def change_single_access_token_with_password(value = nil)
config(:change_single_access_token_with_password, value, false)
@@ -12,32 +19,37 @@ def change_single_access_token_with_password(value = nil)
module Methods
def self.included(klass)
+ return if !klass.column_names.include?("single_access_token")
+
klass.class_eval do
+ include InstanceMethods
validates_uniqueness_of :single_access_token, :if => :single_access_token_changed?
before_validation :reset_single_access_token, :if => :reset_single_access_token?
after_password_set :reset_single_access_token, :if => :change_single_access_token_with_password?
end
end
- # Resets the single_access_token to a random friendly token.
- def reset_single_access_token
- self.single_access_token = Authlogic::Random.friendly_token
- end
+ module InstanceMethods
+ # Resets the single_access_token to a random friendly token.
+ def reset_single_access_token
+ self.single_access_token = Authlogic::Random.friendly_token
+ end
- # same as reset_single_access_token, but then saves the record.
- def reset_single_access_token!
- reset_single_access_token
- save_without_session_maintenance
- end
-
- protected
- def reset_single_access_token?
- single_access_token.blank?
+ # same as reset_single_access_token, but then saves the record.
+ def reset_single_access_token!
+ reset_single_access_token
+ save_without_session_maintenance
end
+
+ protected
+ def reset_single_access_token?
+ single_access_token.blank?
+ end
- def change_single_access_token_with_password?
- aaa_config.change_single_access_token_with_password
- end
+ def change_single_access_token_with_password?
+ self.class.change_single_access_token_with_password == true
+ end
+ end
end
end
end
diff --git a/lib/authlogic/acts_as_authentic/scope.rb b/lib/authlogic/acts_as_authentic/validations_scope.rb
similarity index 68%
rename from lib/authlogic/acts_as_authentic/scope.rb
rename to lib/authlogic/acts_as_authentic/validations_scope.rb
index 825ee662..fad464f6 100644
--- a/lib/authlogic/acts_as_authentic/scope.rb
+++ b/lib/authlogic/acts_as_authentic/validations_scope.rb
@@ -3,7 +3,13 @@ module ActsAsAuthentic
# Allows you to scope everything to specific fields.
# See the Config submodule for more info.
# For information on how to scope off of a parent object see Authlogic::AuthenticatesMany
- module Scope
+ module ValidationsScope
+ def self.included(klass)
+ klass.class_eval do
+ extend Config
+ end
+ end
+
# All configuration for the scope feature.
module Config
# Allows you to scope everything to specific field(s). Works just like validates_uniqueness_of.
@@ -11,15 +17,15 @@ module Config
# company:
#
# acts_as_authentic do |c|
- # c.scope = :company_id
+ # c.validation_scope = :company_id
# end
#
# * Default: nil
# * Accepts: Symbol or Array of symbols
- def scope(value = nil)
- config(:scope, value)
+ def validations_scope(value = nil)
+ config(:validations_scope, value)
end
- alias_method :scope=, :scope
+ alias_method :validations_scope=, :validations_scope
end
end
end
diff --git a/lib/authlogic/session/password.rb b/lib/authlogic/session/password.rb
index 94b0089f..39d387c3 100644
--- a/lib/authlogic/session/password.rb
+++ b/lib/authlogic/session/password.rb
@@ -41,10 +41,10 @@ def find_by_login_method(value = nil)
# login with a field called "login" and then find users by email this is compeltely doable. See the find_by_login_method configuration
# option for more details.
#
- # * Default: Uses the configuration option in your model: User.aaa_config.login_field
+ # * Default: Uses the configuration option in your model: User.login_field
# * Accepts: Symbol or String
def login_field(value = nil)
- config(:login_field, value, klass.aaa_config.login_field || klass.aaa_config.email_field)
+ config(:login_field, value, klass.login_field || klass.email_field)
end
alias_method :login_field=, :login_field
diff --git a/lib/authlogic/session/session.rb b/lib/authlogic/session/session.rb
index 7845ff00..2a94d9dd 100644
--- a/lib/authlogic/session/session.rb
+++ b/lib/authlogic/session/session.rb
@@ -31,8 +31,10 @@ module InstanceMethods
# Tries to validate the session from information in the session
def persist_by_session
persistence_token, record_id = session_credentials
- if !persistence_token.nil? && !record_id.nil?
- record = search_for_record("find_by_#{klass.primary_key}", record_id)
+ if !persistence_token.nil?
+ # Allow finding by persistence token, because when records are created the session is maintained in a before_save, when there is no id.
+ # This is done for performance reasons and to save on queries.
+ record = record_id.nil? ? search_for_record("find_by_persistence_token", persistence_token) : search_for_record("find_by_#{klass.primary_key}", record_id)
self.unauthorized_record = record if record && record.persistence_token == persistence_token
valid?
else
diff --git a/test/acts_as_authentic_test/base_test.rb b/test/acts_as_authentic_test/base_test.rb
index 36dda3ed..78ae55b7 100644
--- a/test/acts_as_authentic_test/base_test.rb
+++ b/test/acts_as_authentic_test/base_test.rb
@@ -4,12 +4,9 @@ module ActsAsAuthenticTest
class BaseTest < ActiveSupport::TestCase
def test_acts_as_authentic
assert_nothing_raised do
- User.acts_as_authentic do |c|
+ User.acts_as_authentic do
end
end
-
- assert User.respond_to?(:aaa_config)
- assert User.new.respond_to?(:aaa_config)
end
end
end
\ No newline at end of file
diff --git a/test/acts_as_authentic_test/config_test.rb b/test/acts_as_authentic_test/config_test.rb
deleted file mode 100644
index 19296065..00000000
--- a/test/acts_as_authentic_test/config_test.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-require File.dirname(__FILE__) + '/../test_helper.rb'
-
-module ActsAsAuthenticTest
- class ConfigTest < ActiveSupport::TestCase
- def test_initialize
- c = Authlogic::ActsAsAuthentic::Config.new(User)
- assert_equal c.klass, User
- end
- end
-end
\ No newline at end of file
diff --git a/test/acts_as_authentic_test/email_test.rb b/test/acts_as_authentic_test/email_test.rb
index be22c29c..f7748f75 100644
--- a/test/acts_as_authentic_test/email_test.rb
+++ b/test/acts_as_authentic_test/email_test.rb
@@ -3,44 +3,44 @@
module ActsAsAuthenticTest
class EmailTest < ActiveSupport::TestCase
def test_email_field_config
- assert_equal :email, User.aaa_config.email_field
- assert_equal :email, Employee.aaa_config.email_field
+ assert_equal :email, User.email_field
+ assert_equal :email, Employee.email_field
- User.aaa_config.email_field = :nope
- assert_equal :nope, User.aaa_config.email_field
- User.aaa_config.email_field :email
- assert_equal :email, User.aaa_config.email_field
+ User.email_field = :nope
+ assert_equal :nope, User.email_field
+ User.email_field :email
+ assert_equal :email, User.email_field
end
def test_validate_email_field_config
- assert User.aaa_config.validate_email_field
- assert Employee.aaa_config.validate_email_field
+ assert User.validate_email_field
+ assert Employee.validate_email_field
- User.aaa_config.validate_email_field = false
- assert !User.aaa_config.validate_email_field
- User.aaa_config.validate_email_field true
- assert User.aaa_config.validate_email_field
+ User.validate_email_field = false
+ assert !User.validate_email_field
+ User.validate_email_field true
+ assert User.validate_email_field
end
def test_validates_length_of_email_field_options_config
- assert_equal({:within => 6..100}, User.aaa_config.validates_length_of_email_field_options)
- assert_equal({:within => 6..100}, Employee.aaa_config.validates_length_of_email_field_options)
+ assert_equal({:within => 6..100}, User.validates_length_of_email_field_options)
+ assert_equal({:within => 6..100}, Employee.validates_length_of_email_field_options)
- User.aaa_config.validates_length_of_email_field_options = {:yes => "no"}
- assert_equal({:yes => "no"}, User.aaa_config.validates_length_of_email_field_options)
- User.aaa_config.validates_length_of_email_field_options({:within => 6..100})
- assert_equal({:within => 6..100}, User.aaa_config.validates_length_of_email_field_options)
+ User.validates_length_of_email_field_options = {:yes => "no"}
+ assert_equal({:yes => "no"}, User.validates_length_of_email_field_options)
+ User.validates_length_of_email_field_options({:within => 6..100})
+ assert_equal({:within => 6..100}, User.validates_length_of_email_field_options)
end
def test_validates_format_of_email_field_options_config
- default = {:with => User.aaa_config.send(:email_regex), :message => I18n.t('error_messages.email_invalid', :default => "should look like an email address.")}
- assert_equal default, User.aaa_config.validates_format_of_email_field_options
- assert_equal default, Employee.aaa_config.validates_format_of_email_field_options
+ default = {:with => User.send(:email_regex), :message => I18n.t('error_messages.email_invalid', :default => "should look like an email address.")}
+ assert_equal default, User.validates_format_of_email_field_options
+ assert_equal default, Employee.validates_format_of_email_field_options
- User.aaa_config.validates_format_of_email_field_options = {:yes => "no"}
- assert_equal({:yes => "no"}, User.aaa_config.validates_format_of_email_field_options)
- User.aaa_config.validates_format_of_email_field_options default
- assert_equal default, User.aaa_config.validates_format_of_email_field_options
+ User.validates_format_of_email_field_options = {:yes => "no"}
+ assert_equal({:yes => "no"}, User.validates_format_of_email_field_options)
+ User.validates_format_of_email_field_options default
+ assert_equal default, User.validates_format_of_email_field_options
end
def test_validates_length_of_email_field
diff --git a/test/acts_as_authentic_test/logged_in_status_test.rb b/test/acts_as_authentic_test/logged_in_status_test.rb
index 587c6214..4a486515 100644
--- a/test/acts_as_authentic_test/logged_in_status_test.rb
+++ b/test/acts_as_authentic_test/logged_in_status_test.rb
@@ -3,13 +3,13 @@
module ActsAsAuthenticTest
class LoggedInStatusTest < ActiveSupport::TestCase
def test_logged_in_timeout_config
- assert_equal 10.minutes.to_i, User.aaa_config.logged_in_timeout
- assert_equal 10.minutes.to_i, Employee.aaa_config.logged_in_timeout
+ assert_equal 10.minutes.to_i, User.logged_in_timeout
+ assert_equal 10.minutes.to_i, Employee.logged_in_timeout
- User.aaa_config.logged_in_timeout = 1.hour
- assert_equal 1.hour.to_i, User.aaa_config.logged_in_timeout
- User.aaa_config.logged_in_timeout 10.minutes
- assert_equal 10.minutes.to_i, User.aaa_config.logged_in_timeout
+ User.logged_in_timeout = 1.hour
+ assert_equal 1.hour.to_i, User.logged_in_timeout
+ User.logged_in_timeout 10.minutes
+ assert_equal 10.minutes.to_i, User.logged_in_timeout
end
def test_named_scope_logged_in
diff --git a/test/acts_as_authentic_test/login_test.rb b/test/acts_as_authentic_test/login_test.rb
index b9e263fd..fa2a3999 100644
--- a/test/acts_as_authentic_test/login_test.rb
+++ b/test/acts_as_authentic_test/login_test.rb
@@ -3,44 +3,44 @@
module ActsAsAuthenticTest
class LoginTest < ActiveSupport::TestCase
def test_login_field_config
- assert_equal :login, User.aaa_config.login_field
- assert_nil Employee.aaa_config.login_field
+ assert_equal :login, User.login_field
+ assert_nil Employee.login_field
- User.aaa_config.login_field = :nope
- assert_equal :nope, User.aaa_config.login_field
- User.aaa_config.login_field :login
- assert_equal :login, User.aaa_config.login_field
+ User.login_field = :nope
+ assert_equal :nope, User.login_field
+ User.login_field :login
+ assert_equal :login, User.login_field
end
def test_validate_login_field_config
- assert User.aaa_config.validate_login_field
- assert Employee.aaa_config.validate_login_field
+ assert User.validate_login_field
+ assert Employee.validate_login_field
- User.aaa_config.validate_login_field = false
- assert !User.aaa_config.validate_login_field
- User.aaa_config.validate_login_field true
- assert User.aaa_config.validate_login_field
+ User.validate_login_field = false
+ assert !User.validate_login_field
+ User.validate_login_field true
+ assert User.validate_login_field
end
def test_validates_length_of_login_field_options_config
- assert_equal({:within => 6..100}, User.aaa_config.validates_length_of_login_field_options)
- assert_equal({:within => 6..100}, Employee.aaa_config.validates_length_of_login_field_options)
+ assert_equal({:within => 3..100}, User.validates_length_of_login_field_options)
+ assert_equal({:within => 3..100}, Employee.validates_length_of_login_field_options)
- User.aaa_config.validates_length_of_login_field_options = {:yes => "no"}
- assert_equal({:yes => "no"}, User.aaa_config.validates_length_of_login_field_options)
- User.aaa_config.validates_length_of_login_field_options({:within => 6..100})
- assert_equal({:within => 6..100}, User.aaa_config.validates_length_of_login_field_options)
+ User.validates_length_of_login_field_options = {:yes => "no"}
+ assert_equal({:yes => "no"}, User.validates_length_of_login_field_options)
+ User.validates_length_of_login_field_options({:within => 3..100})
+ assert_equal({:within => 3..100}, User.validates_length_of_login_field_options)
end
def test_validates_format_of_login_field_options_config
default = {:with => /\A\w[\w\.\-_@ ]+\z/, :message => I18n.t('error_messages.login_invalid', :default => "should use only letters, numbers, spaces, and .-_@ please.")}
- assert_equal default, User.aaa_config.validates_format_of_login_field_options
- assert_equal default, Employee.aaa_config.validates_format_of_login_field_options
+ assert_equal default, User.validates_format_of_login_field_options
+ assert_equal default, Employee.validates_format_of_login_field_options
- User.aaa_config.validates_format_of_login_field_options = {:yes => "no"}
- assert_equal({:yes => "no"}, User.aaa_config.validates_format_of_login_field_options)
- User.aaa_config.validates_format_of_login_field_options default
- assert_equal default, User.aaa_config.validates_format_of_login_field_options
+ User.validates_format_of_login_field_options = {:yes => "no"}
+ assert_equal({:yes => "no"}, User.validates_format_of_login_field_options)
+ User.validates_format_of_login_field_options default
+ assert_equal default, User.validates_format_of_login_field_options
end
def test_validates_length_of_login_field
diff --git a/test/acts_as_authentic_test/password_test.rb b/test/acts_as_authentic_test/password_test.rb
index d9143a27..0a0f5644 100644
--- a/test/acts_as_authentic_test/password_test.rb
+++ b/test/acts_as_authentic_test/password_test.rb
@@ -3,108 +3,108 @@
module ActsAsAuthenticTest
class PasswordTest < ActiveSupport::TestCase
def test_crypted_password_field_config
- assert_equal :crypted_password, User.aaa_config.crypted_password_field
- assert_equal :crypted_password, Employee.aaa_config.crypted_password_field
+ assert_equal :crypted_password, User.crypted_password_field
+ assert_equal :crypted_password, Employee.crypted_password_field
- User.aaa_config.crypted_password_field = :nope
- assert_equal :nope, User.aaa_config.crypted_password_field
- User.aaa_config.crypted_password_field :crypted_password
- assert_equal :crypted_password, User.aaa_config.crypted_password_field
+ User.crypted_password_field = :nope
+ assert_equal :nope, User.crypted_password_field
+ User.crypted_password_field :crypted_password
+ assert_equal :crypted_password, User.crypted_password_field
end
def test_password_salt_field_config
- assert_equal :password_salt, User.aaa_config.password_salt_field
- assert_equal :password_salt, Employee.aaa_config.password_salt_field
+ assert_equal :password_salt, User.password_salt_field
+ assert_equal :password_salt, Employee.password_salt_field
- User.aaa_config.password_salt_field = :nope
- assert_equal :nope, User.aaa_config.password_salt_field
- User.aaa_config.password_salt_field :password_salt
- assert_equal :password_salt, User.aaa_config.password_salt_field
+ User.password_salt_field = :nope
+ assert_equal :nope, User.password_salt_field
+ User.password_salt_field :password_salt
+ assert_equal :password_salt, User.password_salt_field
end
def test_validate_password_field_config
- assert User.aaa_config.validate_password_field
- assert Employee.aaa_config.validate_password_field
+ assert User.validate_password_field
+ assert Employee.validate_password_field
- User.aaa_config.validate_password_field = false
- assert !User.aaa_config.validate_password_field
- User.aaa_config.validate_password_field true
- assert User.aaa_config.validate_password_field
+ User.validate_password_field = false
+ assert !User.validate_password_field
+ User.validate_password_field true
+ assert User.validate_password_field
end
def test_validates_confirmation_of_password_field_options_config
- default = {:minimum => 4, :if => "#{User.aaa_config.password_salt_field}_changed?".to_sym}
- assert_equal default, User.aaa_config.validates_confirmation_of_password_field_options
- assert_equal default, Employee.aaa_config.validates_confirmation_of_password_field_options
-
- User.aaa_config.validates_confirmation_of_password_field_options = {:yes => "no"}
- assert_equal({:yes => "no"}, User.aaa_config.validates_confirmation_of_password_field_options)
- User.aaa_config.validates_confirmation_of_password_field_options default
- assert_equal default, User.aaa_config.validates_confirmation_of_password_field_options
+ default = {:minimum => 4, :if => "#{User.password_salt_field}_changed?".to_sym}
+ assert_equal default, User.validates_confirmation_of_password_field_options
+ assert_equal default, Employee.validates_confirmation_of_password_field_options
+
+ User.validates_confirmation_of_password_field_options = {:yes => "no"}
+ assert_equal({:yes => "no"}, User.validates_confirmation_of_password_field_options)
+ User.validates_confirmation_of_password_field_options default
+ assert_equal default, User.validates_confirmation_of_password_field_options
end
def test_validates_length_of_password_confirmation_field_options_config
default = {:minimum => 4, :if => :require_password_confirmation?}
- assert_equal default, User.aaa_config.validates_length_of_password_confirmation_field_options
- assert_equal default, Employee.aaa_config.validates_length_of_password_confirmation_field_options
+ assert_equal default, User.validates_length_of_password_confirmation_field_options
+ assert_equal default, Employee.validates_length_of_password_confirmation_field_options
- User.aaa_config.validates_length_of_password_confirmation_field_options = {:yes => "no"}
- assert_equal({:yes => "no"}, User.aaa_config.validates_length_of_password_confirmation_field_options)
- User.aaa_config.validates_length_of_password_confirmation_field_options default
- assert_equal default, User.aaa_config.validates_length_of_password_confirmation_field_options
+ User.validates_length_of_password_confirmation_field_options = {:yes => "no"}
+ assert_equal({:yes => "no"}, User.validates_length_of_password_confirmation_field_options)
+ User.validates_length_of_password_confirmation_field_options default
+ assert_equal default, User.validates_length_of_password_confirmation_field_options
end
def test_crypto_provider_config
- assert_equal Authlogic::CryptoProviders::Sha512, User.aaa_config.crypto_provider
- assert_equal Authlogic::CryptoProviders::AES256, Employee.aaa_config.crypto_provider
+ assert_equal Authlogic::CryptoProviders::Sha512, User.crypto_provider
+ assert_equal Authlogic::CryptoProviders::AES256, Employee.crypto_provider
- User.aaa_config.crypto_provider = Authlogic::CryptoProviders::BCrypt
- assert_equal Authlogic::CryptoProviders::BCrypt, User.aaa_config.crypto_provider
- User.aaa_config.crypto_provider Authlogic::CryptoProviders::Sha512
- assert_equal Authlogic::CryptoProviders::Sha512, User.aaa_config.crypto_provider
+ User.crypto_provider = Authlogic::CryptoProviders::BCrypt
+ assert_equal Authlogic::CryptoProviders::BCrypt, User.crypto_provider
+ User.crypto_provider Authlogic::CryptoProviders::Sha512
+ assert_equal Authlogic::CryptoProviders::Sha512, User.crypto_provider
end
def test_transition_from_crypto_providers_config
- assert_equal [], User.aaa_config.transition_from_crypto_providers
- assert_equal [], Employee.aaa_config.transition_from_crypto_providers
+ assert_equal [], User.transition_from_crypto_providers
+ assert_equal [], Employee.transition_from_crypto_providers
- User.aaa_config.transition_from_crypto_providers = [Authlogic::CryptoProviders::BCrypt]
- assert_equal [Authlogic::CryptoProviders::BCrypt], User.aaa_config.transition_from_crypto_providers
- User.aaa_config.transition_from_crypto_providers []
- assert_equal [], User.aaa_config.transition_from_crypto_providers
+ User.transition_from_crypto_providers = [Authlogic::CryptoProviders::BCrypt]
+ assert_equal [Authlogic::CryptoProviders::BCrypt], User.transition_from_crypto_providers
+ User.transition_from_crypto_providers []
+ assert_equal [], User.transition_from_crypto_providers
end
def test_act_like_restful_authentication_config
- assert !User.aaa_config.act_like_restful_authentication
- assert !Employee.aaa_config.act_like_restful_authentication
+ assert !User.act_like_restful_authentication
+ assert !Employee.act_like_restful_authentication
- User.aaa_config.act_like_restful_authentication = true
- assert User.aaa_config.act_like_restful_authentication
- assert_equal Authlogic::CryptoProviders::Sha1, User.aaa_config.crypto_provider
+ User.act_like_restful_authentication = true
+ assert User.act_like_restful_authentication
+ assert_equal Authlogic::CryptoProviders::Sha1, User.crypto_provider
assert defined?(::REST_AUTH_SITE_KEY)
assert_equal 1, Authlogic::CryptoProviders::Sha1.stretches
- User.aaa_config.act_like_restful_authentication false
- assert !User.aaa_config.act_like_restful_authentication
+ User.act_like_restful_authentication false
+ assert !User.act_like_restful_authentication
- User.aaa_config.crypto_provider = Authlogic::CryptoProviders::Sha512
- User.aaa_config.transition_from_crypto_providers = []
+ User.crypto_provider = Authlogic::CryptoProviders::Sha512
+ User.transition_from_crypto_providers = []
end
def test_transition_from_restful_authentication_config
- assert !User.aaa_config.transition_from_restful_authentication
- assert !Employee.aaa_config.transition_from_restful_authentication
+ assert !User.transition_from_restful_authentication
+ assert !Employee.transition_from_restful_authentication
- User.aaa_config.transition_from_restful_authentication = true
- assert User.aaa_config.transition_from_restful_authentication
+ User.transition_from_restful_authentication = true
+ assert User.transition_from_restful_authentication
assert defined?(::REST_AUTH_SITE_KEY)
assert_equal 1, Authlogic::CryptoProviders::Sha1.stretches
- User.aaa_config.transition_from_restful_authentication false
- assert !User.aaa_config.transition_from_restful_authentication
+ User.transition_from_restful_authentication false
+ assert !User.transition_from_restful_authentication
- User.aaa_config.crypto_provider = Authlogic::CryptoProviders::Sha512
- User.aaa_config.transition_from_crypto_providers = []
+ User.crypto_provider = Authlogic::CryptoProviders::Sha512
+ User.transition_from_crypto_providers = []
end
def test_validates_confirmation_of_password
diff --git a/test/acts_as_authentic_test/perishable_token_test.rb b/test/acts_as_authentic_test/perishable_token_test.rb
index d32375b7..79eb09e1 100644
--- a/test/acts_as_authentic_test/perishable_token_test.rb
+++ b/test/acts_as_authentic_test/perishable_token_test.rb
@@ -3,23 +3,23 @@
module ActsAsAuthenticTest
class PerishableTokenTest < ActiveSupport::TestCase
def test_perishable_token_valid_for_config
- assert_equal 10.minutes.to_i, User.aaa_config.perishable_token_valid_for
- assert_equal 10.minutes.to_i, Employee.aaa_config.perishable_token_valid_for
+ assert_equal 10.minutes.to_i, User.perishable_token_valid_for
+ assert_equal 10.minutes.to_i, Employee.perishable_token_valid_for
- User.aaa_config.perishable_token_valid_for = 1.hour
- assert_equal 1.hour.to_i, User.aaa_config.perishable_token_valid_for
- User.aaa_config.perishable_token_valid_for 10.minutes
- assert_equal 10.minutes.to_i, User.aaa_config.perishable_token_valid_for
+ User.perishable_token_valid_for = 1.hour
+ assert_equal 1.hour.to_i, User.perishable_token_valid_for
+ User.perishable_token_valid_for 10.minutes
+ assert_equal 10.minutes.to_i, User.perishable_token_valid_for
end
def test_disable_perishable_token_maintenance_config
- assert !User.aaa_config.disable_perishable_token_maintenance
- assert !Employee.aaa_config.disable_perishable_token_maintenance
+ assert !User.disable_perishable_token_maintenance
+ assert !Employee.disable_perishable_token_maintenance
- User.aaa_config.disable_perishable_token_maintenance = true
- assert User.aaa_config.disable_perishable_token_maintenance
- User.aaa_config.disable_perishable_token_maintenance false
- assert !User.aaa_config.disable_perishable_token_maintenance
+ User.disable_perishable_token_maintenance = true
+ assert User.disable_perishable_token_maintenance
+ User.disable_perishable_token_maintenance false
+ assert !User.disable_perishable_token_maintenance
end
def test_validates_uniqueness_of_perishable_token
diff --git a/test/acts_as_authentic_test/single_access_test.rb b/test/acts_as_authentic_test/single_access_test.rb
index 9c19452b..7b12c79d 100644
--- a/test/acts_as_authentic_test/single_access_test.rb
+++ b/test/acts_as_authentic_test/single_access_test.rb
@@ -3,13 +3,13 @@
module ActsAsAuthenticTest
class SingleAccessTest < ActiveSupport::TestCase
def test_change_single_access_token_with_password_config
- assert !User.aaa_config.change_single_access_token_with_password
- assert !Employee.aaa_config.change_single_access_token_with_password
+ assert !User.change_single_access_token_with_password
+ assert !Employee.change_single_access_token_with_password
- User.aaa_config.change_single_access_token_with_password = true
- assert User.aaa_config.change_single_access_token_with_password
- User.aaa_config.change_single_access_token_with_password false
- assert !User.aaa_config.change_single_access_token_with_password
+ User.change_single_access_token_with_password = true
+ assert User.change_single_access_token_with_password
+ User.change_single_access_token_with_password false
+ assert !User.change_single_access_token_with_password
end
def test_validates_uniqueness_of_single_access_token
@@ -26,14 +26,14 @@ def test_before_validation_reset_single_access_token
end
def test_after_password_set_reset_single_access_token
- User.aaa_config.change_single_access_token_with_password = true
+ User.change_single_access_token_with_password = true
ben = users(:ben)
old_single_access_token = ben.single_access_token
ben.password = "new_pass"
assert_not_equal old_single_access_token, ben.single_access_token
- User.aaa_config.change_single_access_token_with_password = false
+ User.change_single_access_token_with_password = false
end
end
end
\ No newline at end of file
diff --git a/test/fixtures/employees.yml b/test/fixtures/employees.yml
index e8013e08..c30e931c 100644
--- a/test/fixtures/employees.yml
+++ b/test/fixtures/employees.yml
@@ -2,7 +2,7 @@ drew:
company: binary_logic
email: dgainor@binarylogic.com
password_salt: <%= salt = Authlogic::Random.hex_token %>
- crypted_password: '<%= Employee.aaa_config.crypto_provider.encrypt("drewrocks" + salt) %>'
+ crypted_password: '<%= Employee.crypto_provider.encrypt("drewrocks" + salt) %>'
persistence_token: 5273d85ed156e9dbd6a7c1438d319ef8c8d41dd24368db6c222de11346c7b11e53ee08d45ecf619b1c1dc91233d22b372482b751b066d0a6f6f9bac42eacaabf
first_name: Drew
last_name: Gainor
@@ -11,7 +11,7 @@ jennifer:
company: logic_over_data
email: jjohnson@logicoverdata.com
password_salt: <%= salt = Authlogic::Random.hex_token %>
- crypted_password: '<%= Employee.aaa_config.crypto_provider.encrypt("jenniferocks" + salt) %>'
+ crypted_password: '<%= Employee.crypto_provider.encrypt("jenniferocks" + salt) %>'
persistence_token: 2be52a8f741ad00056e6f94eb6844d5316527206da7a3a5e3d0e14d19499ef9fe4c47c89b87febb59a2b41a69edfb4733b6b79302040f3de83f297c6991c75a2
first_name: Jennifer
last_name: Johnson
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 07e8b3e6..78b9711b 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -3,10 +3,6 @@
require "ruby-debug"
require "active_record"
require 'active_record/fixtures'
-require File.dirname(__FILE__) + '/../lib/authlogic' unless defined?(Authlogic)
-require File.dirname(__FILE__) + '/libs/mock_request'
-require File.dirname(__FILE__) + '/libs/mock_cookie_jar'
-require File.dirname(__FILE__) + '/libs/mock_controller'
ActiveRecord::Schema.verbose = false
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
@@ -75,6 +71,10 @@
end
end
+require File.dirname(__FILE__) + '/../lib/authlogic' unless defined?(Authlogic)
+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/project'
require File.dirname(__FILE__) + '/libs/employee'
require File.dirname(__FILE__) + '/libs/employee_session'