From b1e31d86ed912a8e68f9bbf53f0b0cc058d9687c Mon Sep 17 00:00:00 2001 From: jdysya <1912377458@qq.com> Date: Sat, 15 Feb 2025 13:40:04 +0800 Subject: [PATCH] =?UTF-8?q?feat(gateway):=20=E5=AE=9E=E7=8E=B0=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E9=80=80=E5=87=BA=E5=8A=9F=E8=83=BD=E5=B9=B6=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E7=99=BB=E5=BD=95=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加用户退出路由 (/logout),清除会话信息并重定向到登录页 - 重新设计登录页面,增加样式和布局,提升用户体验 - 更新登录表单,添加占位符和错误消息显示 - 修改服务器端口为 7070 --- gateway/main.go | 14 +++- gateway/templates/login.html | 136 +++++++++++++++++++++++++++++++---- 2 files changed, 136 insertions(+), 14 deletions(-) diff --git a/gateway/main.go b/gateway/main.go index e9cb80a..7a0d5b2 100644 --- a/gateway/main.go +++ b/gateway/main.go @@ -88,8 +88,20 @@ func main() { http.ServeFile(c.Writer, c.Request, fmt.Sprintf("./static/guide/%s.html", page)) }) + // 在权限校验中间件后添加退出路由 + r.GET("/logout", func(c *gin.Context) { + session := sessions.Default(c) + session.Clear() + if err := session.Save(); err != nil { + logger.Errorf("退出登录失败: %v", err) + c.HTML(http.StatusInternalServerError, "error.html", gin.H{"error": "退出登录失败"}) + return + } + c.Redirect(http.StatusSeeOther, "/login") + }) + // 启动服务 - r.Run(":8080") + r.Run(":7070") } // 记录访问痕迹 diff --git a/gateway/templates/login.html b/gateway/templates/login.html index 5f627e3..d6e8c99 100644 --- a/gateway/templates/login.html +++ b/gateway/templates/login.html @@ -1,21 +1,131 @@ - + - Login + 登录 - 余氏族谱 + -

Login

-
- -
- -
- -
-{{ if .error }} -

{{ .error }}

-{{ end }} +
+

余氏族谱管理系统

+
+
+ + +
+
+ + +
+ +
+ {{ if .error }} +

{{ .error }}

+ {{ end }} +
\ No newline at end of file