You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/internal/api/captcha.go

50 lines
1.3 KiB

package api
import (
"github.com/gin-gonic/gin"
pbcaptcha "github.com/openimsdk/protocol/captcha"
"github.com/openimsdk/tools/a2r"
"github.com/openimsdk/tools/apiresp"
"github.com/openimsdk/tools/log"
)
type CaptchaApi struct {
Client pbcaptcha.CaptchaClient
}
func NewCaptchaApi(client pbcaptcha.CaptchaClient) *CaptchaApi {
return &CaptchaApi{Client: client}
}
func (c *CaptchaApi) GenerateCaptcha(ctx *gin.Context) {
req, err := a2r.ParseRequestNotCheck[pbcaptcha.GenerateCaptchaReq](ctx)
if err != nil {
log.ZError(ctx, "captcha generate request parse failed", err)
apiresp.GinError(ctx, err)
return
}
resp, err := c.Client.GenerateCaptcha(ctx, req)
if err != nil {
log.ZError(ctx, "captcha generate rpc failed", err)
apiresp.GinError(ctx, err)
return
}
apiresp.GinSuccess(ctx, resp)
}
func (c *CaptchaApi) VerifyCaptcha(ctx *gin.Context) {
req, err := a2r.ParseRequestNotCheck[pbcaptcha.VerifyCaptchaReq](ctx)
if err != nil {
log.ZError(ctx, "captcha verify request parse failed", err)
apiresp.GinError(ctx, err)
return
}
resp, err := c.Client.VerifyCaptcha(ctx, req)
if err != nil {
log.ZError(ctx, "captcha verify rpc failed", err, "captchaID", req.GetCaptchaID(), "clickCount", len(req.GetClickPoints()))
apiresp.GinError(ctx, err)
return
}
apiresp.GinSuccess(ctx, resp)
}