Explorar el Código

v1.1.11

修复一些bug(验证方法修改。)
skyffire hace 5 meses
padre
commit
bc439b9265
Se han modificado 2 ficheros con 34 adiciones y 18 borrados
  1. 1 1
      example/main.js
  2. 33 17
      example/src/App.js

+ 1 - 1
example/main.js

@@ -9,7 +9,7 @@ const password = 'skyfffire-password';
 const key = crypto.createHash('sha256').update(password).digest();
 let memoryCache = {};
 
-const loginFilePath = path.join(app.getPath('userData'), 'loginSession.json');
+const loginFilePath = path.join(app.getPath('userData'), 'loginSession2.json');
 const symbolFilePath = path.join(app.getPath('userData'), 'symbolSession.json');
 const persistentFilePath = path.join(app.getPath('userData'), 'persistentSession.json');
 const mergeFilePath = path.join(app.getPath('userData'), 'mergeSession.json');

+ 33 - 17
example/src/App.js

@@ -209,19 +209,34 @@ export default () => {
   const checkStatus = async ()=>{
     toast.remove();
     const loginInfo = await window.electronAPI.getLoginInfoData() || {}
-    const params = {
-      "code": loginInfo.code,
-      "machine": loginInfo.machine
+    // const params = {
+    //   // 不再依赖联网获取 code 和 machine
+    //   // 我们可以直接检查从 electronAPI 获取的 loginInfo 中 code 的格式
+    //   "code": loginInfo.code,
+    //   "machine": loginInfo.machine
+    // }
+
+  // 离线验证:检查 code 是否是 UUID 格式
+    function isValidUUID(uuid) {
+      const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
+      return uuidRegex.test(uuid);
     }
-    const response = await axios.post('http://139.159.224.218:38888/check_status',params)
-    if(response.data.code !== 200){
-      if(window.sessionStorage.getItem("_HEATMAP_IS_LOGIN") === "1") toast.error(response.data.msg)
-      window.sessionStorage.setItem("_HEATMAP_IS_LOGIN", "0")
-      setIsActivation(false)
-      return
+
+  // 调用 isValidUUID 函数进行本地验证
+    if (!loginInfo.code || !isValidUUID(loginInfo.code)) {
+      // 如果 code 不存在或不是有效的 UUID 格式,则视为验证失败
+      if(window.sessionStorage.getItem("_HEATMAP_IS_LOGIN") === "1") {
+        // 可以根据需要显示不同的错误信息,例如 "本地验证失败,无效的激活码"
+        toast.error("本地验证失败,无效的激活码");
+      }
+      window.sessionStorage.setItem("_HEATMAP_IS_LOGIN", "0");
+      setIsActivation(false);
+      return;
     }
-    setIsActivation(true)
-    window.sessionStorage.setItem("_HEATMAP_IS_LOGIN", "1")
+
+// 如果 code 是有效的 UUID 格式,则视为验证成功
+    setIsActivation(true);
+    window.sessionStorage.setItem("_HEATMAP_IS_LOGIN", "1");
   }
 
   // 保存数据库到本地
@@ -245,11 +260,12 @@ export default () => {
       "code": activationCode,
       "machine": uuidv4()
     }
-    const response = await axios.post('http://139.159.224.218:38888/login', params)
-    if(response.data.code === 200){
+    // const response = await axios.post('http://1.1.1.1:38888/login', params)
+    // if(response.data.code === 200){
       await window.electronAPI.setLoginInfoData(params)
+      await checkStatus()
       window.sessionStorage.setItem("_HEATMAP_IS_LOGIN", "1")
-      toast.success(response.data.msg)
+      toast.success('登录成功,请不要泄露自己的激活码')
       setInterval(()=>{
         checkStatus()
       }, 5000)
@@ -262,9 +278,9 @@ export default () => {
           saveLocalDb()
         }, 30 * 1000)
       }
-    }else{
-      toast.error(response.data.msg);
-    }
+    // }else{
+    //   toast.error(response.data.msg);
+    // }
   }
 
   // ---------- window update ------------