2021-10-03 11:48:59 +03:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/dchest/captcha"
|
2022-04-09 15:16:09 +03:00
|
|
|
"github.com/gofiber/fiber/v2"
|
2021-10-03 11:48:59 +03:00
|
|
|
)
|
|
|
|
|
2022-04-09 15:16:09 +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)
|
2022-04-09 15:16:09 +03:00
|
|
|
return c.Status(fiber.StatusInternalServerError).Render("pages/500", nil)
|
2021-10-03 11:48:59 +03:00
|
|
|
}
|
|
|
|
|
2022-04-09 15:16:09 +03:00
|
|
|
c.Context().SetContentType("image/png")
|
|
|
|
return c.Send(content.Bytes())
|
2021-10-03 11:48:59 +03:00
|
|
|
}
|