mirror of
https://github.com/yanislav-igonin/micrach
synced 2025-04-18 19:00:33 +03:00
connect captcha controller
This commit is contained in:
parent
7703154fd1
commit
961e51ac9e
@ -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())
|
||||
}
|
||||
|
4
main.go
4
main.go
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user