diff --git a/captcha.go b/captcha.go new file mode 100644 index 0000000000000000000000000000000000000000..edb3cd2ab66efce6e6b260742705ccd4cbf0f833 --- /dev/null +++ b/captcha.go @@ -0,0 +1,34 @@ +package main + +import ( + "log" + + "github.com/gofiber/fiber/v3" +) + +// Route to expose hCaptcha site key +func routeHCaptchaSiteKey(app *fiber.App) { + app.Get("/hcaptcha-site-key", func(c fiber.Ctx) error { + if conf[hCaptchaSiteKey] == "unset" { + return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{ + "message": "hCaptcha site key not configured", + }) + } + return c.JSON(fiber.Map{ + "hcaptcha_site_key": conf[hCaptchaSiteKey], + }) + }) +} + +// Middleware to conditionally apply hCaptcha +func conditionalCaptcha(captcha fiber.Handler) fiber.Handler { + return func(c fiber.Ctx) error { + if conf[hCaptchaSecret] == "unset" { + if verbose { + log.Printf("Captcha bypassed for %q", c.IP()) + } + return c.Next() + } + return captcha(c) + } +} diff --git a/register.go b/register.go index 84a00f9ebee65d42c25c745fec40244ffdf68966..109b9ecddd861258d7e6275a9f38f2d5c849f0fb 100644 --- a/register.go +++ b/register.go @@ -3,8 +3,9 @@ package main import ( "log" "regexp" - "github.com/gofiber/fiber/v3" + "github.com/gofiber/contrib/hcaptcha" + "github.com/gofiber/fiber/v3" "github.com/syndtr/goleveldb/leveldb" ) @@ -14,19 +15,6 @@ type registration struct { Email string `json:"email"` } -// Middleware to conditionally apply hCaptcha -func conditionalCaptcha(captcha fiber.Handler) fiber.Handler { - return func(c fiber.Ctx) error { - if conf[hCaptchaSecret] == "unset" { - if verbose { - log.Printf("Captcha bypassed for %q", c.IP()) - } - return c.Next() - } - return captcha(c) - } -} - // Waitlist registration route func routeRegister(app *fiber.App, db *leveldb.DB) { @@ -86,17 +74,3 @@ func routeRegister(app *fiber.App, db *leveldb.DB) { }) }) } - -// Route to expose hCaptcha site key -func routeHCaptchaSiteKey(app *fiber.App) { - app.Get("/hcaptcha-site-key", func(c fiber.Ctx) error { - if conf[hCaptchaSiteKey] == "unset" { - return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{ - "message": "hCaptcha site key not configured", - }) - } - return c.JSON(fiber.Map{ - "hcaptcha_site_key": conf[hCaptchaSiteKey], - }) - }) -} \ No newline at end of file