diff options
author | Kyle D <kdumontnu@gmail.com> | 2024-01-03 16:48:20 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-03 18:48:20 -0600 |
commit | 54acf7b0d4b57907a6d8a2ac470744f185adf0b5 (patch) | |
tree | a9c6a5df44c445b5301ad8f7e3e3218f68fde5f7 /routers/web | |
parent | 657b23d6359bbbb25b3dcfee233cae0735997188 (diff) | |
download | gitea-54acf7b0d4b57907a6d8a2ac470744f185adf0b5.tar.gz gitea-54acf7b0d4b57907a6d8a2ac470744f185adf0b5.zip |
Normalize oauth email username (#28561)
Diffstat (limited to 'routers/web')
-rw-r--r-- | routers/web/auth/auth.go | 8 | ||||
-rw-r--r-- | routers/web/auth/linkaccount.go | 6 | ||||
-rw-r--r-- | routers/web/auth/oauth.go | 7 |
3 files changed, 15 insertions, 6 deletions
diff --git a/routers/web/auth/auth.go b/routers/web/auth/auth.go index 21a72a9521..474bae98e4 100644 --- a/routers/web/auth/auth.go +++ b/routers/web/auth/auth.go @@ -368,14 +368,14 @@ func handleSignInFull(ctx *context.Context, u *user_model.User, remember, obeyRe return setting.AppSubURL + "/" } -func getUserName(gothUser *goth.User) string { +func getUserName(gothUser *goth.User) (string, error) { switch setting.OAuth2Client.Username { case setting.OAuth2UsernameEmail: - return strings.Split(gothUser.Email, "@")[0] + return user_model.NormalizeUserName(strings.Split(gothUser.Email, "@")[0]) case setting.OAuth2UsernameNickname: - return gothUser.NickName + return user_model.NormalizeUserName(gothUser.NickName) default: // OAuth2UsernameUserid - return gothUser.UserID + return gothUser.UserID, nil } } diff --git a/routers/web/auth/linkaccount.go b/routers/web/auth/linkaccount.go index f41590dc13..1d94e52fe3 100644 --- a/routers/web/auth/linkaccount.go +++ b/routers/web/auth/linkaccount.go @@ -55,7 +55,11 @@ func LinkAccount(ctx *context.Context) { } gu, _ := gothUser.(goth.User) - uname := getUserName(&gu) + uname, err := getUserName(&gu) + if err != nil { + ctx.ServerError("UserSignIn", err) + return + } email := gu.Email ctx.Data["user_name"] = uname ctx.Data["email"] = email diff --git a/routers/web/auth/oauth.go b/routers/web/auth/oauth.go index 21d82cea45..00305a36ee 100644 --- a/routers/web/auth/oauth.go +++ b/routers/web/auth/oauth.go @@ -970,8 +970,13 @@ func SignInOAuthCallback(ctx *context.Context) { ctx.ServerError("CreateUser", err) return } + uname, err := getUserName(&gothUser) + if err != nil { + ctx.ServerError("UserSignIn", err) + return + } u = &user_model.User{ - Name: getUserName(&gothUser), + Name: uname, FullName: gothUser.Name, Email: gothUser.Email, LoginType: auth.OAuth2, |