micrach/controllers/captcha_controller.go

24 lines
453 B
Go
Raw Normal View History

2021-10-03 11:48:59 +03:00
package controllers
import (
"bytes"
"log"
"net/http"
"github.com/dchest/captcha"
"github.com/gin-gonic/gin"
)
func GetCaptcha(c *gin.Context) {
ID := c.Param("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)
2021-10-03 11:48:59 +03:00
return
}
c.Data(200, "image/png", content.Bytes())
}