Browse Source

✨ feat: 增加session检查接口

Pchen. 8 months ago
parent
commit
4c5dd9a220
1 changed files with 45 additions and 0 deletions
  1. 45 0
      apis/User/CheckLoginSession.js

+ 45 - 0
apis/User/CheckLoginSession.js

@@ -0,0 +1,45 @@
+const API = require("../../lib/API");
+const { BaseStdResponse } = require("../../BaseStdResponse");
+const AccessControl = require("../../lib/AccessControl");
+
+// 检查session
+class CheckLoginSession extends API {
+    constructor() {
+        super();
+
+        this.setMethod("GET");
+        this.setPath("/User/CheckLoginSession");
+    }
+
+    async onRequest(data, res) {
+        this.setAllowCORS(res);
+        let {
+            uuid,
+            session
+        } = data;
+
+        // 检查必需的参数是否缺失
+        if ([uuid, session].some(value => value === '' || value === null || value === undefined)) {
+            res.json({
+                ...BaseStdResponse.MISSING_PARAMETER,
+                endpoint: 1513123
+            });
+            return;
+        }
+
+        // 检查 session 是否有效
+        if (!await AccessControl.checkSession(uuid, session)) {
+            res.json({
+                ...BaseStdResponse.ACCESS_DENIED,
+                endpoint: 48153145
+            });
+            return;
+        }
+
+        res.json({
+            ...BaseStdResponse.OK
+        });
+    }
+}
+
+module.exports.CheckLoginSession = CheckLoginSession;