authlogic 2.0.8 → 2.0.9

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,3 +1,8 @@
1
+ == 2.0.9 release 2009-4-9
2
+
3
+ * Fixed bug where hooks provided by the password module were called when the password module was not being used due to the fact that the password field did not exist.
4
+ * Fixed bug where the find_with_login method was not being aliased if you were using an alternate field besides login.
5
+
1
6
  == 2.0.8 release 2009-4-9
2
7
 
3
8
  * Dont reset the @password_changed instance variable to false because its halts the callback chain, instead reset it to nil.
@@ -61,13 +61,13 @@ module Authlogic
61
61
  acts_as_authentic_modules.delete(mod)
62
62
  acts_as_authentic_modules
63
63
  end
64
-
64
+
65
65
  private
66
66
  def acts_as_authentic_modules
67
67
  key = :acts_as_authentic_modules
68
68
  inheritable_attributes.include?(key) ? read_inheritable_attribute(key) : []
69
69
  end
70
-
70
+
71
71
  def config(key, value, default_value = nil, read_value = nil)
72
72
  if value == read_value
73
73
  inheritable_attributes.include?(key) ? read_inheritable_attribute(key) : default_value
@@ -75,12 +75,11 @@ module Authlogic
75
75
  write_inheritable_attribute(key, value)
76
76
  end
77
77
  end
78
-
78
+
79
79
  def first_column_to_exist(*columns_to_check)
80
80
  columns_to_check.each { |column_name| return column_name.to_sym if column_names.include?(column_name.to_s) }
81
81
  columns_to_check.first && columns_to_check.first.to_sym
82
82
  end
83
-
84
83
  end
85
84
  end
86
85
  end
@@ -73,8 +73,6 @@ module Authlogic
73
73
  module Methods
74
74
  def self.included(klass)
75
75
  klass.class_eval do
76
- extend ClassMethods
77
-
78
76
  if validate_email_field && email_field
79
77
  validates_length_of email_field, validates_length_of_email_field_options
80
78
  validates_format_of email_field, validates_format_of_email_field_options
@@ -82,24 +80,6 @@ module Authlogic
82
80
  end
83
81
  end
84
82
  end
85
-
86
- # Class methods relating to the email field
87
- module ClassMethods
88
- # Calls alias_method if your email_field name is "out of the norm".
89
- def self.included(klass)
90
- klass.send(:alias_method, "find_with_email", "find_with_#{email_field}") if klass.email_field != :email
91
- end
92
-
93
- # Please see the find_with_login method in Authlogic::ActsAsAuthentic::Login module. It's the same exact thing
94
- # but for the login field instead of the email field.
95
- def find_with_email(email)
96
- if validates_uniqueness_of_email_field_options[:case_sensitive] == false
97
- first(:conditions => ["LOWER(#{quoted_table_name}.#{email_field}) = ?", email.downcase])
98
- else
99
- send("find_by_#{email_field}", email)
100
- end
101
- end
102
- end
103
83
  end
104
84
  end
105
85
  end
@@ -55,6 +55,39 @@ module Authlogic
55
55
  config(:validates_uniqueness_of_login_field_options, value, {:case_sensitive => false, :scope => validations_scope, :if => "#{login_field}_changed?".to_sym})
56
56
  end
57
57
  alias_method :validates_uniqueness_of_login_field_options=, :validates_uniqueness_of_login_field_options
58
+
59
+ # This method allows you to find a record with the given login. If you notice, with ActiveRecord you have the
60
+ # validates_uniqueness_of validation function. They give you a :case_sensitive option. I handle this in the same
61
+ # manner that they handle that. If you are using the login field and set false for the :case_sensitive option in
62
+ # validates_uniqueness_of_login_field_options this method will modify the query to look something like:
63
+ #
64
+ # first(:conditions => ["LOWER(#{quoted_table_name}.#{login_field}) = ?", login.downcase])
65
+ #
66
+ # If you don't specify this it calls the good old find_by_* method:
67
+ #
68
+ # find_by_login(login)
69
+ #
70
+ # The above also applies for using email as your login, except that you need to set the :case_sensitive in
71
+ # validates_uniqueness_of_email_field_options to false.
72
+ #
73
+ # The only reason I need to do the above is for Postgres and SQLite since they perform case sensitive searches with the
74
+ # find_by_* methods.
75
+ def find_by_smart_case_login_field(login)
76
+ if login_field
77
+ find_with_case(login_field, login, validates_uniqueness_of_login_field_options[:case_sensitive] != false)
78
+ else
79
+ find_with_case(email_field, login, validates_uniqueness_of_email_field_options[:case_sensitive] != false)
80
+ end
81
+ end
82
+
83
+ private
84
+ def find_with_case(field, value, sensitivity = true)
85
+ if sensitivity
86
+ send("find_by_#{field}", value)
87
+ else
88
+ first(:conditions => ["LOWER(#{quoted_table_name}.#{field}) = ?", value.downcase])
89
+ end
90
+ end
58
91
  end
59
92
 
60
93
  # All methods relating to the login field
@@ -62,8 +95,6 @@ module Authlogic
62
95
  # Adds in various validations, modules, etc.
63
96
  def self.included(klass)
64
97
  klass.class_eval do
65
- extend ClassMethods
66
-
67
98
  if validate_login_field && login_field
68
99
  validates_length_of login_field, validates_length_of_login_field_options
69
100
  validates_format_of login_field, validates_format_of_login_field_options
@@ -71,35 +102,6 @@ module Authlogic
71
102
  end
72
103
  end
73
104
  end
74
-
75
- # Class methods relating to the login field.
76
- module ClassMethods
77
- # Calls alias_method if your login_field name is "out of the norm".
78
- def self.included(klass)
79
- klass.send(:alias_method, "find_with_login", "find_with_#{login_field}") if klass.login_field != :login
80
- end
81
-
82
- # This method allows you to find a record with the given login. If you notice, with ActiveRecord you have the
83
- # validates_uniqueness_of validation function. They give you a :case_sensitive option. I handle this in the same
84
- # manner that they handle that. If you set false for the :case_sensitive option in validates_uniqueness_of_login_field_options
85
- # this method will modify the query to look something like:
86
- #
87
- # first(:conditions => ["LOWER(#{quoted_table_name}.#{login_field}) = ?", login.downcase])
88
- #
89
- # If you don't specify this it calls the good old find_by_* method:
90
- #
91
- # find_by_login(login)
92
- #
93
- # The only reason I need to do the above is for Postgres and SQLite since they perform case sensitive searches with the
94
- # find_by_* methods.
95
- def find_with_login(login)
96
- if validates_uniqueness_of_login_field_options[:case_sensitive] == false
97
- first(:conditions => ["LOWER(#{quoted_table_name}.#{login_field}) = ?", login.downcase])
98
- else
99
- send("find_by_#{login_field}", login)
100
- end
101
- end
102
- end
103
105
  end
104
106
  end
105
107
  end
@@ -118,7 +118,7 @@ module Authlogic
118
118
  ]
119
119
 
120
120
  def self.included(klass)
121
- return if !klass.column_names.include?(klass.crypted_password_field.to_s)
121
+ return if klass.crypted_password_field.nil?
122
122
  klass.define_callbacks *METHODS
123
123
  end
124
124
 
@@ -135,7 +135,7 @@ module Authlogic
135
135
  # The methods related to the password field.
136
136
  module Methods
137
137
  def self.included(klass)
138
- return if !klass.column_names.include?(klass.crypted_password_field.to_s)
138
+ return if klass.crypted_password_field.nil?
139
139
 
140
140
  klass.class_eval do
141
141
  include InstanceMethods
@@ -16,8 +16,10 @@ module Authlogic
16
16
  extend ClassMethods
17
17
  include InstanceMethods
18
18
 
19
- after_password_set :reset_persistence_token
20
- after_password_verification :reset_persistence_token!, :if => :reset_persistence_token?
19
+ if respond_to?(:after_password_set) && respond_to?(:after_password_verification)
20
+ after_password_set :reset_persistence_token
21
+ after_password_verification :reset_persistence_token!, :if => :reset_persistence_token?
22
+ end
21
23
 
22
24
  validates_presence_of :persistence_token
23
25
  validates_uniqueness_of :persistence_token, :if => :persistence_token_changed?
@@ -32,10 +32,10 @@ module Authlogic
32
32
  # Now just specifcy the name of this method for this configuration option and you are all set. You can do anything you want here. Maybe you allow users to have multiple logins
33
33
  # and you want to search a has_many relationship, etc. The sky is the limit.
34
34
  #
35
- # * <tt>Default:</tt> "find_by_case_insensitive_#{login_field}"
35
+ # * <tt>Default:</tt> "find_by_smart_case_login_field"
36
36
  # * <tt>Accepts:</tt> Symbol or String
37
37
  def find_by_login_method(value = nil)
38
- config(:find_by_login_method, value, "find_with_#{login_field}")
38
+ config(:find_by_login_method, value, "find_by_smart_case_login_field")
39
39
  end
40
40
  alias_method :find_by_login_method=, :find_by_login_method
41
41
 
@@ -41,7 +41,7 @@ module Authlogic # :nodoc:
41
41
 
42
42
  MAJOR = 2
43
43
  MINOR = 0
44
- TINY = 8
44
+ TINY = 9
45
45
 
46
46
  # The current version as a Version instance
47
47
  CURRENT = new(MAJOR, MINOR, TINY)
@@ -89,12 +89,5 @@ module ActsAsAuthenticTest
89
89
  assert !u.valid?
90
90
  assert !u.errors.on(:email)
91
91
  end
92
-
93
- def test_find_with_email
94
- ben = users(:ben)
95
- assert_equal ben, User.find_with_email("bjohnson@binarylogic.com")
96
- assert_equal ben, User.find_with_email("bJohnson@binarylogic.com")
97
- assert_equal ben, User.find_with_email("BJOHNSON@BINARYLOGIC.COM")
98
- end
99
92
  end
100
93
  end
@@ -90,11 +90,16 @@ module ActsAsAuthenticTest
90
90
  assert !u.errors.on(:login)
91
91
  end
92
92
 
93
- def test_find_with_login
93
+ def test_find_by_smart_case_login_field
94
94
  ben = users(:ben)
95
- assert_equal ben, User.find_with_login("bjohnson")
96
- assert_equal ben, User.find_with_login("BJOHNSON")
97
- assert_equal ben, User.find_with_login("Bjohnson")
95
+ assert_equal ben, User.find_by_smart_case_login_field("bjohnson")
96
+ assert_equal ben, User.find_by_smart_case_login_field("BJOHNSON")
97
+ assert_equal ben, User.find_by_smart_case_login_field("Bjohnson")
98
+
99
+ drew = employees(:drew)
100
+ assert_equal drew, Employee.find_by_smart_case_login_field("dgainor@binarylogic.com")
101
+ assert_equal drew, Employee.find_by_smart_case_login_field("Dgainor@binarylogic.com")
102
+ assert_equal drew, Employee.find_by_smart_case_login_field("DGAINOR@BINARYLOGIC.COM")
98
103
  end
99
104
  end
100
105
  end
@@ -69,11 +69,22 @@ ActiveRecord::Schema.define(:version => 1) do
69
69
  t.string :current_login_ip
70
70
  t.string :last_login_ip
71
71
  end
72
+
73
+ create_table :affiliates do |t|
74
+ t.datetime :created_at
75
+ t.datetime :updated_at
76
+ t.integer :company_id
77
+ t.string :username
78
+ t.string :pw_hash
79
+ t.string :pw_salt
80
+ t.string :persistence_token
81
+ end
72
82
  end
73
83
 
74
84
  require File.dirname(__FILE__) + '/../lib/authlogic' unless defined?(Authlogic)
75
85
  require File.dirname(__FILE__) + '/../lib/authlogic/test_case'
76
86
  require File.dirname(__FILE__) + '/libs/project'
87
+ require File.dirname(__FILE__) + '/libs/affiliate'
77
88
  require File.dirname(__FILE__) + '/libs/employee'
78
89
  require File.dirname(__FILE__) + '/libs/employee_session'
79
90
  require File.dirname(__FILE__) + '/libs/user'
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: 2.0.8
4
+ version: 2.0.9
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: 2009-04-09 00:00:00 -04:00
12
+ date: 2009-04-11 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency