aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web/auth/linkaccount.go
diff options
context:
space:
mode:
authorJason Song <i@wolfogre.com>2022-11-10 19:43:06 +0800
committerGitHub <noreply@github.com>2022-11-10 19:43:06 +0800
commit1d22911cfe08db93b4be5a99c2a67bcb132c7035 (patch)
tree7211f3caf436efa89193e3bd1c3d20632dc8b1a8 /routers/web/auth/linkaccount.go
parent385462d36c75e809ee082d3432941f938cbdffc9 (diff)
downloadgitea-1d22911cfe08db93b4be5a99c2a67bcb132c7035.tar.gz
gitea-1d22911cfe08db93b4be5a99c2a67bcb132c7035.zip
Extract updateSession function to reduce repetition (#21735)
A simple refactor to reduce duplicate codes. Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: delvh <dev.lh@web.de>
Diffstat (limited to 'routers/web/auth/linkaccount.go')
-rw-r--r--routers/web/auth/linkaccount.go22
1 files changed, 6 insertions, 16 deletions
diff --git a/routers/web/auth/linkaccount.go b/routers/web/auth/linkaccount.go
index 4f3f2062b6..d3211eaa5c 100644
--- a/routers/web/auth/linkaccount.go
+++ b/routers/web/auth/linkaccount.go
@@ -18,7 +18,6 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/mcaptcha"
"code.gitea.io/gitea/modules/recaptcha"
- "code.gitea.io/gitea/modules/session"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/web"
auth_service "code.gitea.io/gitea/services/auth"
@@ -156,25 +155,16 @@ func linkAccount(ctx *context.Context, u *user_model.User, gothUser goth.User, r
return
}
- if _, err := session.RegenerateSession(ctx.Resp, ctx.Req); err != nil {
+ if err := updateSession(ctx, nil, map[string]interface{}{
+ // User needs to use 2FA, save data and redirect to 2FA page.
+ "twofaUid": u.ID,
+ "twofaRemember": remember,
+ "linkAccount": true,
+ }); err != nil {
ctx.ServerError("RegenerateSession", err)
return
}
- // User needs to use 2FA, save data and redirect to 2FA page.
- if err := ctx.Session.Set("twofaUid", u.ID); err != nil {
- log.Error("Error setting twofaUid in session: %v", err)
- }
- if err := ctx.Session.Set("twofaRemember", remember); err != nil {
- log.Error("Error setting twofaRemember in session: %v", err)
- }
- if err := ctx.Session.Set("linkAccount", true); err != nil {
- log.Error("Error setting linkAccount in session: %v", err)
- }
- if err := ctx.Session.Release(); err != nil {
- log.Error("Error storing session: %v", err)
- }
-
// If WebAuthn is enrolled -> Redirect to WebAuthn instead
regs, err := auth.GetWebAuthnCredentialsByUID(u.ID)
if err == nil && len(regs) > 0 {