更新 Go 版本至 1.23.0,添加管理员功能,包括管理员登录、用户和客户端管理,新增相应的模板和中间件,优化数据库模型以支持管理员管理。

This commit is contained in:
2025-04-17 01:47:10 +08:00
parent a3f3cc17cf
commit 83c82f7135
18 changed files with 686 additions and 21 deletions

42
handlers/auth_handler.go Normal file
View File

@@ -0,0 +1,42 @@
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")
}