mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
FEATURE: new setting to validate user website
This commit is contained in:
@ -12,6 +12,8 @@ class UserProfile < ActiveRecord::Base
|
||||
validates :profile_background, upload_url: true, if: :profile_background_changed?
|
||||
validates :card_background, upload_url: true, if: :card_background_changed?
|
||||
|
||||
validate :website_domain_validator, if: Proc.new { |c| c.new_record? || c.website_changed? }
|
||||
|
||||
belongs_to :card_image_badge, class_name: 'Badge'
|
||||
has_many :user_profile_views, dependent: :destroy
|
||||
|
||||
@ -102,6 +104,14 @@ class UserProfile < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def website_domain_validator
|
||||
allowed_domains = SiteSetting.user_website_domains_whitelist
|
||||
return if (allowed_domains.blank? || self.website.blank?)
|
||||
|
||||
domain = URI.parse(self.website).host
|
||||
self.errors.add :base, (I18n.t('user.website.domain_not_allowed', domains: allowed_domains.split('|').join(", "))) unless allowed_domains.split('|').include?(domain)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# == Schema Information
|
||||
|
Reference in New Issue
Block a user