43 lines
832 B
Go
43 lines
832 B
Go
package controller
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/QuantumNous/new-api/common"
|
|
"github.com/QuantumNous/new-api/service"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// GetCaptcha 获取验证码图片
|
|
// GET /api/captcha
|
|
func GetCaptcha(c *gin.Context) {
|
|
if !common.CaptchaEnabled {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"success": false,
|
|
"message": "验证码功能未启用",
|
|
})
|
|
return
|
|
}
|
|
|
|
id, question, base64PNG, err := service.GenerateMathCaptcha()
|
|
if err != nil {
|
|
common.SysError("failed to generate captcha: " + err.Error())
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"success": false,
|
|
"message": "验证码生成失败,请重试",
|
|
})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"success": true,
|
|
"message": "",
|
|
"data": gin.H{
|
|
"captcha_id": id,
|
|
"question": question,
|
|
"captcha_image": base64PNG,
|
|
},
|
|
})
|
|
}
|