mirror of https://github.com/1Panel-dev/1Panel
fix: 登录页跳转增加 404 (#5164)
parent
c39f029808
commit
acda63d2f7
|
@ -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环境
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ const (
|
|||
CodeSuccess = 200
|
||||
CodeErrBadRequest = 400
|
||||
CodeErrUnauthorized = 401
|
||||
CodeErrNotFound = 404
|
||||
CodeAuth = 406
|
||||
CodeGlobalLoading = 407
|
||||
CodeErrInternalServer = 500
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -8,6 +8,7 @@ export enum ResultEnum {
|
|||
ERROR = 500,
|
||||
OVERDUE = 401,
|
||||
FORBIDDEN = 403,
|
||||
NOTFOUND = 404,
|
||||
ERRAUTH = 406,
|
||||
ERRGLOBALLOADDING = 407,
|
||||
ERRXPACK = 410,
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
<div v-if="errStatus.indexOf('code-') !== -1">
|
||||
<ErrCode :code="errStatus.replaceAll('code-', '')" />
|
||||
</div>
|
||||
<div v-if="errStatus === 'not-found'">
|
||||
<div v-if="errStatus === 'err-found'">
|
||||
<ErrFound />
|
||||
</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 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) => {
|
||||
|
|
Loading…
Reference in New Issue