Skip to content

Commit 63a321b

Browse files
GiteaBotJakobDev
andauthored
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 <jakobdev@gmx.de>
1 parent 844ab9a commit 63a321b

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

routers/web/auth/webauthn.go

+8
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ func WebAuthn(ctx *context.Context) {
3737
return
3838
}
3939

40+
hasTwoFactor, err := auth.HasTwoFactorByUID(ctx, ctx.Session.Get("twofaUid").(int64))
41+
if err != nil {
42+
ctx.ServerError("HasTwoFactorByUID", err)
43+
return
44+
}
45+
46+
ctx.Data["HasTwoFactor"] = hasTwoFactor
47+
4048
ctx.HTML(http.StatusOK, tplWebAuthn)
4149
}
4250

templates/user/auth/webauthn.tmpl

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
<div class="is-loading" style="width: 40px; height: 40px"></div>
1515
{{ctx.Locale.Tr "webauthn_press_button"}}
1616
</div>
17-
<div class="ui attached segment">
18-
<a href="{{AppSubUrl}}/user/two_factor">{{ctx.Locale.Tr "webauthn_use_twofa"}}</a>
19-
</div>
17+
{{if .HasTwoFactor}}
18+
<div class="ui attached segment">
19+
<a href="{{AppSubUrl}}/user/two_factor">{{ctx.Locale.Tr "webauthn_use_twofa"}}</a>
20+
</div>
21+
{{end}}
2022
</div>
2123
</div>
2224
</div>

0 commit comments

Comments
 (0)