From acda63d2f70902de0989cfa277f0b60ff56f1905 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Mon, 27 May 2024 18:42:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=99=BB=E5=BD=95=E9=A1=B5=E8=B7=B3?= =?UTF-8?q?=E8=BD=AC=E5=A2=9E=E5=8A=A0=20404=20(#5164)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/v1/auth.go | 21 +++++++++++++++++++-- backend/app/service/auth.go | 21 +++++++++++++++------ backend/constant/errs.go | 1 + frontend/src/api/index.ts | 5 +++++ frontend/src/enums/http-enum.ts | 1 + frontend/src/views/login/entrance/index.vue | 14 ++++++++++---- 6 files changed, 51 insertions(+), 12 deletions(-) diff --git a/backend/app/api/v1/auth.go b/backend/app/api/v1/auth.go index 7dc47b8af..be2727060 100644 --- a/backend/app/api/v1/auth.go +++ b/backend/app/api/v1/auth.go @@ -114,14 +114,31 @@ func (b *BaseApi) Captcha(c *gin.Context) { // @Router /auth/issafety [get] func (b *BaseApi) CheckIsSafety(c *gin.Context) { code := c.DefaultQuery("code", "") - isSafe := authService.CheckIsSafety(code) - if !isSafe { + status, err := authService.CheckIsSafety(code) + if err != nil { + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + return + } + if status == "disable" && len(code) != 0 { + helper.ErrorWithDetail(c, constant.CodeErrNotFound, constant.ErrTypeInternalServer, err) + return + } + if status == "unpass" { helper.ErrResponse(c, middleware.LoadErrCode("err-entrance")) return } helper.SuccessWithOutData(c) } +func (b *BaseApi) GetResponsePage(c *gin.Context) { + pageCode, err := authService.GetResponsePage() + if err != nil { + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + return + } + helper.SuccessWithData(c, pageCode) +} + // @Tags Auth // @Summary Check System isDemo // @Description 判断是否为demo环境 diff --git a/backend/app/service/auth.go b/backend/app/service/auth.go index 7be4668f3..118ffd982 100644 --- a/backend/app/service/auth.go +++ b/backend/app/service/auth.go @@ -19,7 +19,8 @@ import ( type AuthService struct{} type IAuthService interface { - CheckIsSafety(code string) bool + CheckIsSafety(code string) (string, error) + GetResponsePage() (string, error) VerifyCode(code string) (bool, error) Login(c *gin.Context, info dto.Login, entrance string) (*dto.UserLoginInfo, error) LogOut(c *gin.Context) error @@ -172,16 +173,24 @@ func (u *AuthService) VerifyCode(code string) (bool, error) { return hmac.Equal([]byte(setting.Value), []byte(code)), nil } -func (u *AuthService) CheckIsSafety(code string) bool { +func (u *AuthService) CheckIsSafety(code string) (string, error) { status, err := settingRepo.Get(settingRepo.WithByKey("SecurityEntrance")) if err != nil { - return true + return "", err } if len(status.Value) == 0 { - return true + return "disable", nil } if status.Value == code { - return true + return "pass", nil } - return false + return "unpass", nil +} + +func (u *AuthService) GetResponsePage() (string, error) { + pageCode, err := settingRepo.Get(settingRepo.WithByKey("NoAuthSetting")) + if err != nil { + return "", err + } + return pageCode.Value, nil } diff --git a/backend/constant/errs.go b/backend/constant/errs.go index 26ea7bd0b..d5429800c 100644 --- a/backend/constant/errs.go +++ b/backend/constant/errs.go @@ -8,6 +8,7 @@ const ( CodeSuccess = 200 CodeErrBadRequest = 400 CodeErrUnauthorized = 401 + CodeErrNotFound = 404 CodeAuth = 406 CodeGlobalLoading = 407 CodeErrInternalServer = 500 diff --git a/frontend/src/api/index.ts b/frontend/src/api/index.ts index 0f2909a39..c090354fe 100644 --- a/frontend/src/api/index.ts +++ b/frontend/src/api/index.ts @@ -51,6 +51,10 @@ class RequestHttp { }); return Promise.reject(data); } + if (data.code == ResultEnum.NOTFOUND) { + globalStore.errStatus = 'err-found'; + return; + } if (data.code == ResultEnum.ERRXPACK) { globalStore.isProductPro = false; window.location.reload(); @@ -77,6 +81,7 @@ class RequestHttp { async (error: AxiosError) => { globalStore.errStatus = ''; const { response } = error; + console.log(response.status); if (error.message.indexOf('timeout') !== -1) MsgError('请求超时!请您稍后重试'); if (response) { switch (response.status) { diff --git a/frontend/src/enums/http-enum.ts b/frontend/src/enums/http-enum.ts index aa9c6f640..289877779 100644 --- a/frontend/src/enums/http-enum.ts +++ b/frontend/src/enums/http-enum.ts @@ -8,6 +8,7 @@ export enum ResultEnum { ERROR = 500, OVERDUE = 401, FORBIDDEN = 403, + NOTFOUND = 404, ERRAUTH = 406, ERRGLOBALLOADDING = 407, ERRXPACK = 410, diff --git a/frontend/src/views/login/entrance/index.vue b/frontend/src/views/login/entrance/index.vue index 0bd82958f..24ad1642e 100644 --- a/frontend/src/views/login/entrance/index.vue +++ b/frontend/src/views/login/entrance/index.vue @@ -30,7 +30,7 @@