Enforce username limitations on registration for #2527
This commit is contained in:
parent
0c03773c4c
commit
6a8473a297
@ -56,23 +56,32 @@ func SetupUsers() {
|
|||||||
_datastore = data.GetDatastore()
|
_datastore = data.GetDatastore()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func generateDisplayName() string {
|
||||||
|
suggestedUsernamesList := data.GetSuggestedUsernamesList()
|
||||||
|
|
||||||
|
if len(suggestedUsernamesList) >= minSuggestedUsernamePoolLength {
|
||||||
|
index := utils.RandomIndex(len(suggestedUsernamesList))
|
||||||
|
return suggestedUsernamesList[index]
|
||||||
|
} else {
|
||||||
|
return utils.GeneratePhrase()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// CreateAnonymousUser will create a new anonymous user with the provided display name.
|
// CreateAnonymousUser will create a new anonymous user with the provided display name.
|
||||||
func CreateAnonymousUser(displayName string) (*User, string, error) {
|
func CreateAnonymousUser(displayName string) (*User, string, error) {
|
||||||
id := shortid.MustGenerate()
|
// Try to assign a name that was requested.
|
||||||
|
if displayName != "" {
|
||||||
if displayName == "" {
|
// If name isn't available then generate a random one.
|
||||||
suggestedUsernamesList := data.GetSuggestedUsernamesList()
|
if available, _ := IsDisplayNameAvailable(displayName); !available {
|
||||||
|
displayName = generateDisplayName()
|
||||||
if len(suggestedUsernamesList) >= minSuggestedUsernamePoolLength {
|
|
||||||
index := utils.RandomIndex(len(suggestedUsernamesList))
|
|
||||||
displayName = suggestedUsernamesList[index]
|
|
||||||
} else {
|
|
||||||
displayName = utils.GeneratePhrase()
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
displayName = generateDisplayName()
|
||||||
}
|
}
|
||||||
|
|
||||||
displayColor := utils.GenerateRandomDisplayColor(config.MaxUserColor)
|
displayColor := utils.GenerateRandomDisplayColor(config.MaxUserColor)
|
||||||
|
|
||||||
|
id := shortid.MustGenerate()
|
||||||
user := &User{
|
user := &User{
|
||||||
ID: id,
|
ID: id,
|
||||||
DisplayName: displayName,
|
DisplayName: displayName,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user