Skip to content
Snippets Groups Projects
Verified Commit 875d5b75 authored by Ophestra's avatar Ophestra
Browse files

refactor: move captcha route into separate file

parent 48c4e7a4
Branches
Tags
1 merge request!3Upgrade to Fiber v3 and implement hCaptcha protection
Pipeline #952 failed
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)
}
}
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment