Skip to content

Take control over your live stream video by running it yourself. Streaming + chat out of the box.

Enforce username limitations on registration for #2527

Gabe Kangasb069b8f49165
diff --git a/core/user/user.go b/core/user/user.go
index 8ee99482bc..b63c250736 100644
--- a/core/user/user.go
+++ b/core/user/user.go
@@ -56,23 +56,32 @@ func SetupUsers() {
_datastore = data.GetDatastore()
}
-// CreateAnonymousUser will create a new anonymous user with the provided display name.
-func CreateAnonymousUser(displayName string) (*User, string, error) {
- id := shortid.MustGenerate()
+func generateDisplayName() string {
+ suggestedUsernamesList := data.GetSuggestedUsernamesList()
- if displayName == "" {
- suggestedUsernamesList := data.GetSuggestedUsernamesList()
+ if len(suggestedUsernamesList) >= minSuggestedUsernamePoolLength {
+ index := utils.RandomIndex(len(suggestedUsernamesList))
+ return suggestedUsernamesList[index]
+ } else {
+ return utils.GeneratePhrase()
+ }
+}
- if len(suggestedUsernamesList) >= minSuggestedUsernamePoolLength {
- index := utils.RandomIndex(len(suggestedUsernamesList))
- displayName = suggestedUsernamesList[index]
- } else {
- displayName = utils.GeneratePhrase()
+// CreateAnonymousUser will create a new anonymous user with the provided display name.
+func CreateAnonymousUser(displayName string) (*User, string, error) {
+ // Try to assign a name that was requested.
+ if displayName != "" {
+ // If name isn't available then generate a random one.
+ if available, _ := IsDisplayNameAvailable(displayName); !available {
+ displayName = generateDisplayName()
}
+ } else {
+ displayName = generateDisplayName()
}
displayColor := utils.GenerateRandomDisplayColor(config.MaxUserColor)
+ id := shortid.MustGenerate()
user := &User{
ID: id,
DisplayName: displayName,