1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-11-24 08:57:03 -05:00

Fix empty field login_name in API response JSON when creating user (#30511) (#30516)

Backport #30511 by @yp05327

Fix #30508

ps: if `sourceID` is not set, `LoginName` will be ignored

Co-authored-by: yp05327 <576951401@qq.com>
(cherry picked from commit f9a025f6a358aa6e34408743a59f5081f397d47c)
This commit is contained in:
Giteabot 2024-04-17 01:34:48 +08:00 committed by Earl Warren
parent c044cb2de3
commit 9de4bebbf7
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00

View file

@ -30,7 +30,7 @@ import (
user_service "code.gitea.io/gitea/services/user" user_service "code.gitea.io/gitea/services/user"
) )
func parseAuthSource(ctx *context.APIContext, u *user_model.User, sourceID int64, loginName string) { func parseAuthSource(ctx *context.APIContext, u *user_model.User, sourceID int64) {
if sourceID == 0 { if sourceID == 0 {
return return
} }
@ -47,7 +47,6 @@ func parseAuthSource(ctx *context.APIContext, u *user_model.User, sourceID int64
u.LoginType = source.Type u.LoginType = source.Type
u.LoginSource = source.ID u.LoginSource = source.ID
u.LoginName = loginName
} }
// CreateUser create a user // CreateUser create a user
@ -83,12 +82,13 @@ func CreateUser(ctx *context.APIContext) {
Passwd: form.Password, Passwd: form.Password,
MustChangePassword: true, MustChangePassword: true,
LoginType: auth.Plain, LoginType: auth.Plain,
LoginName: form.LoginName,
} }
if form.MustChangePassword != nil { if form.MustChangePassword != nil {
u.MustChangePassword = *form.MustChangePassword u.MustChangePassword = *form.MustChangePassword
} }
parseAuthSource(ctx, u, form.SourceID, form.LoginName) parseAuthSource(ctx, u, form.SourceID)
if ctx.Written() { if ctx.Written() {
return return
} }