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 @@
-
+
@@ -46,7 +46,7 @@ import ErrIP from '@/components/error-message/err_ip.vue'; import ErrCode from '@/components/error-message/error_code.vue'; import ErrDomain from '@/components/error-message/err_domain.vue'; import ErrFound from '@/components/error-message/404.vue'; -import { ref, onMounted } from 'vue'; +import { ref, onMounted, watch } from 'vue'; import { GlobalStore } from '@/store'; import { getXpackSetting, initFavicon } from '@/utils/xpack'; const globalStore = GlobalStore(); @@ -61,7 +61,14 @@ const mySafetyCode = defineProps({ default: '', }, }); - +watch( + () => globalStore.errStatus, + (newVal) => { + if (newVal?.startsWith('err-') || newVal?.startsWith('code-')) { + errStatus.value = newVal; + } + }, +); const getStatus = async () => { let info = globalStore.errStatus; if (info?.startsWith('err-') || info?.startsWith('code-')) { @@ -74,7 +81,6 @@ const getStatus = async () => { await checkIsSafety(code) .then(() => { loading.value = false; - errStatus.value = ''; loadDataFromXDB(); }) .catch((err) => {