You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.4 KiB
Go
58 lines
1.4 KiB
Go
package http
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// 滑动验证请求
|
|
type SlideVerifyRequest struct {
|
|
Phone string `json:"phone" binding:"required"`
|
|
}
|
|
|
|
// 滑动验证结果请求
|
|
type SlideVerifyResultRequest struct {
|
|
Token string `json:"token" binding:"required"`
|
|
X int `json:"x" binding:"required"`
|
|
}
|
|
|
|
// HandleSlideVerify 处理滑动验证码生成请求
|
|
func (h *AuthHandler) HandleSlideVerify(c *gin.Context) {
|
|
var req SlideVerifyRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "无效的请求参数"})
|
|
return
|
|
}
|
|
|
|
resp, err := h.captchaService.GenerateSlideVerify(req.Phone)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, resp)
|
|
}
|
|
|
|
// HandleVerifySlide 处理滑动验证结果
|
|
func (h *AuthHandler) HandleVerifySlide(c *gin.Context) {
|
|
var req SlideVerifyResultRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "无效的请求参数"})
|
|
return
|
|
}
|
|
|
|
verified, err := h.captchaService.VerifySlide(req.Token, req.X)
|
|
if err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
if !verified {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "验证失败"})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{"message": "验证成功"})
|
|
}
|