commit 73a6c4989e9f1ac4de9be5e08e232fdc5f04b9f4
parent a5b62944ff1ff6e8adea011de13512103646f384
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Wed, 18 Jan 2023 19:50:15 -0800
simplify code search
Diffstat:
2 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go
@@ -1256,14 +1256,15 @@ func LinksDownloadHandler(c echo.Context) error {
// Captcha for bigger files
var data uploadsDownloadData
data.CaptchaID, data.CaptchaImg = captcha.New()
+ const captchaRequiredTmpl = "captcha-required"
if c.Request().Method == http.MethodGet {
- return c.Render(http.StatusOK, "captcha-required", data)
+ return c.Render(http.StatusOK, captchaRequiredTmpl, data)
}
captchaID := c.Request().PostFormValue("captcha_id")
captchaInput := c.Request().PostFormValue("captcha")
if err := hutils.CaptchaVerifyString(c, captchaID, captchaInput); err != nil {
data.ErrCaptcha = err.Error()
- return c.Render(http.StatusOK, "captcha-required", data)
+ return c.Render(http.StatusOK, captchaRequiredTmpl, data)
}
// Keep track of user downloads
@@ -3631,8 +3632,9 @@ func CaptchaRequiredHandler(c echo.Context) error {
data.CaptchaID, data.CaptchaImg = captcha.New()
config.CaptchaRequiredGenerated.Inc()
+ const captchaRequiredTmpl = "captcha-required"
if c.Request().Method == http.MethodGet {
- return c.Render(http.StatusOK, "captcha-required", data)
+ return c.Render(http.StatusOK, captchaRequiredTmpl, data)
}
captchaID := c.Request().PostFormValue("captcha_id")
@@ -3640,7 +3642,7 @@ func CaptchaRequiredHandler(c echo.Context) error {
if err := hutils.CaptchaVerifyString(c, captchaID, captchaInput); err != nil {
data.ErrCaptcha = err.Error()
config.CaptchaRequiredFailed.Inc()
- return c.Render(http.StatusOK, "captcha-required", data)
+ return c.Render(http.StatusOK, captchaRequiredTmpl, data)
}
config.CaptchaRequiredSuccess.Inc()
authUser.CaptchaRequired = false
@@ -3800,14 +3802,15 @@ func UploadsDownloadHandler(c echo.Context) error {
// Captcha for bigger files
var data uploadsDownloadData
data.CaptchaID, data.CaptchaImg = captcha.New()
+ const captchaRequiredTmpl = "captcha-required"
if c.Request().Method == http.MethodGet {
- return c.Render(http.StatusOK, "captcha-required", data)
+ return c.Render(http.StatusOK, captchaRequiredTmpl, data)
}
captchaID := c.Request().PostFormValue("captcha_id")
captchaInput := c.Request().PostFormValue("captcha")
if err := hutils.CaptchaVerifyString(c, captchaID, captchaInput); err != nil {
data.ErrCaptcha = err.Error()
- return c.Render(http.StatusOK, "captcha-required", data)
+ return c.Render(http.StatusOK, captchaRequiredTmpl, data)
}
}
diff --git a/pkg/web/middlewares/middlewares.go b/pkg/web/middlewares/middlewares.go
@@ -57,16 +57,17 @@ func CaptchaMiddleware() echo.MiddlewareFunc {
return func(c echo.Context) error {
var data captchaMiddlewareData
data.CaptchaID, data.CaptchaImg = captcha.New()
+ const captchaRequiredTmpl = "captcha-required"
if c.Request().Method == http.MethodPost {
captchaID := c.Request().PostFormValue("captcha_id")
captchaInput := c.Request().PostFormValue("captcha")
if err := hutils.CaptchaVerifyString(c, captchaID, captchaInput); err != nil {
data.ErrCaptcha = err.Error()
- return c.Render(http.StatusOK, "captcha-required", data)
+ return c.Render(http.StatusOK, captchaRequiredTmpl, data)
}
return next(c)
}
- return c.Render(http.StatusOK, "captcha-required", data)
+ return c.Render(http.StatusOK, captchaRequiredTmpl, data)
}
}
}