mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
UX: Improve error messages for minimum and maximum username lengths.
This commit is contained in:
committed by
Guo Xiang Tan
parent
7591da1e64
commit
e0d7cdac12
19
lib/validators/max_username_length_validator.rb
Normal file
19
lib/validators/max_username_length_validator.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
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? ? true : false
|
||||
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
|
||||
Reference in New Issue
Block a user