Browse Source

fix: 新增权限校验与登录异常处理逻辑

1. 新增合法角色校验,非授权角色用户会被提示并登出
2. 统一用户名不匹配、用户已绑定场景的登出流程,替换原有linkLogin调用
3. 新增统一登出函数loginOut处理注销请求
lsc 1 month ago
parent
commit
bc68aefe86
1 changed files with 29 additions and 2 deletions
  1. 29 2
      src/App.vue

+ 29 - 2
src/App.vue

@@ -54,16 +54,36 @@ onMounted(() => {
             let userid = localStorage.getItem('userid')
             let userid = localStorage.getItem('userid')
             let username = localStorage.getItem('username')
             let username = localStorage.getItem('username')
             if(isBjt == 1){
             if(isBjt == 1){
+              if (data.currentRole == "edupersonnel" || data.currentRole == "areaAdministrator" || data.currentRole == "userAdministrator" || data.currentRole == "securityAuditor" || data.currentRole == "schoolAdministrator" || data.currentRole == "schoolSecurityAuditor" || data.currentRole == "teacher") {
+                
+              } else {
+                top.U.alert("您不是权限用户,请联系管理员授权!");
+                setTimeout(() => {
+                  loginOut()
+                }, 1000);
+                return
+              }
+              if(r.data.data.userName != username){
+                top.U.alert("与绑定用户的姓名不符,请重新登录!");
+                setTimeout(() => {
+                  loginOut()
+                }, 1000);
+                return
+              }
               if(r.data.data.userName != username){
               if(r.data.data.userName != username){
                 top.U.alert("与绑定用户的姓名不符,请重新登录!");
                 top.U.alert("与绑定用户的姓名不符,请重新登录!");
-                linkLogin()
+                setTimeout(() => {
+                  loginOut()
+                }, 1000);
                 return
                 return
               }
               }
               checkEduid(r.data.data.eduId).then(res3 => {
               checkEduid(r.data.data.eduId).then(res3 => {
                 console.log(res3);
                 console.log(res3);
                 if(res3 && res3.data && res3.data.length && res3.data[0].length){
                 if(res3 && res3.data && res3.data.length && res3.data[0].length){
                   top.U.alert("该用户已绑定其他账号,请重新登录!");
                   top.U.alert("该用户已绑定其他账号,请重新登录!");
-                  linkLogin()
+                  setTimeout(() => {
+                    loginOut()
+                  }, 1000);
                   return
                   return
                 }else {
                 }else {
                   localStorage.removeItem('isBjt')
                   localStorage.removeItem('isBjt')
@@ -110,6 +130,13 @@ const linkLogin = () => {
   }
   }
 }
 }
 
 
+
+const loginOut = () => {
+  axios.post('//cloud.cocorobo.cn/api/logout').then(res => {
+      linkLogin()
+  })
+}
+
 // 同步登录信息
 // 同步登录信息
 const userInfo = (data) => {
 const userInfo = (data) => {
   // eduId  - 教育ID
   // eduId  - 教育ID