FEATURE: new setting to validate user website

This commit is contained in:
Arpit Jalan
2016-12-26 20:54:54 +05:30
parent d46b0a7251
commit d72cbcb2a4
4 changed files with 29 additions and 9 deletions

View File

@ -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