mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
more username cycling avoidance
This commit is contained in:
parent
0c287d7d6b
commit
d80ed94608
2 changed files with 6 additions and 7 deletions
|
@ -115,9 +115,8 @@ class DiscourseSingleSignOn < SingleSignOn
|
||||||
end
|
end
|
||||||
|
|
||||||
if SiteSetting.sso_overrides_username &&
|
if SiteSetting.sso_overrides_username &&
|
||||||
user.username != username &&
|
user.username != username
|
||||||
user.username != UserNameSuggester.fix_username(username || name || email)
|
user.username = UserNameSuggester.suggest(username || name || email, user.username)
|
||||||
user.username = UserNameSuggester.suggest(username || name || email)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if SiteSetting.sso_overrides_name && user.name != name
|
if SiteSetting.sso_overrides_name && user.name != name
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
module UserNameSuggester
|
module UserNameSuggester
|
||||||
|
|
||||||
def self.suggest(name)
|
def self.suggest(name, allow_username = nil)
|
||||||
return unless name.present?
|
return unless name.present?
|
||||||
name = parse_name_from_email(name)
|
name = parse_name_from_email(name)
|
||||||
find_available_username_based_on(name)
|
find_available_username_based_on(name, allow_username)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.parse_name_from_email(name)
|
def self.parse_name_from_email(name)
|
||||||
|
@ -16,11 +16,11 @@ module UserNameSuggester
|
||||||
name
|
name
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.find_available_username_based_on(name)
|
def self.find_available_username_based_on(name, allow_username = nil)
|
||||||
name = fix_username(name)
|
name = fix_username(name)
|
||||||
i = 1
|
i = 1
|
||||||
attempt = name
|
attempt = name
|
||||||
until User.username_available?(attempt)
|
until attempt == allow_username || User.username_available?(attempt)
|
||||||
suffix = i.to_s
|
suffix = i.to_s
|
||||||
max_length = User.username_length.end - suffix.length - 1
|
max_length = User.username_length.end - suffix.length - 1
|
||||||
attempt = "#{name[0..max_length]}#{suffix}"
|
attempt = "#{name[0..max_length]}#{suffix}"
|
||||||
|
|
Loading…
Reference in a new issue