diff --git a/backend/app/api/v1/auth.go b/backend/app/api/v1/auth.go index e7bd86e02..96796d9b7 100644 --- a/backend/app/api/v1/auth.go +++ b/backend/app/api/v1/auth.go @@ -103,7 +103,12 @@ func (b *BaseApi) Captcha(c *gin.Context) { // @Router /auth/issafety [get] func (b *BaseApi) CheckIsSafety(c *gin.Context) { code := c.DefaultQuery("code", "") - helper.SuccessWithData(c, authService.CheckIsSafety(code)) + status, err := authService.CheckIsSafety(code) + if err != nil { + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + return + } + helper.SuccessWithData(c, status) } // @Tags Auth diff --git a/backend/app/service/auth.go b/backend/app/service/auth.go index 6842124cd..5ddc7cc8c 100644 --- a/backend/app/service/auth.go +++ b/backend/app/service/auth.go @@ -17,7 +17,7 @@ import ( type AuthService struct{} type IAuthService interface { - CheckIsSafety(code string) bool + CheckIsSafety(code string) (string, error) VerifyCode(code string) (bool, error) Login(c *gin.Context, info dto.Login) (*dto.UserLoginInfo, error) LogOut(c *gin.Context) error @@ -143,13 +143,16 @@ func (u *AuthService) VerifyCode(code string) (bool, error) { return setting.Value == 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 false + return "", err } if len(status.Value) == 0 { - return true + return "disable", nil } - return status.Value == code + if status.Value == code { + return "pass", nil + } + return "unpass", nil } diff --git a/frontend/src/api/modules/auth.ts b/frontend/src/api/modules/auth.ts index 18edf5c1e..120bdce47 100644 --- a/frontend/src/api/modules/auth.ts +++ b/frontend/src/api/modules/auth.ts @@ -18,7 +18,7 @@ export const logOutApi = () => { }; export const checkIsSafety = (code: string) => { - return http.get(`/auth/issafety?code=${code}`); + return http.get(`/auth/issafety?code=${code}`); }; export const checkIsDemo = () => { diff --git a/frontend/src/layout/index.vue b/frontend/src/layout/index.vue index 2684d999d..18b997e45 100644 --- a/frontend/src/layout/index.vue +++ b/frontend/src/layout/index.vue @@ -65,6 +65,7 @@ const loadDataFromDB = async () => { document.title = res.data.panelName; i18n.locale.value = res.data.language; i18n.warnHtmlMessage = false; + globalStore.entrance = res.data.securityEntrance; globalStore.updateLanguage(res.data.language); globalStore.setThemeConfig({ ...themeConfig.value, theme: res.data.theme }); globalStore.setThemeConfig({ ...themeConfig.value, panelName: res.data.panelName }); diff --git a/frontend/src/routers/index.ts b/frontend/src/routers/index.ts index a49e4697c..d8c5b1b7b 100644 --- a/frontend/src/routers/index.ts +++ b/frontend/src/routers/index.ts @@ -29,15 +29,6 @@ router.beforeEach((to, from, next) => { } if (!to.matched.some((record) => record.meta.requiresAuth)) return next(); - if (!globalStore.isLogin) { - next({ - name: 'entrance', - params: { code: globalStore.entrance }, - }); - NProgress.done(); - return; - } - return next(); }); diff --git a/frontend/src/views/login/entrance/index.vue b/frontend/src/views/login/entrance/index.vue index aafb87c3b..fa430e1e5 100644 --- a/frontend/src/views/login/entrance/index.vue +++ b/frontend/src/views/login/entrance/index.vue @@ -1,6 +1,6 @@ @@ -32,6 +35,7 @@ import { checkIsSafety } from '@/api/modules/auth'; import LoginForm from '../components/login-form.vue'; import UnSafe from '@/components/error-message/unsafe.vue'; import ErrIP from '@/components/error-message/err_ip.vue'; +import ErrFound from '@/components/error-message/404.vue'; import ErrDomain from '@/components/error-message/err_domain.vue'; import { ref, onMounted } from 'vue'; import { GlobalStore } from '@/store'; @@ -40,6 +44,7 @@ const globalStore = GlobalStore(); const isSafety = ref(true); const screenWidth = ref(null); const isErr = ref(); +const isNotFound = ref(); const mySafetyCode = defineProps({ code: { @@ -50,15 +55,24 @@ const mySafetyCode = defineProps({ }); const getStatus = async () => { - if (mySafetyCode.code === 'err-ip' || mySafetyCode.code === 'err-domain') { - isErr.value = true; - } + isErr.value = true; const res = await checkIsSafety(mySafetyCode.code); - if (mySafetyCode.code === 'err-ip' || mySafetyCode.code === 'err-domain') { - isErr.value = false; + isErr.value = false; + globalStore.entrance = ''; + if (res.data === 'disable') { + if (mySafetyCode.code === '') { + isNotFound.value = false; + } else { + isNotFound.value = true; + } + return; } - isSafety.value = res.data; - if (isSafety.value) { + isNotFound.value = false; + if (res.data !== 'pass') { + isSafety.value = false; + return; + } + if (res.data === 'pass') { globalStore.entrance = mySafetyCode.code; } }; diff --git a/frontend/src/views/login/index.vue b/frontend/src/views/login/index.vue index 18a6f29b1..b4257c220 100644 --- a/frontend/src/views/login/index.vue +++ b/frontend/src/views/login/index.vue @@ -31,7 +31,7 @@ const screenWidth = ref(null); const getStatus = async () => { const res = await checkIsSafety(globalStore.entrance); - if (!res.data) { + if (res.data === 'unpass') { router.replace({ name: 'entrance' }); } }; diff --git a/frontend/src/views/setting/safe/index.vue b/frontend/src/views/setting/safe/index.vue index d8cd003b7..ad46eec78 100644 --- a/frontend/src/views/setting/safe/index.vue +++ b/frontend/src/views/setting/safe/index.vue @@ -171,6 +171,8 @@ import { updateSetting, getSettingInfo, getSystemAvailable, updateSSL, loadSSLIn import i18n from '@/lang'; import { MsgSuccess } from '@/utils/message'; import { Setting } from '@/api/interface/setting'; +import { GlobalStore } from '@/store'; +const globalStore = GlobalStore(); const loading = ref(false); const entranceRef = ref(); @@ -280,8 +282,14 @@ const handleSSL = async () => { await updateSSL({ ssl: 'disable', domain: '', sslType: '', key: '', cert: '', sslID: 0 }); MsgSuccess(i18n.global.t('commons.msg.operationSuccess')); let href = window.location.href; + globalStore.isLogin = false; let address = href.split('://')[1]; - window.open(`http://${address}/`, '_self'); + if (globalStore.entrance) { + address = address.replaceAll('settings/safe', globalStore.entrance); + } else { + address = address.replaceAll('settings/safe', 'login'); + } + window.location.href = `http://${address}`; }) .catch(() => { form.ssl = 'enable'; diff --git a/frontend/src/views/setting/safe/port/index.vue b/frontend/src/views/setting/safe/port/index.vue index f1e90f104..11d5c3d73 100644 --- a/frontend/src/views/setting/safe/port/index.vue +++ b/frontend/src/views/setting/safe/port/index.vue @@ -72,7 +72,14 @@ const onSavePort = async (formEl: FormInstance | undefined) => { globalStore.isLogin = false; let href = window.location.href; let ip = href.split('//')[1].split(':')[0]; - window.open(`${href.split('//')[0]}//${ip}:${form.serverPort}/${globalStore.entrance}`, '_self'); + if (globalStore.entrance) { + window.open( + `${href.split('//')[0]}//${ip}:${form.serverPort}/${globalStore.entrance}`, + '_self', + ); + } else { + window.open(`${href.split('//')[0]}//${ip}:${form.serverPort}/login`, '_self'); + } }) .catch(() => { loading.value = false; diff --git a/frontend/src/views/setting/safe/ssl/index.vue b/frontend/src/views/setting/safe/ssl/index.vue index eaba02f59..25a084349 100644 --- a/frontend/src/views/setting/safe/ssl/index.vue +++ b/frontend/src/views/setting/safe/ssl/index.vue @@ -212,7 +212,11 @@ const onSaveSSL = async (formEl: FormInstance | undefined) => { let href = window.location.href; globalStore.isLogin = false; let address = href.split('://')[1]; - address = address.replaceAll('settings/safe', globalStore.entrance); + if (globalStore.entrance) { + address = address.replaceAll('settings/safe', globalStore.entrance); + } else { + address = address.replaceAll('settings/safe', 'login'); + } window.open(`https://${address}`, '_self'); }); });