From 63a321b83a6f3ed35f33316d61628d49e8612f66 Mon Sep 17 00:00:00 2001 From: Giteabot Date: Thu, 12 Oct 2023 04:59:21 +0800 Subject: [PATCH] Don't show Link to TOTP if not set up (#27585) (#27588) Backport #27585 by @JakobDev Fixes https://codeberg.org/forgejo/forgejo/issues/1592 When login in with WebAuth, the page has a link to use TOTP instead. This link is always displayed, no matter if the User has set up TOTP or not, which do of cause not work for those who have not. Co-authored-by: JakobDev --- routers/web/auth/webauthn.go | 8 ++++++++ templates/user/auth/webauthn.tmpl | 8 +++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/routers/web/auth/webauthn.go b/routers/web/auth/webauthn.go index 88413caea6..9b516ce396 100644 --- a/routers/web/auth/webauthn.go +++ b/routers/web/auth/webauthn.go @@ -37,6 +37,14 @@ func WebAuthn(ctx *context.Context) { return } + hasTwoFactor, err := auth.HasTwoFactorByUID(ctx, ctx.Session.Get("twofaUid").(int64)) + if err != nil { + ctx.ServerError("HasTwoFactorByUID", err) + return + } + + ctx.Data["HasTwoFactor"] = hasTwoFactor + ctx.HTML(http.StatusOK, tplWebAuthn) } diff --git a/templates/user/auth/webauthn.tmpl b/templates/user/auth/webauthn.tmpl index f738937025..722da02f54 100644 --- a/templates/user/auth/webauthn.tmpl +++ b/templates/user/auth/webauthn.tmpl @@ -14,9 +14,11 @@
{{ctx.Locale.Tr "webauthn_press_button"}} - + {{if .HasTwoFactor}} + + {{end}}