mirror of
https://github.com/yanislav-igonin/micrach
synced 2025-04-20 03:40:33 +03:00
connect captcha controller
This commit is contained in:
parent
7703154fd1
commit
961e51ac9e
@ -3,21 +3,20 @@ package controllers
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/dchest/captcha"
|
"github.com/dchest/captcha"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetCaptcha(c *gin.Context) {
|
func GetCaptcha(c *fiber.Ctx) error {
|
||||||
ID := c.Param("captchaID")
|
ID := c.Params("captchaID")
|
||||||
var content bytes.Buffer
|
var content bytes.Buffer
|
||||||
err := captcha.WriteImage(&content, ID, captcha.StdWidth, captcha.StdHeight)
|
err := captcha.WriteImage(&content, ID, captcha.StdWidth, captcha.StdHeight)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("error:", err)
|
log.Println("error:", err)
|
||||||
c.HTML(http.StatusInternalServerError, "pages/500.html", nil)
|
return c.Status(fiber.StatusInternalServerError).Render("pages/500", nil)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
app.Post("/threadID", func(c *fiber.Ctx) error {
|
||||||
return c.SendString("create post in thread")
|
return c.SendString("create post in thread")
|
||||||
})
|
})
|
||||||
app.Get("/captcha/:captchaID", func(c *fiber.Ctx) error {
|
app.Get("/captcha/:captchaID", controllers.GetCaptcha)
|
||||||
return c.SendString("get captcha by id")
|
|
||||||
})
|
|
||||||
|
|
||||||
log.Println("app - online, port -", strconv.Itoa(config.App.Port))
|
log.Println("app - online, port -", strconv.Itoa(config.App.Port))
|
||||||
log.Println("all systems nominal")
|
log.Println("all systems nominal")
|
||||||
|
Loading…
Reference in New Issue
Block a user