FEATURE: make username suggester suggest user1, user2 etc. for input that contains invalid characters only (#14179)

We were suggesting 111, 1111, 1112 before.

See the discussion on Meta – https://meta.discourse.org/t/curious-account-creation-behaviour/199970/14.
This commit is contained in:
Andrei Prigorshnev
2021-10-04 16:47:55 +04:00
committed by GitHub
parent 34cebfd867
commit 149e869c22
3 changed files with 21 additions and 5 deletions
+8 -1
View File
@@ -2,6 +2,7 @@
module UserNameSuggester
GENERIC_NAMES = ['i', 'me', 'info', 'support', 'admin', 'webmaster', 'hello', 'mail', 'office', 'contact', 'team']
LAST_RESORT_USERNAME = "user"
def self.suggest(name_or_email, allowed_username = nil)
return unless name_or_email.present?
@@ -102,7 +103,13 @@ module UserNameSuggester
end
def self.fix_username(name)
rightsize_username(sanitize_username(name))
fixed_username = sanitize_username(name)
if fixed_username.empty?
fixed_username << sanitize_username(I18n.t('fallback_username'))
fixed_username << LAST_RESORT_USERNAME if fixed_username.empty?
end
rightsize_username(fixed_username)
end
def self.sanitize_username(name)