dkforest

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

commit ae231a3caaeb402e14440f6f5cac65b6948d245a
parent 978225796ae20f2f85a4ed4cbd8be885b37aa5a7
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Sun, 18 Dec 2022 01:49:22 -0800

simplify code

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

diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go @@ -800,11 +800,8 @@ func waitPageWrapper(c echo.Context, clb echo.HandlerFunc, cookieName string) er signupToken = payload.Token start = payload.Now if c.Request().Method == http.MethodGet { - count := payload.Count - unix := payload.Unix - // If you reload the page before the wait time is over, we kill the circuit. - if time.Now().Unix() < unix { + if time.Now().Unix() < payload.Unix { // Kill circuit if conn, ok := c.Request().Context().Value("conn").(net.Conn); ok { config.ConnMap.Close(conn) @@ -813,16 +810,13 @@ func waitPageWrapper(c echo.Context, clb echo.HandlerFunc, cookieName string) er } // If the wait time is over, and you reload the protected page more than 4 times, we make you wait 1min - if count >= 4 { + if payload.Count >= 4 { c.SetCookie(hutils.CreateCookie(cookieName, cc.Value, utils.OneMinuteSecs)) return c.String(http.StatusFound, "You tried to reload the page too many times. Now you have to wait one minute.") } - newPayload := WaitPageCookiePayload{ - Count: count + 1, - Now: time.Now().UnixMilli(), - Token: signupToken, - } - c.SetCookie(hutils.CreateEncCookie(cookieName, newPayload, utils.OneMinuteSecs*5)) + payload.Count++ + payload.Now = time.Now().UnixMilli() + c.SetCookie(hutils.CreateEncCookie(cookieName, payload, utils.OneMinuteSecs*5)) } } c.Set("start", start)