dkforest

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

commit 4fa97b90dfb37dc370dfc5c281a2cb546910dcbf
parent 1ff6a0f380620a9ad3ca0024aade11db13aa8eb4
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Wed, 14 Dec 2022 20:23:13 -0500

improve protected home page UX

Diffstat:
Mpkg/web/handlers/handlers.go | 30+++++++++++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go @@ -118,6 +118,7 @@ func HomeHandler(c echo.Context) error { // If we protect the home page, render the special login page with time based captcha for login URL discovery if config.ProtectHome.IsTrue() { + // return waitPageWrapper(c, protectHomeHandler, hutils.WaitCookieName) return protectHomeHandler(c) } @@ -152,6 +153,17 @@ func protectHomeHandler(c echo.Context) error { tempLoginCache.Set("login_link", loginLink, 3*time.Minute) } + waitTime := int64(time.Until(loginLink.ValidUntil).Seconds()) + var frames []string + + // Generate css frames + step := 100.0 / float64(waitTime) + pct := 0.0 + for i := int64(0); i <= waitTime; i++ { + frames = append(frames, fmt.Sprintf(`%.2f%% { content: "%s"; }`, pct, utils.ShortDur(time.Duration(waitTime-i)*time.Second))) + pct += step + } + time.Sleep(utils.RandSec(1, 2)) bufTmp := make([]byte, 0, 1024*4) buf := bytes.NewBuffer(bufTmp) @@ -172,6 +184,20 @@ func protectHomeHandler(c echo.Context) error { #form_login { display: table; margin: auto; } .captcha-img { transition: transform .2s; } .captcha-img:hover { transform: scale(2.5); } + #tutorial_secs:before { + content: "`)) + buf.Write([]byte(utils.ShortDur(time.Duration(waitTime) * time.Second))) + buf.Write([]byte(`"; + animation: `)) + buf.Write([]byte(utils.FormatInt64(waitTime))) + buf.Write([]byte(`s 1s forwards timer_countdown; + } + @keyframes timer_countdown {`)) + for _, frame := range frames { + buf.Write([]byte(frame)) + } + buf.Write([]byte(` + } </style> </head> <body class="bg"> @@ -183,9 +209,7 @@ func protectHomeHandler(c echo.Context) error { To login go to <code>/login/XXXXXX</code><br /> To register go to <code>/signup/XXXXXX</code><br /> (replace X by the numbers in the image)<br /> - Link valid for <strong>`)) - buf.Write([]byte(utils.ShortDur(time.Until(loginLink.ValidUntil)))) - buf.Write([]byte(`</strong> + Link valid for <strong><span id="tutorial_secs"></span></strong> </p> <img src="data:image/png;base64,`)) buf.Write([]byte(loginLink.Img))