The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

24 lines
651 B

  1. # frozen_string_literal: true
  2. class UnreservedUsernameValidator < ActiveModel::Validator
  3. def validate(account)
  4. @username = account.username
  5. return if @username.nil?
  6. account.errors.add(:username, I18n.t('accounts.reserved_username')) if reserved_username?
  7. end
  8. private
  9. def pam_controlled?
  10. return false unless Devise.pam_authentication && Devise.pam_controlled_service
  11. Rpam2.account(Devise.pam_controlled_service, @username).present?
  12. end
  13. def reserved_username?
  14. return true if pam_controlled?
  15. return false unless Setting.reserved_usernames
  16. Setting.reserved_usernames.include?(@username.downcase)
  17. end
  18. end