fix: 解决登录页跳转空白的问题 (#5285)
Some checks failed
Build / SonarCloud (push) Failing after -5m2s
sync2gitee / repo-sync (push) Failing after -5m3s
Build Test / build-linux-binary (push) Failing after 7s

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
}
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
}
helper.SuccessWithOutData(c)

View file

@ -1,6 +1,7 @@
package middleware
import (
"errors"
"strings"
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
@ -28,7 +29,11 @@ func BindDomain() gin.HandlerFunc {
}
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
}
c.Next()

View file

@ -4,7 +4,6 @@ import (
"net/http"
"github.com/1Panel-dev/1Panel/backend/app/repo"
"github.com/1Panel-dev/1Panel/backend/constant"
)
func LoadErrCode(errInfo string) int {
@ -22,21 +21,12 @@ func LoadErrCode(errInfo string) int {
case "403":
return http.StatusForbidden
case "404":
return http.StatusFound
return http.StatusNotFound
case "408":
return http.StatusRequestTimeout
case "416":
return http.StatusRequestedRangeNotSatisfiable
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
}
}

View file

@ -1,6 +1,7 @@
package middleware
import (
"errors"
"net"
"strings"
@ -34,7 +35,11 @@ func WhiteAllow() gin.HandlerFunc {
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())
expiredTime, err := time.ParseInLocation("2006-01-02 15:04:05", extime.Value, loc)
if err != nil {
helper.ErrResponse(c, constant.CodePasswordExpired)
helper.ErrorWithDetail(c, constant.CodePasswordExpired, constant.ErrTypePasswordExpired, err)
return
}
if time.Now().After(expiredTime) {
helper.ErrResponse(c, constant.CodePasswordExpired)
helper.ErrorWithDetail(c, constant.CodePasswordExpired, constant.ErrTypePasswordExpired, err)
return
}
c.Next()

View file

@ -55,6 +55,22 @@ class RequestHttp {
globalStore.errStatus = 'err-found';
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) {
globalStore.isProductPro = false;
window.location.reload();
@ -109,7 +125,6 @@ class RequestHttp {
router.push({ name: 'Expired' });
return;
case 500:
case 400:
case 407:
checkStatus(
response.status,
@ -122,6 +137,7 @@ class RequestHttp {
name: 'entrance',
params: { code: globalStore.entrance },
});
return;
}
}
if (!window.navigator.onLine) router.replace({ path: '/500' });

View file

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

View file

@ -83,21 +83,8 @@ const getStatus = async () => {
loading.value = false;
loadDataFromXDB();
})
.catch((err) => {
.catch(() => {
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;
}
});
};