Skip to content

Commit

Permalink
Don't show Link to TOTP if not set up (go-gitea#27585) (go-gitea#27588)
Browse files Browse the repository at this point in the history
Backport go-gitea#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>
  • Loading branch information
GiteaBot and JakobDev authored Oct 11, 2023
1 parent 844ab9a commit 63a321b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 8 additions & 0 deletions routers/web/auth/webauthn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
8 changes: 5 additions & 3 deletions templates/user/auth/webauthn.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
<div class="is-loading" style="width: 40px; height: 40px"></div>
{{ctx.Locale.Tr "webauthn_press_button"}}
</div>
<div class="ui attached segment">
<a href="{{AppSubUrl}}/user/two_factor">{{ctx.Locale.Tr "webauthn_use_twofa"}}</a>
</div>
{{if .HasTwoFactor}}
<div class="ui attached segment">
<a href="{{AppSubUrl}}/user/two_factor">{{ctx.Locale.Tr "webauthn_use_twofa"}}</a>
</div>
{{end}}
</div>
</div>
</div>
Expand Down

0 comments on commit 63a321b

Please sign in to comment.