fix: check oauthUser.Username length

This commit is contained in:
Seefs committed 2026-02-24 13:26:19 +08:00
1 parent 0427ddda03
commit 262ece0d71
2 files changed
+5

No files matched your search

+3
View File
@@ -240,9 +240,12 @@ func findOrCreateOAuthUser(c *gin.Context, provider oauth.Provider, oauthUser *o
if oauthUser.Username != "" { if oauthUser.Username != "" {
if exists, err := model.CheckUserExistOrDeleted(oauthUser.Username, ""); err == nil && !exists { if exists, err := model.CheckUserExistOrDeleted(oauthUser.Username, ""); err == nil && !exists {
// 防止索引退化
if len(oauthUser.Username) <= model.UserNameMaxLength {
user.Username = oauthUser.Username user.Username = oauthUser.Username
} }
} }
}
if oauthUser.DisplayName != "" { if oauthUser.DisplayName != "" {
user.DisplayName = oauthUser.DisplayName user.DisplayName = oauthUser.DisplayName
+2
View File
@@ -15,6 +15,8 @@ import (
"gorm.io/gorm" "gorm.io/gorm"
) )
const UserNameMaxLength = 20
// User if you add sensitive fields, don't forget to clean them in setupLogin function. // User if you add sensitive fields, don't forget to clean them in setupLogin function.
// Otherwise, the sensitive information will be saved on local storage in plain text! // Otherwise, the sensitive information will be saved on local storage in plain text!
type User struct { type User struct {