Skip to content

Commit 89c0b79

Browse files
authored
Merge pull request #2998 from seefs001/fix/pr-2900
Fix/pr 2900
2 parents 6b19c84 + 262ece0 commit 89c0b79

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

controller/oauth.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,16 @@ func findOrCreateOAuthUser(c *gin.Context, provider oauth.Provider, oauthUser *o
237237

238238
// Set up new user
239239
user.Username = provider.GetProviderPrefix() + strconv.Itoa(model.GetMaxUserId()+1)
240+
241+
if oauthUser.Username != "" {
242+
if exists, err := model.CheckUserExistOrDeleted(oauthUser.Username, ""); err == nil && !exists {
243+
// 防止索引退化
244+
if len(oauthUser.Username) <= model.UserNameMaxLength {
245+
user.Username = oauthUser.Username
246+
}
247+
}
248+
}
249+
240250
if oauthUser.DisplayName != "" {
241251
user.DisplayName = oauthUser.DisplayName
242252
} else if oauthUser.Username != "" {

model/user.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515
"gorm.io/gorm"
1616
)
1717

18+
const UserNameMaxLength = 20
19+
1820
// User if you add sensitive fields, don't forget to clean them in setupLogin function.
1921
// Otherwise, the sensitive information will be saved on local storage in plain text!
2022
type User struct {

0 commit comments

Comments
 (0)