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)