Browse Source

添加登录限制

Michael Wang 5 years ago
parent
commit
075a05b94d
4 changed files with 50 additions and 8 deletions
  1. 1 0
      package.json
  2. 26 8
      src/features/Login/Login.vue
  3. 18 0
      src/utils/ua.js
  4. 5 0
      yarn.lock

+ 1 - 0
package.json

@@ -29,6 +29,7 @@
     "js-md5": "^0.7.3",
     "moment": "^2.24.0",
     "register-service-worker": "^1.6.2",
+    "ua-parser-js": "^0.7.20",
     "viewerjs": "^1.3.6",
     "vue": "^2.6.10",
     "vue-router": "^3.1.2",

+ 26 - 8
src/features/Login/Login.vue

@@ -127,6 +127,7 @@ import { FACE_API_MODEL_PATH } from "@/constants/constants";
 import DevTools from "./DevTools.vue";
 import nativeExe from "@/utils/nativeExe";
 import { EPCC_DOMAIN } from "@/constants/constants";
+import UA, { chromeUA } from "@/utils/ua.js";
 
 // 检测devtools.  仅在chrome 72+ 有效。
 let element = new Image();
@@ -189,7 +190,7 @@ export default {
       isElectron: true,
       disableLoginBtnBecauseRemoteApp: true,
       disableLoginBtnBecauseVCam: true,
-      disableLoginBtnBecauseNoRemoteAppChecker: false,
+      disableLoginBtnBecauseAppVersionChecker: false,
       disableLoginBtnBecauseRefreshServiceWorker: false,
       newVersionAvailable: false,
       VUE_APP_GIT_REPO_VERSION: process.env.VUE_APP_GIT_REPO_VERSION,
@@ -243,13 +244,13 @@ export default {
       //   this.isElectron,
       //   this.disableLoginBtnBecauseRemoteApp,
       //   this.disableLoginBtnBecauseVCam,
-      //   this.disableLoginBtnBecauseNoRemoteAppChecker
+      //   this.disableLoginBtnBecauseAppVersionChecker
       // );
       return (
         (this.isElectron &&
           (this.disableLoginBtnBecauseRemoteApp ||
-            this.disableLoginBtnBecauseVCam ||
-            this.disableLoginBtnBecauseNoRemoteAppChecker)) ||
+            this.disableLoginBtnBecauseVCam)) ||
+        this.disableLoginBtnBecauseAppVersionChecker ||
         this.disableLoginBtnBecauseRefreshServiceWorker
       );
     },
@@ -355,17 +356,34 @@ export default {
         "xjtu.ecs.qmth.com.cn",
         "ccnu.ecs.qmth.com.cn",
         "snnu.ecs.qmth.com.cn",
-        "cup.ecs.qmth.com.cn",
         "swjtu.ecs.qmth.com.cn",
-        "cugr.ecs.qmth.com.cn",
-        "sdu.ecs.qmth.com.cn",
       ].includes(this.$route.params.domain)
     ) {
       if (
         typeof nodeRequire == "undefined" ||
         !window.nodeRequire("fs").existsSync("multiCamera.exe")
       ) {
-        this.disableLoginBtnBecauseNoRemoteAppChecker = true;
+        this.disableLoginBtnBecauseAppVersionChecker = true;
+        this.$Message.error({
+          content: "请与学校申请最新的客户端,进行考试!",
+          duration: 2 * 24 * 60 * 60,
+        });
+      }
+    }
+
+    if (
+      [
+        "cup.ecs.qmth.com.cn",
+        "cugr.ecs.qmth.com.cn",
+        "sdu.ecs.qmth.com.cn",
+      ].includes(this.$route.params.domain)
+    ) {
+      if (
+        UA.getBrowser().name !== "electron-exam-shell" ||
+        UA.getBrowser().major !== "2" ||
+        chromeUA.major < "76"
+      ) {
+        this.disableLoginBtnBecauseAppVersionChecker = true;
         this.$Message.error({
           content: "请与学校申请最新的客户端,进行考试!",
           duration: 2 * 24 * 60 * 60,

+ 18 - 0
src/utils/ua.js

@@ -0,0 +1,18 @@
+import UAParser from "ua-parser-js";
+
+const examShellRegex = [
+  [/(electron-exam-shell)\/([\w.]+)/i],
+  [UAParser.BROWSER.NAME, UAParser.BROWSER.VERSION],
+];
+export default new UAParser(
+  null,
+  // "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) electron-exam-shell/2.0.0 Chrome/77.0.3865.120 Safari/537.36 ",
+  { browser: examShellRegex }
+);
+
+export const chromeUA = new UAParser(
+  navigator.userAgent.replace("electron-exam-shell", ""),
+  { browser: examShellRegex }
+).getBrowser();
+
+// console.log(UA.getResult());

+ 5 - 0
yarn.lock

@@ -10342,6 +10342,11 @@ typedarray@^0.0.6:
   resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
   integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=
 
+ua-parser-js@^0.7.20:
+  version "0.7.20"
+  resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.20.tgz#7527178b82f6a62a0f243d1f94fd30e3e3c21098"
+  integrity sha512-8OaIKfzL5cpx8eCMAhhvTlft8GYF8b2eQr6JkCyVdrgjcytyOmPCXrqXFcUnhonRpLlh5yxEZVohm6mzaowUOw==
+
 uglify-js@3.4.x:
   version "3.4.10"
   resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.4.10.tgz#9ad9563d8eb3acdfb8d38597d2af1d815f6a755f"