signup_controller.go 837 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package auth
  2. import (
  3. "fmt"
  4. "github.com/gin-gonic/gin"
  5. v1 "github.com/runningwater/gohub/app/http/controllers/api/v1"
  6. "github.com/runningwater/gohub/app/models/user"
  7. )
  8. // SignupController 处理用户注册相关的逻辑
  9. type SignupController struct {
  10. v1.BaseApiController
  11. }
  12. func (controller *SignupController) IsPhoneExist(c *gin.Context) {
  13. // 请求对象
  14. type SignupPhoneExistRequest struct {
  15. Phone string `json:"phone,omitempty" binding:"required,min=11"`
  16. }
  17. req := SignupPhoneExistRequest{}
  18. // 解析 JSON 请求
  19. if err := c.ShouldBindJSON(&req); err != nil {
  20. c.AbortWithStatusJSON(422, gin.H{
  21. "error": "请求参数错误"+ err.Error(),
  22. })
  23. // 打印错误信息
  24. fmt.Println(err.Error())
  25. return
  26. }
  27. // 检查数据库并返回响应
  28. c.JSON(200, gin.H{
  29. "exist": user.IsPhoneExist(req.Phone),
  30. })
  31. }