Explorar o código

第三方登录

Michael Wang %!s(int64=5) %!d(string=hai) anos
pai
achega
1bd1b18692
Modificáronse 3 ficheiros con 180 adicións e 15 borrados
  1. 91 15
      src/features/Login/Login.vue
  2. 83 0
      src/features/Login/StudentAccess.vue
  3. 6 0
      src/router.js

+ 91 - 15
src/features/Login/Login.vue

@@ -191,8 +191,18 @@ export default {
         this.newVersionAvailable = true;
       }
     }, 1000);
+    if (this.isEPCC) {
+      this.login();
+    }
   },
   async created() {
+    if (this.isEPCC) {
+      this.$Spin.show({
+        render: () => {
+          return <div style="font-size: 44px">正在登录...</div>;
+        },
+      });
+    }
     localStorage.setItem("redirectUrl", this.$route.query.redirectUrl);
 
     this.isElectron = typeof nodeRequire != "undefined";
@@ -265,21 +275,29 @@ export default {
       this.loginTimeout = setTimeout(() => {
         this.loginBtnLoading = false;
       }, 10 * 1000);
-      // https://www.cnblogs.com/weiqinl/p/6708993.html
-      const valid = await this.$refs.loginForm.validate();
-      if (!valid) {
-        return;
-      }
+      let loginResponse;
+      if (!this.isEPCC) {
+        // https://www.cnblogs.com/weiqinl/p/6708993.html
+        const valid = await this.$refs.loginForm.validate();
+        if (!valid) {
+          return;
+        }
 
-      let repPara = this.loginForm;
-      // 以下网络请求失败,直接报网络异常错误
-      const response = await this.$http.post("/api/ecs_core/auth/login", {
-        ...repPara,
-        accountType: this.loginType,
-        domain: this.schoolDomain,
-        alwaysOK: true,
-      });
-      let data = response.data;
+        let repPara = this.loginForm;
+        // 以下网络请求失败,直接报网络异常错误
+        loginResponse = await this.$http.post("/api/ecs_core/auth/login", {
+          ...repPara,
+          accountType: this.loginType,
+          domain: this.schoolDomain,
+          alwaysOK: true,
+        });
+      } else {
+        loginResponse = await this.epccLogin();
+        if (!loginResponse) {
+          return;
+        }
+      }
+      let data = loginResponse.data;
       // if (
       //   Math.abs() >
       //   5 * 60 * 1000
@@ -292,7 +310,9 @@ export default {
       //   throw "与服务器时间差异超过5分钟,请校准本机时间之后再重试!";
       // }
 
-      this.updateTimeDifference(moment(response.headers.date).diff(moment()));
+      this.updateTimeDifference(
+        moment(loginResponse.headers.date).diff(moment())
+      );
       if (data.code == "200") {
         data = data.content;
         this.errorInfo = "";
@@ -556,6 +576,59 @@ export default {
         }
       }
     },
+    async epccLogin() {
+      const {
+        accountType,
+        accountValue,
+        rootOrgId,
+        appId,
+        timestamp,
+        token,
+        redirectUrl,
+      } = this.$route.query;
+
+      if (
+        accountType &&
+        accountValue &&
+        rootOrgId &&
+        appId &&
+        timestamp &&
+        token &&
+        redirectUrl
+      ) {
+        try {
+          const response = await this.$http.post(
+            "/api/ecs_core/auth/thirdPartyStudentAccess",
+            {
+              accountType,
+              accountValue,
+              rootOrgId,
+              appId,
+              timestamp,
+              token,
+            }
+          );
+          return response;
+        } catch (error) {
+          window._hmt.push(["_trackEvent", "第三方登录页面", "接口出错", ""]);
+          this.$Modal.error({
+            title: "返回",
+            content: "第三方登录访问错误",
+            onOk: () => {
+              history.back();
+            },
+          });
+        }
+      } else {
+        this.$Modal.error({
+          title: "返回",
+          content: "第三方登录参数错误",
+          onOk: () => {
+            history.back();
+          },
+        });
+      }
+    },
   },
   computed: {
     logoPath() {
@@ -581,6 +654,9 @@ export default {
       }
       return domain;
     },
+    isEPCC() {
+      return this.schoolDomain === "iepcc-ps.qmth.com.cn";
+    },
     usernameInputPlaceholder() {
       if (this.loginType === "STUDENT_CODE") {
         return "请输入学号";

+ 83 - 0
src/features/Login/StudentAccess.vue

@@ -0,0 +1,83 @@
+<template>
+  <div>
+    第三方登录
+    <br />
+    <Button @click="goBack"></Button>
+  </div>
+</template>
+
+<script>
+export default {
+  name: "StudentAccess",
+  async created() {
+    const {
+      accountType,
+      accountValue,
+      rootOrgId,
+      appId,
+      timestamp,
+      token,
+      redirectUrl,
+    } = this.$route.query;
+
+    if (
+      accountType &&
+      accountValue &&
+      rootOrgId &&
+      appId &&
+      timestamp &&
+      token &&
+      redirectUrl
+    ) {
+      try {
+        const response = await this.$http.post(
+          "/api/ecs_core/auth/thirdPartyStudentAccess",
+          {
+            accountType,
+            accountValue,
+            rootOrgId,
+            appId,
+            timestamp,
+            token,
+          }
+        );
+        const domain = response.data.rootOrgDomain;
+        const o = {
+          accountType,
+          accountValue,
+          rootOrgId,
+          appId,
+          timestamp,
+          token,
+        };
+        const query = Object.keys(o)
+          .map(key => key + "=" + o[key])
+          .join("&");
+        this.$router.push("/login/" + domain + "?" + query);
+      } catch (error) {
+        window._hmt.push(["_trackEvent", "第三方登录页面", "接口出错", ""]);
+        this.$Modal.error({
+          title: "返回",
+          content: "第三方登录访问错误",
+          onOk: () => {
+            history.back();
+          },
+        });
+      }
+    } else {
+      this.$Modal.error({
+        title: "返回",
+        content: "第三方登录参数错误",
+        onOk: () => {
+          history.back();
+        },
+      });
+    }
+  },
+  methods: {
+    goBack() {
+      history.back();
+    },
+  },
+};
+</script>

+ 6 - 0
src/router.js

@@ -11,6 +11,7 @@ import OnlinePracticeHome from "./features/OnlinePractice/OnlinePracticeHome.vue
 import OnlinePracticeRecordList from "./features/OnlinePractice/OnlinePracticeRecordList.vue";
 import OnlinePracticeRecordDetail from "./features/OnlinePractice/OnlinePracticeRecordDetail.vue";
 import Login from "./features/Login/Login.vue";
+import StudentAccess from "./features/Login/StudentAccess.vue";
 import SiteMessageHome from "./features/SiteMessage/SiteMessageHome.vue";
 import SiteMessageDetail from "./features/SiteMessage/SiteMessageDetail.vue";
 import Password from "./features/Password/Password.vue";
@@ -30,6 +31,11 @@ let router = new Router({
       name: "Login",
       component: Login,
     },
+    {
+      path: "/StudentAccess",
+      name: "StudentAccess",
+      component: StudentAccess,
+    },
     {
       path: "/online-exam",
       name: "OnlineExamHome",