From 67c1fbd07ae91ac0f127c6bb9496f097f339b05d Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Wed, 13 Nov 2024 14:44:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E7=99=BB=E9=99=86?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E7=89=B9=E5=BE=81=E4=BF=A1=E6=81=AF=20(#7027?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs #7000 --- backend/app/api/v1/auth.go | 8 ++- backend/middleware/bind_domain.go | 5 +- backend/middleware/helper.go | 2 +- backend/middleware/ip_limit.go | 5 +- frontend/src/api/index.ts | 3 +- .../components/error-message/error_code.vue | 6 -- frontend/src/views/login/entrance/index.vue | 59 +++++++++---------- 7 files changed, 42 insertions(+), 46 deletions(-) diff --git a/backend/app/api/v1/auth.go b/backend/app/api/v1/auth.go index e1959e1dc..435c36a7c 100644 --- a/backend/app/api/v1/auth.go +++ b/backend/app/api/v1/auth.go @@ -2,6 +2,7 @@ package v1 import ( "encoding/base64" + "net/http" "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper" "github.com/1Panel-dev/1Panel/backend/app/dto" @@ -120,12 +121,13 @@ func (b *BaseApi) CheckIsSafety(c *gin.Context) { return } if status == "disable" && len(code) != 0 { - helper.ErrorWithDetail(c, constant.CodeErrNotFound, constant.ErrTypeInternalServer, err) + helper.ErrResponse(c, http.StatusNotFound) return } if status == "unpass" { - if middleware.LoadErrCode("err-entrance") != 200 { - helper.ErrResponse(c, middleware.LoadErrCode("err-entrance")) + code := middleware.LoadErrCode() + if code != 200 { + helper.ErrResponse(c, code) return } helper.ErrorWithDetail(c, constant.CodeErrEntrance, constant.ErrTypeInternalServer, nil) diff --git a/backend/middleware/bind_domain.go b/backend/middleware/bind_domain.go index 1b561cbe6..8ca06f2ea 100644 --- a/backend/middleware/bind_domain.go +++ b/backend/middleware/bind_domain.go @@ -29,8 +29,9 @@ func BindDomain() gin.HandlerFunc { } if domains != status.Value { - if LoadErrCode("err-domain") != 200 { - helper.ErrResponse(c, LoadErrCode("err-domain")) + code := LoadErrCode() + if code != 200 { + helper.ErrResponse(c, code) return } helper.ErrorWithDetail(c, constant.CodeErrDomain, constant.ErrTypeInternalServer, errors.New("domain not allowed")) diff --git a/backend/middleware/helper.go b/backend/middleware/helper.go index b25c99907..eb422ece7 100644 --- a/backend/middleware/helper.go +++ b/backend/middleware/helper.go @@ -6,7 +6,7 @@ import ( "github.com/1Panel-dev/1Panel/backend/app/repo" ) -func LoadErrCode(errInfo string) int { +func LoadErrCode() int { settingRepo := repo.NewISettingRepo() codeVal, err := settingRepo.Get(settingRepo.WithByKey("NoAuthSetting")) if err != nil { diff --git a/backend/middleware/ip_limit.go b/backend/middleware/ip_limit.go index 9bef2b80a..d396b78ed 100644 --- a/backend/middleware/ip_limit.go +++ b/backend/middleware/ip_limit.go @@ -35,8 +35,9 @@ func WhiteAllow() gin.HandlerFunc { return } } - if LoadErrCode("err-ip") != 200 { - helper.ErrResponse(c, LoadErrCode("err-ip")) + code := LoadErrCode() + if code != 200 { + helper.ErrResponse(c, code) return } helper.ErrorWithDetail(c, constant.CodeErrIP, constant.ErrTypeInternalServer, errors.New("IP address not allowed")) diff --git a/frontend/src/api/index.ts b/frontend/src/api/index.ts index ca40a309e..57e5393e6 100644 --- a/frontend/src/api/index.ts +++ b/frontend/src/api/index.ts @@ -132,12 +132,13 @@ class RequestHttp { ); return; default: + globalStore.isLogin = false; globalStore.errStatus = 'code-' + response.status; router.push({ name: 'entrance', params: { code: globalStore.entrance }, }); - return; + return Promise.reject(error); } } if (!window.navigator.onLine) router.replace({ path: '/500' }); diff --git a/frontend/src/components/error-message/error_code.vue b/frontend/src/components/error-message/error_code.vue index 2bd25d957..fb3e28ad8 100644 --- a/frontend/src/components/error-message/error_code.vue +++ b/frontend/src/components/error-message/error_code.vue @@ -33,9 +33,3 @@ const loadErrInfo = () => { } }; - - diff --git a/frontend/src/views/login/entrance/index.vue b/frontend/src/views/login/entrance/index.vue index af74d26af..6ddf0f247 100644 --- a/frontend/src/views/login/entrance/index.vue +++ b/frontend/src/views/login/entrance/index.vue @@ -1,17 +1,19 @@