Skip to content

Commit

Permalink
优化登录检测
Browse files Browse the repository at this point in the history
  • Loading branch information
Jrohy committed Jul 3, 2021
1 parent b023b12 commit 0f30683
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions web/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit 0f30683

Please sign in to comment.