micrach/controllers/captcha_controller.go

23 lines
484 B
Go
Raw Permalink Normal View History

2021-10-03 11:48:59 +03:00
package controllers
import (
"bytes"
"log"
"github.com/dchest/captcha"
2026-07-16 15:25:23 +03:00
"github.com/gofiber/fiber/v3"
2021-10-03 11:48:59 +03:00
)
2026-07-16 15:25:23 +03:00
func GetCaptcha(c fiber.Ctx) error {
ID := c.Params("captchaID")
2021-10-03 11:48:59 +03:00
var content bytes.Buffer
err := captcha.WriteImage(&content, ID, captcha.StdWidth, captcha.StdHeight)
if err != nil {
log.Println("error:", err)
return c.Status(fiber.StatusInternalServerError).Render("pages/500", nil)
2021-10-03 11:48:59 +03:00
}
2026-07-16 15:25:23 +03:00
c.RequestCtx().SetContentType("image/png")
return c.Send(content.Bytes())
2021-10-03 11:48:59 +03:00
}