]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/user.rb
Require user names and emails to be case insensitively unique
[rails.git] / app / models / user.rb
index 759c8d0b04f81b24690b28719c153af96963eff3..56c8890b5b3c645674f2973cd4a0d18d00114c12 100644 (file)
@@ -18,11 +18,14 @@ class User < ActiveRecord::Base
   has_many :active_blocks, :class_name => "UserBlock", :conditions => proc { [ "user_blocks.ends_at > :ends_at or user_blocks.needs_view", { :ends_at => Time.now.getutc } ] }
   has_many :roles, :class_name => "UserRole"
 
+  scope :visible, where(:status => ["pending", "active", "confirmed"])
+  scope :active, where(:status => ["active", "confirmed"])
+
   validates_presence_of :email, :display_name
   validates_confirmation_of :email#, :message => ' addresses must match'
   validates_confirmation_of :pass_crypt#, :message => ' must match the confirmation password'
-  validates_uniqueness_of :display_name, :allow_nil => true
-  validates_uniqueness_of :email
+  validates_uniqueness_of :display_name, :allow_nil => true, :case_sensitive => false, :if => Proc.new { |u| u.display_name_changed? }
+  validates_uniqueness_of :email, :case_sensitive => false, :if => Proc.new { |u| u.email_changed? }
   validates_uniqueness_of :openid_url, :allow_nil => true
   validates_length_of :pass_crypt, :within => 8..255
   validates_length_of :display_name, :within => 3..255, :allow_nil => true