Skip to content

Commit

Permalink
Fix goth user infer bug (go-gitea#15821)
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny authored and AbdulrhmnGhanem committed Aug 10, 2021
1 parent 53eda62 commit 245cfca
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions routers/user/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -983,11 +983,16 @@ func LinkAccountPostRegister(ctx *context.Context) {
ctx.Data["SignInLink"] = setting.AppSubURL + "/user/link_account_signin"
ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/link_account_signup"

gothUser := ctx.Session.Get("linkAccountGothUser")
if gothUser == nil {
gothUserInterface := ctx.Session.Get("linkAccountGothUser")
if gothUserInterface == nil {
ctx.ServerError("UserSignUp", errors.New("not in LinkAccount session"))
return
}
gothUser, ok := gothUserInterface.(goth.User)
if !ok {
ctx.ServerError("UserSignUp", fmt.Errorf("session linkAccountGothUser type is %t but not goth.User", gothUserInterface))
return
}

if ctx.HasError() {
ctx.HTML(http.StatusOK, tplLinkAccount)
Expand Down Expand Up @@ -1049,7 +1054,7 @@ func LinkAccountPostRegister(ctx *context.Context) {
}
}

loginSource, err := models.GetActiveOAuth2LoginSourceByName(gothUser.(goth.User).Provider)
loginSource, err := models.GetActiveOAuth2LoginSourceByName(gothUser.Provider)
if err != nil {
ctx.ServerError("CreateUser", err)
}
Expand All @@ -1061,10 +1066,10 @@ func LinkAccountPostRegister(ctx *context.Context) {
IsActive: !(setting.Service.RegisterEmailConfirm || setting.Service.RegisterManualConfirm),
LoginType: models.LoginOAuth2,
LoginSource: loginSource.ID,
LoginName: gothUser.(goth.User).UserID,
LoginName: gothUser.UserID,
}

if !createAndHandleCreatedUser(ctx, tplLinkAccount, form, u, gothUser.(*goth.User), false) {
if !createAndHandleCreatedUser(ctx, tplLinkAccount, form, u, &gothUser, false) {
// error already handled
return
}
Expand Down

0 comments on commit 245cfca

Please sign in to comment.