micrach/controllers/captcha_controller.go

23 lines
482 B
Go
Raw Permalink Normal View History

2021-10-03 11:48:59 +03:00
package controllers
import (
"bytes"
"log"
"github.com/dchest/captcha"
"github.com/gofiber/fiber/v2"
2021-10-03 11:48:59 +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
}
c.Context().SetContentType("image/png")
return c.Send(content.Bytes())
2021-10-03 11:48:59 +03:00
}