dkforest

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

commit 05ff2ee61274739ae745ad598458d532d04b25c6
parent e43dbac6ca1e71b86f3a8e550a7fd40b4d531ea6
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Sat,  3 Dec 2022 23:51:45 -0500

simplify code

Diffstat:
Mpkg/web/handlers/handlers.go | 34+++++++++++++++++-----------------
1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go @@ -90,7 +90,7 @@ func firstUseHandler(c echo.Context) error { logrus.Error("Failed to save session : ", err) } - c.SetCookie(createSessionCookie(session.Token, utils.OneMonthSecs)) + c.SetCookie(createSessionCookie(session.Token)) return c.Redirect(http.StatusFound, "/") } @@ -278,7 +278,7 @@ func loginHandler(c echo.Context) error { if user.GpgTwoFactorEnabled { token := utils.GenerateToken32() partialAuthCache.Set(token, user.ID, cache1.DefaultExpiration) - c.SetCookie(createPartialSessionCookie(token, 10*utils.OneMinuteSecs)) + c.SetCookie(createPartialSessionCookie(token)) redirectURL := "/sessions/gpg-two-factor" if user.GpgTwoFactorMode { redirectURL = "/sessions/gpg-sign-two-factor" @@ -291,7 +291,7 @@ func loginHandler(c echo.Context) error { } else if string(user.TwoFactorSecret) != "" { token := utils.GenerateToken32() partialAuthCache.Set(token, user.ID, cache1.DefaultExpiration) - c.SetCookie(createPartialSessionCookie(token, 10*utils.OneMinuteSecs)) + c.SetCookie(createPartialSessionCookie(token)) redirectURL := "/sessions/two-factor" if redir != "" { redirectURL += "?redirect=" + redir @@ -351,7 +351,7 @@ func completeLogin(c echo.Context, user database.User, ip string) error { } database.CreateSecurityLog(user.ID, database.LoginSecurityLog) - c.SetCookie(createSessionCookie(session.Token, utils.OneMonthSecs)) + c.SetCookie(createSessionCookie(session.Token)) redirectURL := "/" redir := c.QueryParam("redirect") @@ -419,7 +419,7 @@ func SessionsGpgTwoFactorHandler(c echo.Context) error { if string(user.TwoFactorSecret) != "" { token := utils.GenerateToken32() partialAuthCache.Set(token, user.ID, cache1.DefaultExpiration) - c.SetCookie(createPartialSessionCookie(token, 10*utils.OneMinuteSecs)) + c.SetCookie(createPartialSessionCookie(token)) redirectURL := "/sessions/two-factor" redir := c.QueryParam("redirect") if redir != "" { @@ -473,7 +473,7 @@ func SessionsGpgSignTwoFactorHandler(c echo.Context) error { if string(user.TwoFactorSecret) != "" { token := utils.GenerateToken32() partialAuthCache.Set(token, user.ID, cache1.DefaultExpiration) - c.SetCookie(createPartialSessionCookie(token, 10*utils.OneMinuteSecs)) + c.SetCookie(createPartialSessionCookie(token)) redirectURL := "/sessions/two-factor" redir := c.QueryParam("redirect") if redir != "" { @@ -574,20 +574,20 @@ func LogoutHandler(ctx echo.Context) error { return ctx.Redirect(http.StatusFound, "/") } -func createPartialRecoveryCookie(value string, maxAge int64) *http.Cookie { - return hutils.CreateCookie("partial-recovery-token", value, maxAge) +func createPartialRecoveryCookie(value string) *http.Cookie { + return hutils.CreateCookie("partial-recovery-token", value, 10*utils.OneMinuteSecs) } -func createPartialRecovery2Cookie(value string, maxAge int64) *http.Cookie { - return hutils.CreateCookie("partial-recovery2-token", value, maxAge) +func createPartialRecovery2Cookie(value string) *http.Cookie { + return hutils.CreateCookie("partial-recovery2-token", value, 10*utils.OneMinuteSecs) } -func createPartialSessionCookie(value string, maxAge int64) *http.Cookie { - return hutils.CreateCookie("partial-auth-token", value, maxAge) +func createPartialSessionCookie(value string) *http.Cookie { + return hutils.CreateCookie("partial-auth-token", value, 10*utils.OneMinuteSecs) } -func createSessionCookie(value string, maxAge int64) *http.Cookie { - return hutils.CreateCookie("auth-token", value, maxAge) +func createSessionCookie(value string) *http.Cookie { + return hutils.CreateCookie("auth-token", value, utils.OneMonthSecs) } func createSignupCookie(value string, maxAge int64) *http.Cookie { @@ -1020,7 +1020,7 @@ func ForgotPasswordHandler(c echo.Context) error { token := utils.GenerateToken32() partialRecoveryCache.Set(token, user.ID, cache1.DefaultExpiration) - c.SetCookie(createPartialRecoveryCookie(token, 10*utils.OneMinuteSecs)) + c.SetCookie(createPartialRecoveryCookie(token)) data.Step = 2 return c.Render(http.StatusOK, "forgot-password", data) @@ -1068,7 +1068,7 @@ func ForgotPasswordHandler(c echo.Context) error { token2 := utils.GenerateToken32() partialRecovery2Cache.Set(token2, userID, cache1.DefaultExpiration) - c.SetCookie(createPartialRecovery2Cookie(token2, 10*utils.OneMinuteSecs)) + c.SetCookie(createPartialRecovery2Cookie(token2)) data.Step = 3 return c.Render(http.StatusOK, "forgot-password", data) @@ -2344,7 +2344,7 @@ func chatHandler(c echo.Context, redRoom bool) error { if err != nil { logrus.Error("Failed to create session : ", err) } - c.SetCookie(createSessionCookie(session.Token, utils.OneMonthSecs)) + c.SetCookie(createSessionCookie(session.Token)) } hutils.CreateRoomCookie(c, room.ID, hashedPassword, key)