|
|
@@ -0,0 +1,38 @@
|
|
|
+package auth
|
|
|
+
|
|
|
+import (
|
|
|
+ "fmt"
|
|
|
+
|
|
|
+ "github.com/gin-gonic/gin"
|
|
|
+ v1 "github.com/runningwater/gohub/app/http/controllers/api/v1"
|
|
|
+ "github.com/runningwater/gohub/app/models/user"
|
|
|
+)
|
|
|
+
|
|
|
+// SignupController 处理用户注册相关的逻辑
|
|
|
+type SignupController struct {
|
|
|
+ v1.BaseApiController
|
|
|
+}
|
|
|
+
|
|
|
+func (controller *SignupController) IsPhoneExist(c *gin.Context) {
|
|
|
+
|
|
|
+ // 请求对象
|
|
|
+ type SignupPhoneExistRequest struct {
|
|
|
+ Phone string `json:"phone,omitempty" binding:"required,min=11"`
|
|
|
+ }
|
|
|
+ req := SignupPhoneExistRequest{}
|
|
|
+
|
|
|
+ // 解析 JSON 请求
|
|
|
+ if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
+ c.AbortWithStatusJSON(422, gin.H{
|
|
|
+ "error": "请求参数错误"+ err.Error(),
|
|
|
+ })
|
|
|
+ // 打印错误信息
|
|
|
+ fmt.Println(err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查数据库并返回响应
|
|
|
+ c.JSON(200, gin.H{
|
|
|
+ "exist": user.IsPhoneExist(req.Phone),
|
|
|
+ })
|
|
|
+}
|