package handlers import ( "net/http" "github.com/gin-gonic/gin" ) // ShowSignup 显示注册页面 func (h *AuthHandler) ShowSignup(c *gin.Context) { c.HTML(http.StatusOK, "signup.html", gin.H{ "title": "注册", }) } // HandleSignup 处理用户注册 func (h *AuthHandler) HandleSignup(c *gin.Context) { username := c.PostForm("username") password := c.PostForm("password") email := c.PostForm("email") if username == "" || password == "" || email == "" { c.HTML(http.StatusBadRequest, "signup.html", gin.H{ "title": "注册", "error": "用户名、密码和邮箱都不能为空", }) return } // 创建新用户 _, err := h.authService.CreateUser(username, password, email) if err != nil { c.HTML(http.StatusBadRequest, "signup.html", gin.H{ "title": "注册", "error": "注册失败:" + err.Error(), }) return } // 注册成功后重定向到登录页 c.Redirect(http.StatusFound, "/login") }