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