mirror of https://github.com/1Panel-dev/1Panel
fix: 优化未启用安全入口跳转逻辑 (#1210)
parent
cbdf1ad7b7
commit
bb48964cca
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ export const logOutApi = () => {
|
|||
};
|
||||
|
||||
export const checkIsSafety = (code: string) => {
|
||||
return http.get<boolean>(`/auth/issafety?code=${code}`);
|
||||
return http.get<string>(`/auth/issafety?code=${code}`);
|
||||
};
|
||||
|
||||
export const checkIsDemo = () => {
|
||||
|
|
|
@ -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 });
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<template>
|
||||
<div>
|
||||
<div class="login-backgroud" v-if="isSafety && !isErr">
|
||||
<div class="login-backgroud" v-if="isSafety && !isErr && !isNotFound">
|
||||
<div class="login-wrapper">
|
||||
<div :class="screenWidth > 1110 ? 'left inline-block' : ''">
|
||||
<div class="login-title">
|
||||
|
@ -15,15 +15,18 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="!isSafety && !isErr">
|
||||
<div v-if="!isSafety && !isErr && !isNotFound">
|
||||
<UnSafe />
|
||||
</div>
|
||||
<div v-if="isErr && mySafetyCode.code === 'err-ip'">
|
||||
<div v-if="isErr && mySafetyCode.code === 'err-ip' && !isNotFound">
|
||||
<ErrIP />
|
||||
</div>
|
||||
<div v-if="isErr && mySafetyCode.code === 'err-domain'">
|
||||
<div v-if="isErr && mySafetyCode.code === 'err-domain' && !isNotFound">
|
||||
<ErrDomain />
|
||||
</div>
|
||||
<div v-if="isNotFound">
|
||||
<ErrFound />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
const res = await checkIsSafety(mySafetyCode.code);
|
||||
if (mySafetyCode.code === 'err-ip' || mySafetyCode.code === 'err-domain') {
|
||||
isErr.value = false;
|
||||
globalStore.entrance = '';
|
||||
if (res.data === 'disable') {
|
||||
if (mySafetyCode.code === '') {
|
||||
isNotFound.value = false;
|
||||
} else {
|
||||
isNotFound.value = true;
|
||||
}
|
||||
isSafety.value = res.data;
|
||||
if (isSafety.value) {
|
||||
return;
|
||||
}
|
||||
isNotFound.value = false;
|
||||
if (res.data !== 'pass') {
|
||||
isSafety.value = false;
|
||||
return;
|
||||
}
|
||||
if (res.data === 'pass') {
|
||||
globalStore.entrance = mySafetyCode.code;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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' });
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -212,7 +212,11 @@ const onSaveSSL = async (formEl: FormInstance | undefined) => {
|
|||
let href = window.location.href;
|
||||
globalStore.isLogin = false;
|
||||
let address = href.split('://')[1];
|
||||
if (globalStore.entrance) {
|
||||
address = address.replaceAll('settings/safe', globalStore.entrance);
|
||||
} else {
|
||||
address = address.replaceAll('settings/safe', 'login');
|
||||
}
|
||||
window.open(`https://${address}`, '_self');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue