summaryrefslogtreecommitdiffstats
path: root/routers/user/setting/security_twofa.go
diff options
context:
space:
mode:
authorkolaente <konrad@kola-entertainments.de>2019-06-12 21:41:28 +0200
committertechknowlogick <techknowlogick@gitea.io>2019-06-12 15:41:28 -0400
commitf9ec2f89f2265bc1371a6c62359de9816534fa6b (patch)
treef48b138a457e5ac6cf843bbb38400926704370f7 /routers/user/setting/security_twofa.go
parent5832f8d90df2d72cb38698c3e9050f2b29717dc7 (diff)
downloadgitea-f9ec2f89f2265bc1371a6c62359de9816534fa6b.tar.gz
gitea-f9ec2f89f2265bc1371a6c62359de9816534fa6b.zip
Add golangci (#6418)
Diffstat (limited to 'routers/user/setting/security_twofa.go')
-rw-r--r--routers/user/setting/security_twofa.go28
1 files changed, 24 insertions, 4 deletions
diff --git a/routers/user/setting/security_twofa.go b/routers/user/setting/security_twofa.go
index fca1151a04..6e3516dbba 100644
--- a/routers/user/setting/security_twofa.go
+++ b/routers/user/setting/security_twofa.go
@@ -73,6 +73,10 @@ func twofaGenerateSecretAndQr(ctx *context.Context) bool {
uri := ctx.Session.Get("twofaUri")
if uri != nil {
otpKey, err = otp.NewKeyFromURL(uri.(string))
+ if err != nil {
+ ctx.ServerError("SettingsTwoFactor: NewKeyFromURL: ", err)
+ return false
+ }
}
// Filter unsafe character ':' in issuer
issuer := strings.Replace(setting.AppName+" ("+setting.Domain+")", ":", "", -1)
@@ -103,8 +107,16 @@ func twofaGenerateSecretAndQr(ctx *context.Context) bool {
}
ctx.Data["QrUri"] = template.URL("data:image/png;base64," + base64.StdEncoding.EncodeToString(imgBytes.Bytes()))
- ctx.Session.Set("twofaSecret", otpKey.Secret())
- ctx.Session.Set("twofaUri", otpKey.String())
+ err = ctx.Session.Set("twofaSecret", otpKey.Secret())
+ if err != nil {
+ ctx.ServerError("SettingsTwoFactor", err)
+ return false
+ }
+ err = ctx.Session.Set("twofaUri", otpKey.String())
+ if err != nil {
+ ctx.ServerError("SettingsTwoFactor", err)
+ return false
+ }
return true
}
@@ -184,8 +196,16 @@ func EnrollTwoFactorPost(ctx *context.Context, form auth.TwoFactorAuthForm) {
return
}
- ctx.Session.Delete("twofaSecret")
- ctx.Session.Delete("twofaUri")
+ err = ctx.Session.Delete("twofaSecret")
+ if err != nil {
+ ctx.ServerError("SettingsTwoFactor", err)
+ return
+ }
+ err = ctx.Session.Delete("twofaUri")
+ if err != nil {
+ ctx.ServerError("SettingsTwoFactor", err)
+ return
+ }
ctx.Flash.Success(ctx.Tr("settings.twofa_enrolled", token))
ctx.Redirect(setting.AppSubURL + "/user/settings/security")
}