2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-06 10:50:21 +08:00
discourse/lib/validators/max_username_length_validator.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

22 lines
530 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class MaxUsernameLengthValidator
def initialize(opts = {})
@opts = opts
end
def valid_value?(value)
return false if value < SiteSetting.min_username_length
@username = User.where('length(username) > ?', value).pluck_first(:username)
2018-10-02 15:20:19 +08:00
@username.blank?
end
def error_message
if @username.blank?
I18n.t("site_settings.errors.max_username_length_range")
else
I18n.t("site_settings.errors.max_username_length_exists", username: @username)
end
end
end