闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

15 lines
429 B

  1. # frozen_string_literal: true
  2. class UnreservedUsernameValidator < ActiveModel::Validator
  3. def validate(account)
  4. return if account.username.nil?
  5. account.errors.add(:username, I18n.t('accounts.reserved_username')) if reserved_username?(account.username)
  6. end
  7. private
  8. def reserved_username?(value)
  9. return false unless Setting.reserved_usernames
  10. Setting.reserved_usernames.include?(value.downcase)
  11. end
  12. end