commit 511d59e61be09fc23cf73a3a7c88bad0bed2099c
parent f1abb9c5e38959f44cf127f4435a1f9fa903f456
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Tue, 6 Jun 2023 21:22:34 -0700
cleanup
Diffstat:
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/pkg/database/tableUsers.go b/pkg/database/tableUsers.go
@@ -263,6 +263,10 @@ func (u *User) GenerateChatStyle1() string {
return sb.String()
}
+func (u *User) HasTotpEnabled() bool {
+ return string(u.TwoFactorSecret) != ""
+}
+
func (u *User) IsModerator() bool {
return u.IsAdmin || u.Role == "moderator"
}
diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go
@@ -329,7 +329,7 @@ func loginFormHandler(c echo.Context) error {
return c.Render(http.StatusOK, "standalone.login", data)
}
- if user.GpgTwoFactorEnabled || string(user.TwoFactorSecret) != "" {
+ if user.GpgTwoFactorEnabled || user.HasTotpEnabled() {
token := utils.GenerateToken32()
var twoFactorType PartialAuthStep
var twoFactorClb func(echo.Context, bool, string) error
@@ -339,7 +339,7 @@ func loginFormHandler(c echo.Context) error {
} else if user.GpgTwoFactorEnabled {
twoFactorType = PgpStep
twoFactorClb = SessionsGpgTwoFactorHandler
- } else if string(user.TwoFactorSecret) != "" {
+ } else if user.HasTotpEnabled() {
twoFactorType = TwoFactorStep
twoFactorClb = SessionsTwoFactorHandler
}
@@ -487,7 +487,7 @@ func SessionsGpgTwoFactorHandler(c echo.Context, step1 bool, token string) error
pgpTokenCache.Delete(user.ID)
partialAuthCache.Delete(token)
- if string(user.TwoFactorSecret) != "" {
+ if user.HasTotpEnabled() {
token := utils.GenerateToken32()
partialAuthCache.SetD(token, NewPartialAuthItem(user.ID, TwoFactorStep, item.SessionDuration))
return SessionsTwoFactorHandler(c, true, token)
@@ -538,7 +538,7 @@ func SessionsGpgSignTwoFactorHandler(c echo.Context, step1 bool, token string) e
pgpTokenCache.Delete(user.ID)
partialAuthCache.Delete(token)
- if string(user.TwoFactorSecret) != "" {
+ if user.HasTotpEnabled() {
token := utils.GenerateToken32()
partialAuthCache.SetD(token, NewPartialAuthItem(user.ID, TwoFactorStep, item.SessionDuration))
return SessionsTwoFactorHandler(c, true, token)
@@ -3668,7 +3668,7 @@ func TwoFactorAuthenticationVerifyHandler(c echo.Context) error {
}
authUser := c.Get("authUser").(*database.User)
db := c.Get("database").(*database.DkfDB)
- if authUser.TwoFactorSecret != "" {
+ if authUser.HasTotpEnabled() {
return c.Redirect(http.StatusFound, "/settings/account")
}
var data twoFactorAuthenticationVerifyData