summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-05-10 23:31:32 +0800
committerGitHub <noreply@github.com>2021-05-10 16:31:32 +0100
commit3656a2a67296a2f9e8212d5b1374a0a22c6b9653 (patch)
treed6cb7f8d5ab6d18bce91783eb9bcd9fce4b32180
parente5723d6556d632df08132472066f1bb167753299 (diff)
downloadgitea-3656a2a67296a2f9e8212d5b1374a0a22c6b9653.tar.gz
gitea-3656a2a67296a2f9e8212d5b1374a0a22c6b9653.zip
Fix goth user infer bug (#15821)
-rw-r--r--routers/user/auth.go15
1 files changed, 10 insertions, 5 deletions
diff --git a/routers/user/auth.go b/routers/user/auth.go
index cfe116c902..5f8b1a6b99 100644
--- a/routers/user/auth.go
+++ b/routers/user/auth.go
@@ -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)
@@ -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)
}
@@ -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
}