2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-08-22 14:49:52 -05:00
|
|
|
class MaxUsernameLengthValidator
|
|
|
|
def initialize(opts = {})
|
|
|
|
@opts = opts
|
|
|
|
end
|
|
|
|
|
|
|
|
def valid_value?(value)
|
|
|
|
return false if value < SiteSetting.min_username_length
|
2019-10-21 05:32:27 -05:00
|
|
|
@username = User.where('length(username) > ?', value).pluck_first(:username)
|
2018-10-02 02:20:19 -05:00
|
|
|
@username.blank?
|
2018-08-22 14:49:52 -05:00
|
|
|
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
|