From 0f30683a797e19e0c7981fdf4d46b6ca0388ad7f Mon Sep 17 00:00:00 2001 From: Jrohy Date: Sat, 3 Jul 2021 18:35:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=99=BB=E5=BD=95=E6=A3=80?= =?UTF-8?q?=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/auth.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/web/auth.go b/web/auth.go index f21bf14a..37321ded 100644 --- a/web/auth.go +++ b/web/auth.go @@ -115,6 +115,7 @@ func RequestUsername(c *gin.Context) string { // Auth 权限router func Auth(r *gin.Engine) *jwt.GinJWTMiddleware { + newInstall := gin.H{"code": 201, "message": "No administrator account found inside the database", "data": nil} r.NoRoute(authMiddleware.MiddlewareFunc(), func(c *gin.Context) { claims := jwt.ExtractClaims(c) fmt.Printf("NoRoute claims: %#v\n", claims) @@ -123,7 +124,7 @@ func Auth(r *gin.Engine) *jwt.GinJWTMiddleware { r.GET("/auth/check", func(c *gin.Context) { result, _ := core.GetValue("admin_pass") if result == "" { - c.JSON(201, gin.H{"code": 201, "message": "No administrator account found inside the database", "data": nil}) + c.JSON(201, newInstall) } else { title, err := core.GetValue("login_title") if err != nil { @@ -144,13 +145,18 @@ func Auth(r *gin.Engine) *jwt.GinJWTMiddleware { authO.Use(authMiddleware.MiddlewareFunc()) { authO.GET("/loginUser", func(c *gin.Context) { - c.JSON(200, gin.H{ - "code": 200, - "message": "success", - "data": map[string]string{ - "username": RequestUsername(c), - }, - }) + result, _ := core.GetValue("admin_pass") + if result == "" { + c.JSON(201, newInstall) + } else { + c.JSON(200, gin.H{ + "code": 200, + "message": "success", + "data": map[string]string{ + "username": RequestUsername(c), + }, + }) + } }) authO.POST("/reset_pass", updateUser) authO.POST("/logout", authMiddleware.LogoutHandler)