dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit c56a8bf9efa353ba0bb73ad4a1cd8244ee6f33bd
parent cec06e3f2d0ec74e512fb412eb017bef46874a34
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Wed, 14 Dec 2022 21:07:34 -0500

cleanup

Diffstat:
Mpkg/web/handlers/handlers.go | 14+++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go @@ -234,6 +234,10 @@ type PartialAuthItem struct { Step PartialAuthStep // Inform which type of 2fa the user is supposed to complete } +func NewPartialAuthItem(userID database.UserID, step PartialAuthStep) PartialAuthItem { + return PartialAuthItem{UserID: userID, Step: step} +} + type PartialAuthStep string const ( @@ -322,15 +326,15 @@ func loginHandler(c echo.Context) error { if user.GpgTwoFactorEnabled { token := utils.GenerateToken32() if user.GpgTwoFactorMode { - partialAuthCache.Set(token, PartialAuthItem{user.ID, PgpSignStep}, cache.DefaultExpiration) + partialAuthCache.Set(token, NewPartialAuthItem(user.ID, PgpSignStep), cache.DefaultExpiration) return SessionsGpgSignTwoFactorHandler(c, true, token) } - partialAuthCache.Set(token, PartialAuthItem{user.ID, PgpStep}, cache.DefaultExpiration) + partialAuthCache.Set(token, NewPartialAuthItem(user.ID, PgpStep), cache.DefaultExpiration) return SessionsGpgTwoFactorHandler(c, true, token) } else if string(user.TwoFactorSecret) != "" { token := utils.GenerateToken32() - partialAuthCache.Set(token, PartialAuthItem{user.ID, TwoFactorStep}, cache.DefaultExpiration) + partialAuthCache.Set(token, NewPartialAuthItem(user.ID, TwoFactorStep), cache.DefaultExpiration) return SessionsTwoFactorHandler(c, true, token) } @@ -464,7 +468,7 @@ func SessionsGpgTwoFactorHandler(c echo.Context, step1 bool, token string) error if string(user.TwoFactorSecret) != "" { token := utils.GenerateToken32() - partialAuthCache.Set(token, PartialAuthItem{user.ID, TwoFactorStep}, cache.DefaultExpiration) + partialAuthCache.Set(token, NewPartialAuthItem(user.ID, TwoFactorStep), cache.DefaultExpiration) return SessionsTwoFactorHandler(c, true, token) } @@ -508,7 +512,7 @@ func SessionsGpgSignTwoFactorHandler(c echo.Context, step1 bool, token string) e if string(user.TwoFactorSecret) != "" { token := utils.GenerateToken32() - partialAuthCache.Set(token, PartialAuthItem{user.ID, TwoFactorStep}, cache.DefaultExpiration) + partialAuthCache.Set(token, NewPartialAuthItem(user.ID, TwoFactorStep), cache.DefaultExpiration) return SessionsTwoFactorHandler(c, true, token) }