diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2017-06-05 01:03:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-05 01:03:45 +0200 |
commit | f7a30e2fae3199a82e2ad23bb9d761d1fe1be8de (patch) | |
tree | 5934d035c66396fd0f5cbca17baec19a9440de13 /app/validators/unreserved_validator.rb | |
parent | 3f815b2052f0528bd84fa2c856c69985876561eb (diff) |
Added support for configurable reserved usernames (fix of #1382) (#3566)
* Added support for configurable reserved usernames * Added reserved usernames from mastodon issue 1355 * Fix reserved usernames
Diffstat (limited to 'app/validators/unreserved_validator.rb')
-rw-r--r-- | app/validators/unreserved_validator.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/app/validators/unreserved_validator.rb b/app/validators/unreserved_validator.rb new file mode 100644 index 000000000..4e5b9dafc --- /dev/null +++ b/app/validators/unreserved_validator.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class UnreservedValidator < ActiveModel::EachValidator + def validate_each(record, attribute, value) + return if value.nil? + record.errors.add(attribute, I18n.t('accounts.reserved_username')) if reserved_username?(value) + end + + private + + def reserved_username?(value) + return false unless Setting.reserved_usernames + Setting.reserved_usernames.include?(value.downcase) + end +end |