feat: 增加验证失败之后的跳转

This commit is contained in:
zhengkunwang223 2022-08-17 11:47:56 +08:00
parent 253015e6ff
commit 94281558ae
11 changed files with 34 additions and 30 deletions

1
.gitignore vendored
View File

@ -4,6 +4,7 @@
*.dll
*.so
*.dylib
.idea
# Test binary, built with `go test -c`
*.test

View File

@ -32,4 +32,5 @@ var (
ErrTypeInvalidParams = "ErrInvalidParams"
ErrTypeToken = "ErrToken"
ErrTypeTokenTimeOut = "ErrTokenTimeOut"
ErrTypeNotLogin = "ErrNotLogin"
)

View File

@ -6,4 +6,5 @@ ErrCaptchaCode: "The verification code information is incorrect"
ErrInternalServer: "Service internal error: {{ .detail }}"
ErrRecordExist: "Record already exists: {{ .detail }}"
ErrRecordNotFound: "Records not found: {{ .detail }}"
ErrStructTransform: "Type conversion failure: {{ .detail }}"
ErrStructTransform: "Type conversion failure: {{ .detail }}"
ErrTypeNotLogin: "User is not Login"

View File

@ -6,4 +6,5 @@ ErrCaptchaCode: "错误的验证码信息"
ErrInternalServer: "服务内部错误: {{ .detail }}"
ErrRecordExist: "记录已存在: {{ .detail }}"
ErrRecordNotFound: "记录未能找到: {{ .detail }}"
ErrStructTransform: "类型转换失败: {{ .detail }}"
ErrStructTransform: "类型转换失败: {{ .detail }}"
ErrTypeNotLogin: "用户未登录"

View File

@ -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)

View File

@ -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()

View File

@ -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'));
}
};

View File

@ -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',

View File

@ -2,6 +2,7 @@ export enum ResultEnum {
SUCCESS = 200,
ERROR = 500,
OVERDUE = 401,
FORBIDDEN = 403,
TIMEOUT = 10000,
TYPE = 'success',
}

View File

@ -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: {

View File

@ -39,6 +39,13 @@ export default {
commonName: '支持英文、中文、数字、.-_,长度1-30',
email: '邮箱格式错误',
},
res: {
paramError: '请求失败,请稍后重试!',
forbidden: '当前用户无权限',
serverError: '服务异常',
notFound: '资源不存在',
commonError: '请求失败',
},
},
business: {
user: {