connect captcha controller

This commit is contained in:
Yanislav Igonin 2022-04-07 11:27:49 +03:00
parent 7703154fd1
commit 961e51ac9e
2 changed files with 7 additions and 10 deletions

View File

@ -3,21 +3,20 @@ package controllers
import (
"bytes"
"log"
"net/http"
"github.com/dchest/captcha"
"github.com/gin-gonic/gin"
"github.com/gofiber/fiber/v2"
)
func GetCaptcha(c *gin.Context) {
ID := c.Param("captchaID")
func GetCaptcha(c *fiber.Ctx) error {
ID := c.Params("captchaID")
var content bytes.Buffer
err := captcha.WriteImage(&content, ID, captcha.StdWidth, captcha.StdHeight)
if err != nil {
log.Println("error:", err)
c.HTML(http.StatusInternalServerError, "pages/500.html", nil)
return
return c.Status(fiber.StatusInternalServerError).Render("pages/500", nil)
}
c.Data(200, "image/png", content.Bytes())
c.Context().SetContentType("image/png")
return c.Send(content.Bytes())
}

View File

@ -73,9 +73,7 @@ func main() {
app.Post("/threadID", func(c *fiber.Ctx) error {
return c.SendString("create post in thread")
})
app.Get("/captcha/:captchaID", func(c *fiber.Ctx) error {
return c.SendString("get captcha by id")
})
app.Get("/captcha/:captchaID", controllers.GetCaptcha)
log.Println("app - online, port -", strconv.Itoa(config.App.Port))
log.Println("all systems nominal")