diff --git a/app/models/user.rb b/app/models/user.rb index 638928861bd..5970326ae6f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -90,15 +90,15 @@ class User < ApplicationRecord validates :display_name, :presence => true, :length => 3..255, :exclusion => %w[new terms save confirm confirm-email go_public reset-password forgot-password suspended] - validates :display_name, :if => proc { |u| u.display_name_changed? }, + validates :display_name, :if => proc { |u| u.new_record? || u.display_name_changed? }, :uniqueness => { :case_sensitive => false } - validates :display_name, :if => proc { |u| u.display_name_changed? }, + validates :display_name, :if => proc { |u| u.new_record? || u.display_name_changed? }, :characters => { :url_safe => true }, :whitespace => { :leading => false, :trailing => false } validates :email, :presence => true, :confirmation => true, :characters => true - validates :email, :if => proc { |u| u.email_changed? }, + validates :email, :if => proc { |u| u.new_record? || u.email_changed? }, :uniqueness => { :case_sensitive => false } - validates :email, :if => proc { |u| u.email_changed? }, + validates :email, :if => proc { |u| u.new_record? || u.email_changed? }, :whitespace => { :leading => false, :trailing => false } validates :pass_crypt, :confirmation => true, :length => 8..255 validates :home_lat, :allow_nil => true, :numericality => true, :inclusion => { :in => -90..90 } @@ -110,8 +110,8 @@ class User < ApplicationRecord validates :avatar, :if => proc { |u| u.attachment_changes["avatar"] }, :image => true - validates_email_format_of :email, :if => proc { |u| u.email_changed? } - validates_email_format_of :new_email, :allow_blank => true, :if => proc { |u| u.new_email_changed? } + validates_email_format_of :email, :if => proc { |u| u.new_record? || u.email_changed? } + validates_email_format_of :new_email, :allow_blank => true, :if => proc { |u| u.new_record? || u.new_email_changed? } alias_attribute :created_at, :creation_time