mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-03-30 02:42:29 +00:00
@@ -237,6 +237,16 @@ func findOrCreateOAuthUser(c *gin.Context, provider oauth.Provider, oauthUser *o
|
|||||||
|
|
||||||
// Set up new user
|
// Set up new user
|
||||||
user.Username = provider.GetProviderPrefix() + strconv.Itoa(model.GetMaxUserId()+1)
|
user.Username = provider.GetProviderPrefix() + strconv.Itoa(model.GetMaxUserId()+1)
|
||||||
|
|
||||||
|
if oauthUser.Username != "" {
|
||||||
|
if exists, err := model.CheckUserExistOrDeleted(oauthUser.Username, ""); err == nil && !exists {
|
||||||
|
// 防止索引退化
|
||||||
|
if len(oauthUser.Username) <= model.UserNameMaxLength {
|
||||||
|
user.Username = oauthUser.Username
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if oauthUser.DisplayName != "" {
|
if oauthUser.DisplayName != "" {
|
||||||
user.DisplayName = oauthUser.DisplayName
|
user.DisplayName = oauthUser.DisplayName
|
||||||
} else if oauthUser.Username != "" {
|
} else if oauthUser.Username != "" {
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user