This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/lib/validators/max_username_length_validator.rb
2018-10-02 15:24:12 +08:00

20 lines
499 B
Ruby

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(:username).first
@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