mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-31 14:08:06 +08:00
fix: 登录页跳转增加 404 (#5164)
This commit is contained in:
parent
c39f029808
commit
acda63d2f7
@ -114,14 +114,31 @@ func (b *BaseApi) Captcha(c *gin.Context) {
|
|||||||
// @Router /auth/issafety [get]
|
// @Router /auth/issafety [get]
|
||||||
func (b *BaseApi) CheckIsSafety(c *gin.Context) {
|
func (b *BaseApi) CheckIsSafety(c *gin.Context) {
|
||||||
code := c.DefaultQuery("code", "")
|
code := c.DefaultQuery("code", "")
|
||||||
isSafe := authService.CheckIsSafety(code)
|
status, err := authService.CheckIsSafety(code)
|
||||||
if !isSafe {
|
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"))
|
helper.ErrResponse(c, middleware.LoadErrCode("err-entrance"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
helper.SuccessWithOutData(c)
|
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
|
// @Tags Auth
|
||||||
// @Summary Check System isDemo
|
// @Summary Check System isDemo
|
||||||
// @Description 判断是否为demo环境
|
// @Description 判断是否为demo环境
|
||||||
|
@ -19,7 +19,8 @@ import (
|
|||||||
type AuthService struct{}
|
type AuthService struct{}
|
||||||
|
|
||||||
type IAuthService interface {
|
type IAuthService interface {
|
||||||
CheckIsSafety(code string) bool
|
CheckIsSafety(code string) (string, error)
|
||||||
|
GetResponsePage() (string, error)
|
||||||
VerifyCode(code string) (bool, error)
|
VerifyCode(code string) (bool, error)
|
||||||
Login(c *gin.Context, info dto.Login, entrance string) (*dto.UserLoginInfo, error)
|
Login(c *gin.Context, info dto.Login, entrance string) (*dto.UserLoginInfo, error)
|
||||||
LogOut(c *gin.Context) 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
|
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"))
|
status, err := settingRepo.Get(settingRepo.WithByKey("SecurityEntrance"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return true
|
return "", err
|
||||||
}
|
}
|
||||||
if len(status.Value) == 0 {
|
if len(status.Value) == 0 {
|
||||||
return true
|
return "disable", nil
|
||||||
}
|
}
|
||||||
if status.Value == code {
|
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
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ const (
|
|||||||
CodeSuccess = 200
|
CodeSuccess = 200
|
||||||
CodeErrBadRequest = 400
|
CodeErrBadRequest = 400
|
||||||
CodeErrUnauthorized = 401
|
CodeErrUnauthorized = 401
|
||||||
|
CodeErrNotFound = 404
|
||||||
CodeAuth = 406
|
CodeAuth = 406
|
||||||
CodeGlobalLoading = 407
|
CodeGlobalLoading = 407
|
||||||
CodeErrInternalServer = 500
|
CodeErrInternalServer = 500
|
||||||
|
@ -51,6 +51,10 @@ class RequestHttp {
|
|||||||
});
|
});
|
||||||
return Promise.reject(data);
|
return Promise.reject(data);
|
||||||
}
|
}
|
||||||
|
if (data.code == ResultEnum.NOTFOUND) {
|
||||||
|
globalStore.errStatus = 'err-found';
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (data.code == ResultEnum.ERRXPACK) {
|
if (data.code == ResultEnum.ERRXPACK) {
|
||||||
globalStore.isProductPro = false;
|
globalStore.isProductPro = false;
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
@ -77,6 +81,7 @@ class RequestHttp {
|
|||||||
async (error: AxiosError) => {
|
async (error: AxiosError) => {
|
||||||
globalStore.errStatus = '';
|
globalStore.errStatus = '';
|
||||||
const { response } = error;
|
const { response } = error;
|
||||||
|
console.log(response.status);
|
||||||
if (error.message.indexOf('timeout') !== -1) MsgError('请求超时!请您稍后重试');
|
if (error.message.indexOf('timeout') !== -1) MsgError('请求超时!请您稍后重试');
|
||||||
if (response) {
|
if (response) {
|
||||||
switch (response.status) {
|
switch (response.status) {
|
||||||
|
@ -8,6 +8,7 @@ export enum ResultEnum {
|
|||||||
ERROR = 500,
|
ERROR = 500,
|
||||||
OVERDUE = 401,
|
OVERDUE = 401,
|
||||||
FORBIDDEN = 403,
|
FORBIDDEN = 403,
|
||||||
|
NOTFOUND = 404,
|
||||||
ERRAUTH = 406,
|
ERRAUTH = 406,
|
||||||
ERRGLOBALLOADDING = 407,
|
ERRGLOBALLOADDING = 407,
|
||||||
ERRXPACK = 410,
|
ERRXPACK = 410,
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
<div v-if="errStatus.indexOf('code-') !== -1">
|
<div v-if="errStatus.indexOf('code-') !== -1">
|
||||||
<ErrCode :code="errStatus.replaceAll('code-', '')" />
|
<ErrCode :code="errStatus.replaceAll('code-', '')" />
|
||||||
</div>
|
</div>
|
||||||
<div v-if="errStatus === 'not-found'">
|
<div v-if="errStatus === 'err-found'">
|
||||||
<ErrFound />
|
<ErrFound />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -46,7 +46,7 @@ import ErrIP from '@/components/error-message/err_ip.vue';
|
|||||||
import ErrCode from '@/components/error-message/error_code.vue';
|
import ErrCode from '@/components/error-message/error_code.vue';
|
||||||
import ErrDomain from '@/components/error-message/err_domain.vue';
|
import ErrDomain from '@/components/error-message/err_domain.vue';
|
||||||
import ErrFound from '@/components/error-message/404.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 { GlobalStore } from '@/store';
|
||||||
import { getXpackSetting, initFavicon } from '@/utils/xpack';
|
import { getXpackSetting, initFavicon } from '@/utils/xpack';
|
||||||
const globalStore = GlobalStore();
|
const globalStore = GlobalStore();
|
||||||
@ -61,7 +61,14 @@ const mySafetyCode = defineProps({
|
|||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
watch(
|
||||||
|
() => globalStore.errStatus,
|
||||||
|
(newVal) => {
|
||||||
|
if (newVal?.startsWith('err-') || newVal?.startsWith('code-')) {
|
||||||
|
errStatus.value = newVal;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
const getStatus = async () => {
|
const getStatus = async () => {
|
||||||
let info = globalStore.errStatus;
|
let info = globalStore.errStatus;
|
||||||
if (info?.startsWith('err-') || info?.startsWith('code-')) {
|
if (info?.startsWith('err-') || info?.startsWith('code-')) {
|
||||||
@ -74,7 +81,6 @@ const getStatus = async () => {
|
|||||||
await checkIsSafety(code)
|
await checkIsSafety(code)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
errStatus.value = '';
|
|
||||||
loadDataFromXDB();
|
loadDataFromXDB();
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user