diff --git a/app/models/person.rb b/app/models/person.rb index 6ab4a9109..45128e3db 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -20,7 +20,7 @@ class Person < ActiveRecord::Base has_one :profile delegate :last_name, :to => :profile - before_save :downcase_diaspora_handle + before_validation :downcase_diaspora_handle def downcase_diaspora_handle diaspora_handle.downcase! end @@ -39,7 +39,7 @@ class Person < ActiveRecord::Base before_validation :clean_url validates_presence_of :url, :profile, :serialized_public_key - validates_uniqueness_of :diaspora_handle, :case_sensitive => false + validates_uniqueness_of :diaspora_handle scope :searchable, joins(:profile).where(:profiles => {:searchable => true}) @@ -230,7 +230,7 @@ class Person < ActiveRecord::Base def remove_all_traces Notification.joins(:notification_actors).where(:notification_actors => {:person_id => self.id}).all.each{ |n| n.destroy} end - + def fix_profile Webfinger.new(self.diaspora_handle).fetch self.reload diff --git a/app/models/user.rb b/app/models/user.rb index 93e0cce1b..8707c4f6d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -19,7 +19,7 @@ class User < ActiveRecord::Base before_validation :set_current_language, :on => :create validates_presence_of :username - validates_uniqueness_of :username, :case_sensitive => false + validates_uniqueness_of :username validates_format_of :username, :with => /\A[A-Za-z0-9_]+\z/ validates_length_of :username, :maximum => 32 validates_inclusion_of :language, :in => AVAILABLE_LANGUAGE_CODES @@ -76,12 +76,13 @@ class User < ActiveRecord::Base self.language = I18n.locale.to_s if self.language.blank? end - def self.find_for_authentication(conditions={}) + def self.find_for_database_authentication(conditions={}) + conditions = conditions.dup conditions[:username] = conditions[:username].downcase if conditions[:username] =~ /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i # email regex conditions[:email] = conditions.delete(:username) end - super(conditions) + where(conditions).first end def can_add?(person) diff --git a/db/migrate/20110512220310_downcase_usernames_again.rb b/db/migrate/20110512220310_downcase_usernames_again.rb new file mode 100644 index 000000000..02eeed8eb --- /dev/null +++ b/db/migrate/20110512220310_downcase_usernames_again.rb @@ -0,0 +1,10 @@ +require 'db/migrate/20110421120744_downcase_usernames' +class DowncaseUsernamesAgain < ActiveRecord::Migration + def self.up + DowncaseUsernames.up + end + + def self.down + DowncaseUsernames.down + end +end