1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Display error if twofaSecret cannot be retrieved (#14372)

This commit is contained in:
Ash McKenzie
2021-01-19 07:38:41 +11:00
committed by GitHub
parent 2686e6bbbe
commit 6ff63c8202
2 changed files with 9 additions and 1 deletions

View File

@@ -189,7 +189,14 @@ func EnrollTwoFactorPost(ctx *context.Context, form auth.TwoFactorAuthForm) {
return
}
secret := ctx.Session.Get("twofaSecret").(string)
secretRaw := ctx.Session.Get("twofaSecret")
if secretRaw == nil {
ctx.Flash.Error(ctx.Tr("settings.twofa_failed_get_secret"))
ctx.Redirect(setting.AppSubURL + "/user/settings/security/two_factor/enroll")
return
}
secret := secretRaw.(string)
if !totp.Validate(form.Passcode, secret) {
if !twofaGenerateSecretAndQr(ctx) {
return