✨ Captcha Gateway
This commit is contained in:
25
pkg/internal/web/api/captcha.go
Normal file
25
pkg/internal/web/api/captcha.go
Normal file
@ -0,0 +1,25 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/internal/captcha"
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/internal/web/exts"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func renderCaptcha(c *fiber.Ctx) error {
|
||||
return c.Render("captcha", captcha.GetTemplateData())
|
||||
}
|
||||
|
||||
func validateCaptcha(c *fiber.Ctx) error {
|
||||
var body struct {
|
||||
CaptchaToken string `json:"captcha_tk"`
|
||||
}
|
||||
if err := exts.BindAndValidate(c, &body); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !captcha.Validate(body.CaptchaToken, c.IP()) {
|
||||
return c.SendStatus(fiber.StatusNotAcceptable)
|
||||
}
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
}
|
@ -12,6 +12,8 @@ import (
|
||||
)
|
||||
|
||||
func MapControllers(app *fiber.App) {
|
||||
app.Get("/captcha", renderCaptcha)
|
||||
app.Post("/captcha", validateCaptcha)
|
||||
app.Get("/check-ip", getClientIP)
|
||||
app.Get("/", func(c *fiber.Ctx) error {
|
||||
return c.JSON(fiber.Map{
|
||||
|
Reference in New Issue
Block a user