logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

unreserved_username_validator.rb (655B)


  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 pam_controlled?(value)
  9. return false unless Devise.pam_authentication && Devise.pam_controlled_service
  10. Rpam2.account(Devise.pam_controlled_service, value).present?
  11. end
  12. def reserved_username?(value)
  13. return true if pam_controlled?(value)
  14. return false unless Setting.reserved_usernames
  15. Setting.reserved_usernames.include?(value.downcase)
  16. end
  17. end