From cbe9c83515e266cceb15e698ecae1a926687db9a Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Wed, 29 Mar 2023 11:46:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BA=86=20jwt=20?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E7=99=BB=E5=BD=95=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20(#436)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/v1/auth.go | 8 +- backend/init/router/router.go | 4 + backend/middleware/jwt.go | 1 - backend/middleware/session.go | 1 + cmd/server/docs/docs.go | 199 ++-------------------------------- cmd/server/docs/swagger.json | 199 ++-------------------------------- cmd/server/docs/swagger.yaml | 129 +--------------------- 7 files changed, 32 insertions(+), 509 deletions(-) diff --git a/backend/app/api/v1/auth.go b/backend/app/api/v1/auth.go index 981957b5c..a06479d8e 100644 --- a/backend/app/api/v1/auth.go +++ b/backend/app/api/v1/auth.go @@ -28,9 +28,11 @@ func (b *BaseApi) Login(c *gin.Context) { helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) return } - if err := captcha.VerifyCode(req.CaptchaID, req.Captcha); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) - return + if req.AuthMethod != "jwt" { + if err := captcha.VerifyCode(req.CaptchaID, req.Captcha); err != nil { + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + return + } } user, err := authService.Login(c, req) diff --git a/backend/init/router/router.go b/backend/init/router/router.go index fe0a35aff..5d01407a1 100644 --- a/backend/init/router/router.go +++ b/backend/init/router/router.go @@ -63,6 +63,10 @@ func Routers() *gin.Engine { systemRouter := rou.RouterGroupApp + swaggerRouter := Router.Group("1panel") + docs.SwaggerInfo.BasePath = "/api/v1" + swaggerRouter.Use(middleware.JwtAuth()).Use(middleware.SessionAuth()).GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler)) + PublicGroup := Router.Group("") { PublicGroup.GET("/health", func(c *gin.Context) { diff --git a/backend/middleware/jwt.go b/backend/middleware/jwt.go index a381286d6..e9498ec2e 100644 --- a/backend/middleware/jwt.go +++ b/backend/middleware/jwt.go @@ -16,7 +16,6 @@ import ( func JwtAuth() gin.HandlerFunc { return func(c *gin.Context) { - c.Set("authMethod", "") token := c.Request.Header.Get(constant.JWTHeaderName) if token == "" { c.Next() diff --git a/backend/middleware/session.go b/backend/middleware/session.go index 1df01429b..5bffb1cb9 100644 --- a/backend/middleware/session.go +++ b/backend/middleware/session.go @@ -14,6 +14,7 @@ func SessionAuth() gin.HandlerFunc { return func(c *gin.Context) { if method, exist := c.Get("authMethod"); exist && method == constant.AuthMethodJWT { c.Next() + return } sId, err := c.Cookie(constant.SessionName) if err != nil { diff --git a/cmd/server/docs/docs.go b/cmd/server/docs/docs.go index 26d6ba65e..53a6c05a4 100644 --- a/cmd/server/docs/docs.go +++ b/cmd/server/docs/docs.go @@ -1073,7 +1073,7 @@ var doc = `{ ], "responses": { "200": { - "description": "OK" + "description": "" } }, "x-panel-log": { @@ -6914,7 +6914,7 @@ var doc = `{ ], "responses": { "200": { - "description": "OK" + "description": "" } } }, @@ -7814,161 +7814,6 @@ var doc = `{ } } }, - "/websites/groups": { - "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "获取网站组", - "tags": [ - "Website Group" - ], - "summary": "List website groups", - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "anrry" - } - } - } - }, - "post": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "创建网站组", - "consumes": [ - "application/json" - ], - "tags": [ - "Website Group" - ], - "summary": "Create website group", - "parameters": [ - { - "description": "request", - "name": "request", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/request.WebsiteGroupCreate" - } - } - ], - "responses": { - "200": { - "description": "" - } - }, - "x-panel-log": { - "BeforeFuntions": [], - "bodyKeys": [ - "name" - ], - "formatEN": "Create website groups [name]", - "formatZH": "创建网站组 [name]", - "paramKeys": [] - } - } - }, - "/websites/groups/del": { - "post": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "删除网站组", - "consumes": [ - "application/json" - ], - "tags": [ - "Website Group" - ], - "summary": "Delete website group", - "parameters": [ - { - "description": "request", - "name": "request", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/request.WebsiteResourceReq" - } - } - ], - "responses": { - "200": { - "description": "" - } - }, - "x-panel-log": { - "BeforeFuntions": [ - { - "db": "website_groups", - "input_colume": "id", - "input_value": "id", - "isList": false, - "output_colume": "name", - "output_value": "name" - } - ], - "bodyKeys": [ - "id" - ], - "formatEN": "Delete website group [name]", - "formatZH": "删除网站组 [name]", - "paramKeys": [] - } - } - }, - "/websites/groups/update": { - "post": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "更新网站组", - "consumes": [ - "application/json" - ], - "tags": [ - "Website Group" - ], - "summary": "Update website group", - "parameters": [ - { - "description": "request", - "name": "request", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/request.WebsiteGroupUpdate" - } - } - ], - "responses": { - "200": { - "description": "" - } - }, - "x-panel-log": { - "BeforeFuntions": [], - "bodyKeys": [ - "name" - ], - "formatEN": "Update website groups [name]", - "formatZH": "更新网站组 [name]", - "paramKeys": [] - } - } - }, "/websites/list": { "get": { "security": [ @@ -9583,6 +9428,9 @@ var doc = `{ }, "dto.GroupUpdate": { "type": "object", + "required": [ + "type" + ], "properties": { "id": { "type": "integer" @@ -9592,6 +9440,9 @@ var doc = `{ }, "name": { "type": "string" + }, + "type": { + "type": "string" } } }, @@ -9913,9 +9764,6 @@ var doc = `{ }, "password": { "type": "string" - }, - "secret": { - "type": "string" } } }, @@ -10761,9 +10609,6 @@ var doc = `{ "dto.UserLoginInfo": { "type": "object", "properties": { - "mfaSecret": { - "type": "string" - }, "mfaStatus": { "type": "string" }, @@ -11869,34 +11714,6 @@ var doc = `{ } } }, - "request.WebsiteGroupCreate": { - "type": "object", - "required": [ - "name" - ], - "properties": { - "name": { - "type": "string" - } - } - }, - "request.WebsiteGroupUpdate": { - "type": "object", - "required": [ - "id" - ], - "properties": { - "default": { - "type": "boolean" - }, - "id": { - "type": "integer" - }, - "name": { - "type": "string" - } - } - }, "request.WebsiteHTTPSOp": { "type": "object", "required": [ diff --git a/cmd/server/docs/swagger.json b/cmd/server/docs/swagger.json index 75a2d5312..8d14d9c74 100644 --- a/cmd/server/docs/swagger.json +++ b/cmd/server/docs/swagger.json @@ -1059,7 +1059,7 @@ ], "responses": { "200": { - "description": "OK" + "description": "" } }, "x-panel-log": { @@ -6900,7 +6900,7 @@ ], "responses": { "200": { - "description": "OK" + "description": "" } } }, @@ -7800,161 +7800,6 @@ } } }, - "/websites/groups": { - "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "获取网站组", - "tags": [ - "Website Group" - ], - "summary": "List website groups", - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "anrry" - } - } - } - }, - "post": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "创建网站组", - "consumes": [ - "application/json" - ], - "tags": [ - "Website Group" - ], - "summary": "Create website group", - "parameters": [ - { - "description": "request", - "name": "request", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/request.WebsiteGroupCreate" - } - } - ], - "responses": { - "200": { - "description": "" - } - }, - "x-panel-log": { - "BeforeFuntions": [], - "bodyKeys": [ - "name" - ], - "formatEN": "Create website groups [name]", - "formatZH": "创建网站组 [name]", - "paramKeys": [] - } - } - }, - "/websites/groups/del": { - "post": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "删除网站组", - "consumes": [ - "application/json" - ], - "tags": [ - "Website Group" - ], - "summary": "Delete website group", - "parameters": [ - { - "description": "request", - "name": "request", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/request.WebsiteResourceReq" - } - } - ], - "responses": { - "200": { - "description": "" - } - }, - "x-panel-log": { - "BeforeFuntions": [ - { - "db": "website_groups", - "input_colume": "id", - "input_value": "id", - "isList": false, - "output_colume": "name", - "output_value": "name" - } - ], - "bodyKeys": [ - "id" - ], - "formatEN": "Delete website group [name]", - "formatZH": "删除网站组 [name]", - "paramKeys": [] - } - } - }, - "/websites/groups/update": { - "post": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "更新网站组", - "consumes": [ - "application/json" - ], - "tags": [ - "Website Group" - ], - "summary": "Update website group", - "parameters": [ - { - "description": "request", - "name": "request", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/request.WebsiteGroupUpdate" - } - } - ], - "responses": { - "200": { - "description": "" - } - }, - "x-panel-log": { - "BeforeFuntions": [], - "bodyKeys": [ - "name" - ], - "formatEN": "Update website groups [name]", - "formatZH": "更新网站组 [name]", - "paramKeys": [] - } - } - }, "/websites/list": { "get": { "security": [ @@ -9569,6 +9414,9 @@ }, "dto.GroupUpdate": { "type": "object", + "required": [ + "type" + ], "properties": { "id": { "type": "integer" @@ -9578,6 +9426,9 @@ }, "name": { "type": "string" + }, + "type": { + "type": "string" } } }, @@ -9899,9 +9750,6 @@ }, "password": { "type": "string" - }, - "secret": { - "type": "string" } } }, @@ -10747,9 +10595,6 @@ "dto.UserLoginInfo": { "type": "object", "properties": { - "mfaSecret": { - "type": "string" - }, "mfaStatus": { "type": "string" }, @@ -11855,34 +11700,6 @@ } } }, - "request.WebsiteGroupCreate": { - "type": "object", - "required": [ - "name" - ], - "properties": { - "name": { - "type": "string" - } - } - }, - "request.WebsiteGroupUpdate": { - "type": "object", - "required": [ - "id" - ], - "properties": { - "default": { - "type": "boolean" - }, - "id": { - "type": "integer" - }, - "name": { - "type": "string" - } - } - }, "request.WebsiteHTTPSOp": { "type": "object", "required": [ diff --git a/cmd/server/docs/swagger.yaml b/cmd/server/docs/swagger.yaml index 41522706c..b8b570c62 100644 --- a/cmd/server/docs/swagger.yaml +++ b/cmd/server/docs/swagger.yaml @@ -622,6 +622,10 @@ definitions: type: boolean name: type: string + type: + type: string + required: + - type type: object dto.HostConnTest: properties: @@ -837,8 +841,6 @@ definitions: type: string password: type: string - secret: - type: string type: object dto.MfaCredential: properties: @@ -1398,8 +1400,6 @@ definitions: type: object dto.UserLoginInfo: properties: - mfaSecret: - type: string mfaStatus: type: string name: @@ -2135,24 +2135,6 @@ definitions: required: - id type: object - request.WebsiteGroupCreate: - properties: - name: - type: string - required: - - name - type: object - request.WebsiteGroupUpdate: - properties: - default: - type: boolean - id: - type: integer - name: - type: string - required: - - id - type: object request.WebsiteHTTPSOp: properties: HttpConfig: @@ -3291,7 +3273,7 @@ paths: $ref: '#/definitions/dto.ComposeCreate' responses: "200": - description: OK + description: "" security: - ApiKeyAuth: [] summary: Test compose @@ -7008,7 +6990,7 @@ paths: $ref: '#/definitions/dto.Upgrade' responses: "200": - description: OK + description: "" security: - ApiKeyAuth: [] summary: Load release notes by version @@ -7584,105 +7566,6 @@ paths: formatEN: Delete domain [domain] formatZH: 删除域名 [domain] paramKeys: [] - /websites/groups: - get: - description: 获取网站组 - responses: - "200": - description: OK - schema: - type: anrry - security: - - ApiKeyAuth: [] - summary: List website groups - tags: - - Website Group - post: - consumes: - - application/json - description: 创建网站组 - parameters: - - description: request - in: body - name: request - required: true - schema: - $ref: '#/definitions/request.WebsiteGroupCreate' - responses: - "200": - description: "" - security: - - ApiKeyAuth: [] - summary: Create website group - tags: - - Website Group - x-panel-log: - BeforeFuntions: [] - bodyKeys: - - name - formatEN: Create website groups [name] - formatZH: 创建网站组 [name] - paramKeys: [] - /websites/groups/del: - post: - consumes: - - application/json - description: 删除网站组 - parameters: - - description: request - in: body - name: request - required: true - schema: - $ref: '#/definitions/request.WebsiteResourceReq' - responses: - "200": - description: "" - security: - - ApiKeyAuth: [] - summary: Delete website group - tags: - - Website Group - x-panel-log: - BeforeFuntions: - - db: website_groups - input_colume: id - input_value: id - isList: false - output_colume: name - output_value: name - bodyKeys: - - id - formatEN: Delete website group [name] - formatZH: 删除网站组 [name] - paramKeys: [] - /websites/groups/update: - post: - consumes: - - application/json - description: 更新网站组 - parameters: - - description: request - in: body - name: request - required: true - schema: - $ref: '#/definitions/request.WebsiteGroupUpdate' - responses: - "200": - description: "" - security: - - ApiKeyAuth: [] - summary: Update website group - tags: - - Website Group - x-panel-log: - BeforeFuntions: [] - bodyKeys: - - name - formatEN: Update website groups [name] - formatZH: 更新网站组 [name] - paramKeys: [] /websites/list: get: description: 获取网站列表