1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-31 14:08:06 +08:00

fix: 解决登录页跳转空白的问题 (#5285)

This commit is contained in:
ssongliu 2024-06-04 22:29:05 +08:00 committed by GitHub
parent 0afc6242a2
commit 7fb41f43cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 43 additions and 33 deletions

View File

@ -124,7 +124,11 @@ func (b *BaseApi) CheckIsSafety(c *gin.Context) {
return return
} }
if status == "unpass" { if status == "unpass" {
helper.ErrResponse(c, middleware.LoadErrCode("err-entrance")) if middleware.LoadErrCode("err-entrance") != 200 {
helper.ErrResponse(c, middleware.LoadErrCode("err-entrance"))
return
}
helper.ErrorWithDetail(c, constant.CodeErrEntrance, constant.ErrTypeInternalServer, nil)
return return
} }
helper.SuccessWithOutData(c) helper.SuccessWithOutData(c)

View File

@ -1,6 +1,7 @@
package middleware package middleware
import ( import (
"errors"
"strings" "strings"
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper" "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
@ -28,7 +29,11 @@ func BindDomain() gin.HandlerFunc {
} }
if domains != status.Value { if domains != status.Value {
helper.ErrResponse(c, LoadErrCode("err-domain")) if LoadErrCode("err-domain") != 200 {
helper.ErrResponse(c, LoadErrCode("err-domain"))
return
}
helper.ErrorWithDetail(c, constant.CodeErrDomain, constant.ErrTypeInternalServer, errors.New("domain not allowed"))
return return
} }
c.Next() c.Next()

View File

@ -4,7 +4,6 @@ import (
"net/http" "net/http"
"github.com/1Panel-dev/1Panel/backend/app/repo" "github.com/1Panel-dev/1Panel/backend/app/repo"
"github.com/1Panel-dev/1Panel/backend/constant"
) )
func LoadErrCode(errInfo string) int { func LoadErrCode(errInfo string) int {
@ -22,21 +21,12 @@ func LoadErrCode(errInfo string) int {
case "403": case "403":
return http.StatusForbidden return http.StatusForbidden
case "404": case "404":
return http.StatusFound return http.StatusNotFound
case "408": case "408":
return http.StatusRequestTimeout return http.StatusRequestTimeout
case "416": case "416":
return http.StatusRequestedRangeNotSatisfiable return http.StatusRequestedRangeNotSatisfiable
default: default:
if errInfo == "err-ip" {
return constant.CodeErrIP
}
if errInfo == "err-domain" {
return constant.CodeErrDomain
}
if errInfo == "err-entrance" {
return constant.CodeErrEntrance
}
return http.StatusOK return http.StatusOK
} }
} }

View File

@ -1,6 +1,7 @@
package middleware package middleware
import ( import (
"errors"
"net" "net"
"strings" "strings"
@ -34,7 +35,11 @@ func WhiteAllow() gin.HandlerFunc {
return return
} }
} }
helper.ErrResponse(c, LoadErrCode("err-ip")) if LoadErrCode("err-ip") != 200 {
helper.ErrResponse(c, LoadErrCode("err-ip"))
return
}
helper.ErrorWithDetail(c, constant.CodeErrIP, constant.ErrTypeInternalServer, errors.New("IP address not allowed"))
} }
} }

View File

@ -33,11 +33,11 @@ func PasswordExpired() gin.HandlerFunc {
loc, _ := time.LoadLocation(common.LoadTimeZone()) loc, _ := time.LoadLocation(common.LoadTimeZone())
expiredTime, err := time.ParseInLocation("2006-01-02 15:04:05", extime.Value, loc) expiredTime, err := time.ParseInLocation("2006-01-02 15:04:05", extime.Value, loc)
if err != nil { if err != nil {
helper.ErrResponse(c, constant.CodePasswordExpired) helper.ErrorWithDetail(c, constant.CodePasswordExpired, constant.ErrTypePasswordExpired, err)
return return
} }
if time.Now().After(expiredTime) { if time.Now().After(expiredTime) {
helper.ErrResponse(c, constant.CodePasswordExpired) helper.ErrorWithDetail(c, constant.CodePasswordExpired, constant.ErrTypePasswordExpired, err)
return return
} }
c.Next() c.Next()

View File

@ -55,6 +55,22 @@ class RequestHttp {
globalStore.errStatus = 'err-found'; globalStore.errStatus = 'err-found';
return; return;
} }
if (data.code == ResultEnum.ERRIP) {
globalStore.errStatus = 'err-ip';
return;
}
if (data.code == ResultEnum.ERRDOMAIN) {
globalStore.errStatus = 'err-domain';
return;
}
if (data.code == ResultEnum.UNSAFETY) {
globalStore.errStatus = 'err-unsafe';
return;
}
if (data.code == ResultEnum.EXPIRED) {
globalStore.errStatus = 'err-entrance';
return;
}
if (data.code == ResultEnum.ERRXPACK) { if (data.code == ResultEnum.ERRXPACK) {
globalStore.isProductPro = false; globalStore.isProductPro = false;
window.location.reload(); window.location.reload();
@ -109,7 +125,6 @@ class RequestHttp {
router.push({ name: 'Expired' }); router.push({ name: 'Expired' });
return; return;
case 500: case 500:
case 400:
case 407: case 407:
checkStatus( checkStatus(
response.status, response.status,
@ -122,6 +137,7 @@ class RequestHttp {
name: 'entrance', name: 'entrance',
params: { code: globalStore.entrance }, params: { code: globalStore.entrance },
}); });
return;
} }
} }
if (!window.navigator.onLine) router.replace({ path: '/500' }); if (!window.navigator.onLine) router.replace({ path: '/500' });

View File

@ -19,17 +19,20 @@ const props = defineProps({
code: String, code: String,
}); });
const loadErrInfo = () => { const loadErrInfo = () => {
console.log(props.code);
switch (props.code) { switch (props.code) {
case '400':
return '400 Bad Request';
case '401': case '401':
return '401 Unauthorized'; return '401 Unauthorized';
case '403': case '403':
return '403 Forbidden'; return '403 Forbidden';
case '404': case '404':
return '403 Not Found'; return '404 Not Found';
case '408': case '408':
return '408 Request Timeout'; return '408 Request Timeout';
case '416': case '416':
return '408 Requested Not Satisfiable'; return '416 Requested Not Satisfiable';
} }
}; };
</script> </script>

View File

@ -83,21 +83,8 @@ const getStatus = async () => {
loading.value = false; loading.value = false;
loadDataFromXDB(); loadDataFromXDB();
}) })
.catch((err) => { .catch(() => {
loading.value = false; loading.value = false;
switch (err.response.status) {
case 310:
errStatus.value = 'err-ip';
return;
case 311:
errStatus.value = 'err-domain';
return;
case 312:
errStatus.value = 'err-entrance';
return;
default:
errStatus.value = 'code-' + err.response.status;
}
}); });
}; };