mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2024-11-27 12:39:01 +08:00
feat: 增加验证失败之后的跳转
This commit is contained in:
parent
253015e6ff
commit
94281558ae
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,6 +4,7 @@
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
.idea
|
||||
|
||||
# Test binary, built with `go test -c`
|
||||
*.test
|
||||
|
@ -32,4 +32,5 @@ var (
|
||||
ErrTypeInvalidParams = "ErrInvalidParams"
|
||||
ErrTypeToken = "ErrToken"
|
||||
ErrTypeTokenTimeOut = "ErrTokenTimeOut"
|
||||
ErrTypeNotLogin = "ErrNotLogin"
|
||||
)
|
||||
|
@ -7,3 +7,4 @@ ErrInternalServer: "Service internal error: {{ .detail }}"
|
||||
ErrRecordExist: "Record already exists: {{ .detail }}"
|
||||
ErrRecordNotFound: "Records not found: {{ .detail }}"
|
||||
ErrStructTransform: "Type conversion failure: {{ .detail }}"
|
||||
ErrTypeNotLogin: "User is not Login"
|
@ -7,3 +7,4 @@ ErrInternalServer: "服务内部错误: {{ .detail }}"
|
||||
ErrRecordExist: "记录已存在: {{ .detail }}"
|
||||
ErrRecordNotFound: "记录未能找到: {{ .detail }}"
|
||||
ErrStructTransform: "类型转换失败: {{ .detail }}"
|
||||
ErrTypeNotLogin: "用户未登录"
|
@ -15,7 +15,7 @@ func CSRF() gin.HandlerFunc {
|
||||
csrf.ErrorHandler(http.HandlerFunc(
|
||||
func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
_, _ = w.Write([]byte("message: csrf token invalid"))
|
||||
_, _ = w.Write([]byte("csrf token invalid"))
|
||||
})),
|
||||
)
|
||||
return adapter.Wrap(csrfMd)
|
||||
|
@ -14,11 +14,11 @@ func SessionAuth() gin.HandlerFunc {
|
||||
}
|
||||
sId, err := c.Cookie(global.CONF.Session.SessionName)
|
||||
if err != nil {
|
||||
helper.ErrorWithDetail(c, constant.CodeErrUnauthorized, constant.ErrTypeToken, nil)
|
||||
helper.ErrorWithDetail(c, constant.CodeErrUnauthorized, constant.ErrTypeNotLogin, nil)
|
||||
return
|
||||
}
|
||||
if _, err := global.SESSION.Get(sId); err != nil {
|
||||
helper.ErrorWithDetail(c, constant.CodeErrUnauthorized, constant.ErrTypeToken, nil)
|
||||
helper.ErrorWithDetail(c, constant.CodeErrUnauthorized, constant.ErrTypeNotLogin, nil)
|
||||
return
|
||||
}
|
||||
c.Next()
|
||||
|
@ -1,4 +1,6 @@
|
||||
import i18n from '@/lang';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import router from '@/routers';
|
||||
|
||||
/**
|
||||
* @description: 校验网络请求状态码
|
||||
@ -8,36 +10,19 @@ import { ElMessage } from 'element-plus';
|
||||
export const checkStatus = (status: number): void => {
|
||||
switch (status) {
|
||||
case 400:
|
||||
ElMessage.error('请求失败!请您稍后重试');
|
||||
break;
|
||||
case 401:
|
||||
ElMessage.error('登录失效!请您重新登录');
|
||||
break;
|
||||
case 403:
|
||||
ElMessage.error('当前账号无权限访问!');
|
||||
ElMessage.error(i18n.global.t('commons.res.paramError'));
|
||||
break;
|
||||
case 404:
|
||||
ElMessage.error('你所访问的资源不存在!');
|
||||
ElMessage.error(i18n.global.t('commons.res.notFound'));
|
||||
break;
|
||||
case 405:
|
||||
ElMessage.error('请求方式错误!请您稍后重试');
|
||||
break;
|
||||
case 408:
|
||||
ElMessage.error('请求超时!请您稍后重试');
|
||||
case 403:
|
||||
router.replace({ path: '/login' });
|
||||
ElMessage.error(i18n.global.t('commons.res.forbidden'));
|
||||
break;
|
||||
case 500:
|
||||
ElMessage.error('服务异常!');
|
||||
break;
|
||||
case 502:
|
||||
ElMessage.error('网关错误!');
|
||||
break;
|
||||
case 503:
|
||||
ElMessage.error('服务不可用!');
|
||||
break;
|
||||
case 504:
|
||||
ElMessage.error('网关超时!');
|
||||
ElMessage.error(i18n.global.t('commons.res.serverError'));
|
||||
break;
|
||||
default:
|
||||
ElMessage.error('请求失败!');
|
||||
ElMessage.error(i18n.global.t('commons.res.commonError'));
|
||||
}
|
||||
};
|
||||
|
@ -49,7 +49,7 @@ class RequestHttp {
|
||||
}
|
||||
axiosCanceler.removePending(config);
|
||||
tryHideFullScreenLoading();
|
||||
if (data.code == ResultEnum.OVERDUE) {
|
||||
if (data.code == ResultEnum.OVERDUE || data.code == ResultEnum.FORBIDDEN) {
|
||||
ElMessage.error(data.msg);
|
||||
router.replace({
|
||||
path: '/login',
|
||||
|
@ -2,6 +2,7 @@ export enum ResultEnum {
|
||||
SUCCESS = 200,
|
||||
ERROR = 500,
|
||||
OVERDUE = 401,
|
||||
FORBIDDEN = 403,
|
||||
TIMEOUT = 10000,
|
||||
TYPE = 'success',
|
||||
}
|
||||
|
@ -39,6 +39,13 @@ export default {
|
||||
commonName: 'Support English, Chinese, numbers, .-_, length 1-30',
|
||||
email: 'Email format error',
|
||||
},
|
||||
res: {
|
||||
paramError: 'The request failed, please try again later!',
|
||||
forbidden: 'The current user has no permission',
|
||||
serverError: 'Service exception',
|
||||
notFound: 'The resource does not exist',
|
||||
commonError: 'The request failed',
|
||||
},
|
||||
},
|
||||
business: {
|
||||
user: {
|
||||
|
@ -39,6 +39,13 @@ export default {
|
||||
commonName: '支持英文、中文、数字、.-_,长度1-30',
|
||||
email: '邮箱格式错误',
|
||||
},
|
||||
res: {
|
||||
paramError: '请求失败,请稍后重试!',
|
||||
forbidden: '当前用户无权限',
|
||||
serverError: '服务异常',
|
||||
notFound: '资源不存在',
|
||||
commonError: '请求失败',
|
||||
},
|
||||
},
|
||||
business: {
|
||||
user: {
|
||||
|
Loading…
Reference in New Issue
Block a user