forked from Gitlink/gitea-1156
* fixes #1050 where linking an account to a 2fa enabled account failed because we forgot to really link the account when 2fa is completed * handle errors
This commit is contained in:
parent
c0f99e8229
commit
8947b711aa
|
@ -221,6 +221,20 @@ func TwoFactorPost(ctx *context.Context, form auth.TwoFactorAuthForm) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ctx.Session.Get("linkAccount") != nil {
|
||||||
|
gothUser := ctx.Session.Get("linkAccountGothUser")
|
||||||
|
if gothUser == nil {
|
||||||
|
ctx.Handle(500, "UserSignIn", errors.New("not in LinkAccount session"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = models.LinkAccountToUser(u, gothUser.(goth.User))
|
||||||
|
if err != nil {
|
||||||
|
ctx.Handle(500, "UserSignIn", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
handleSignIn(ctx, u, remember)
|
handleSignIn(ctx, u, remember)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -532,8 +546,12 @@ func LinkAccountPostSignIn(ctx *context.Context, signInForm auth.SignInForm) {
|
||||||
_, err = models.GetTwoFactorByUID(u.ID)
|
_, err = models.GetTwoFactorByUID(u.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrTwoFactorNotEnrolled(err) {
|
if models.IsErrTwoFactorNotEnrolled(err) {
|
||||||
models.LinkAccountToUser(u, gothUser.(goth.User))
|
err = models.LinkAccountToUser(u, gothUser.(goth.User))
|
||||||
|
if err != nil {
|
||||||
|
ctx.Handle(500, "UserLinkAccount", err)
|
||||||
|
} else {
|
||||||
handleSignIn(ctx, u, signInForm.Remember)
|
handleSignIn(ctx, u, signInForm.Remember)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ctx.Handle(500, "UserLinkAccount", err)
|
ctx.Handle(500, "UserLinkAccount", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue