- scope :visible, -> { where(:status => ["pending", "active", "confirmed"]) }
- scope :active, -> { where(:status => ["active", "confirmed"]) }
- scope :public, -> { where(:data_public => true) }
-
- 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, :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
- validates_email_format_of :email, :if => Proc.new { |u| u.email_changed? }
- validates_email_format_of :new_email, :allow_blank => true, :if => Proc.new { |u| u.new_email_changed? }
- validates_format_of :display_name, :with => /\A[^\/;.,?%#]*\z/, :if => Proc.new { |u| u.display_name_changed? }
- validates_format_of :display_name, :with => /\A\S/, :message => "has leading whitespace", :if => Proc.new { |u| u.display_name_changed? }
- validates_format_of :display_name, :with => /\S\z/, :message => "has trailing whitespace", :if => Proc.new { |u| u.display_name_changed? }
- validates_numericality_of :home_lat, :allow_nil => true
- validates_numericality_of :home_lon, :allow_nil => true
- validates_numericality_of :home_zoom, :only_integer => true, :allow_nil => true
- validates_inclusion_of :preferred_editor, :in => Editors::ALL_EDITORS, :allow_nil => true
-
- after_initialize :set_defaults
+ has_many :issues, :class_name => "Issue", :foreign_key => :reported_user_id, :inverse_of => :reported_user
+ has_many :issue_comments
+
+ has_many :reports
+
+ scope :visible, -> { where(:status => %w[pending active confirmed]) }
+ scope :active, -> { where(:status => %w[active confirmed]) }
+ scope :identifiable, -> { where(:data_public => true) }
+
+ has_one_attached :avatar, :service => Settings.avatar_storage
+
+ 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? },
+ :uniqueness => { :case_sensitive => false }
+ validates :display_name, :if => proc { |u| 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? },
+ :uniqueness => { :case_sensitive => false }
+ validates :email, :if => proc { |u| 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 }
+ validates :home_lon, :allow_nil => true, :numericality => true, :inclusion => { :in => -180..180 }
+ validates :home_zoom, :allow_nil => true, :numericality => { :only_integer => true }
+ validates :preferred_editor, :inclusion => Editors::ALL_EDITORS, :allow_nil => true
+ validates :auth_uid, :unless => proc { |u| u.auth_provider.nil? },
+ :uniqueness => { :scope => :auth_provider }
+ 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? }
+
+ alias_attribute :created_at, :creation_time
+