commit 4a2f16d905b0336887d1ff784a4e9fd55e7267e2
parent 100394e8e6104deba5d90e50aca89bd7e04ca507
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Sat, 3 Dec 2022 18:03:53 -0500
simplify code
Diffstat:
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go
@@ -927,12 +927,7 @@ func signupHandler(c echo.Context) error {
config.SignupPageLoad.Inc()
data.CaptchaSec = 120
- step := 100.0 / float64(data.CaptchaSec)
- pct := 0.0
- for i := int64(0); i <= data.CaptchaSec; i++ {
- data.Frames = append(data.Frames, fmt.Sprintf(`%.2f%% { content: "%d"; }`, pct, data.CaptchaSec-i))
- pct += step
- }
+ data.Frames = generateCaptchaCssFrames(data.CaptchaSec)
hbCookie, hbCookieErr := c.Cookie(hutils.HBCookieName)
hasHBCookie := hbCookieErr == nil && hbCookie.Value != ""
@@ -1042,6 +1037,16 @@ func validateCaptcha(c echo.Context) error {
var partialRecoveryCache = cache1.New[database.UserID](10*time.Minute, time.Hour)
var partialRecovery2Cache = cache1.New[database.UserID](10*time.Minute, time.Hour)
+func generateCaptchaCssFrames(captchaSec int64) (frames []string) {
+ step := 100.0 / float64(captchaSec)
+ pct := 0.0
+ for i := int64(0); i <= captchaSec; i++ {
+ frames = append(frames, fmt.Sprintf(`%.2f%% { content: "%d"; }`, pct, captchaSec-i))
+ pct += step
+ }
+ return
+}
+
// ForgotPasswordHandler ...
func ForgotPasswordHandler(c echo.Context) error {
// If already logged in, redirect.
@@ -1054,12 +1059,7 @@ func ForgotPasswordHandler(c echo.Context) error {
data.Step = 1
data.CaptchaSec = 120
- step := 100.0 / float64(data.CaptchaSec)
- pct := 0.0
- for i := int64(0); i <= data.CaptchaSec; i++ {
- data.Frames = append(data.Frames, fmt.Sprintf(`%.2f%% { content: "%d"; }`, pct, data.CaptchaSec-i))
- pct += step
- }
+ data.Frames = generateCaptchaCssFrames(data.CaptchaSec)
data.CaptchaID, data.CaptchaImg = captcha.New()