Ver código fonte

外部评审权限功能

warrior 3 semanas atrás
pai
commit
4e9a6ba188

+ 37 - 18
projects/textbook/src/modules/review-verify/auth.guard.ts

@@ -42,41 +42,60 @@ export class AuthGuard implements CanActivate {
               'https://audit.hep.com.cn/admin/401?noGoBack=0';
             this.router.navigate([this.LoginPage]);
             resolve(false);
-            // Parse.User.logIn('145review', 'review-textbook145').then((user) => {
-            //     resolve(true);
+            // fetch('https://145.tbook.com.cn/api/textbook/review/token', {
+            //   method: 'POST',
+            //   headers: {
+            //     'Content-Type': 'application/json',
+            //   },
             // })
-            // Parse.User.become('r:4d692312d4b08d4120981152e67428f8')
-            //   .then((user) => resolve(true))
-            //   .catch((err) => {
-            //     resolve(false);
-            //     this.router.navigate([this.LoginPage]);
+            //   .then((response) => response.json())
+            //   .then(async (res) => {
+            //     console.log(res);
             //   });
           } else {
             if (!Parse.User.current()?.id) {
-              fetch('https://145.tbook.com.cn/api/textbook/review/token', {
-                method: 'POST',
-                headers: {
-                  'Content-Type': 'application/json',
-                },
-              })
-                .then((response) => response.json())
-                .then(async (res) => {
+              Parse.Cloud.run('reviewToken')
+                .then((res) => {
                   Parse.User.become(
                     res?.token || 'r:4d692312d4b08d4120981152e67428f8'
                   )
                     .then((user) => resolve(true))
                     .catch((err) => {
-                      console.log(err);
+                      console.error(err);
                       window.location.href =
                         'https://audit.hep.com.cn/admin/401?noGoBack=0';
                       resolve(false);
                     });
                 })
-                .catch((error) => {
-                  console.error('获取token失败:', error);
+                .catch((err) => {
+                  console.error('获取token失败:', err);
                   resolve(false);
                   this.router.navigate([this.LoginPage]);
                 });
+              // fetch('https://145.tbook.com.cn/api/textbook/review/token', {
+              //   method: 'POST',
+              //   headers: {
+              //     'Content-Type': 'application/json',
+              //   },
+              // })
+              //   .then((response) => response.json())
+              //   .then(async (res) => {
+              //     Parse.User.become(
+              //       res?.token || 'r:4d692312d4b08d4120981152e67428f8'
+              //     )
+              //       .then((user) => resolve(true))
+              //       .catch((err) => {
+              //         console.log(err);
+              //         window.location.href =
+              //           'https://audit.hep.com.cn/admin/401?noGoBack=0';
+              //         resolve(false);
+              //       });
+              //   })
+              //   .catch((error) => {
+              //     console.error('获取token失败:', error);
+              //     resolve(false);
+              //     this.router.navigate([this.LoginPage]);
+              //   });
             } else {
               resolve(true);
             }

+ 1 - 1
server/api/textbook/routes.js

@@ -198,7 +198,7 @@ async function setMobileSessionToken(user, reset) {
 router.post("/review/token", async (req, res) => {
     let refer = req.headers["referer"] || req.headers["referered"];
     // 检查referer来源
-    if (refer && refer.includes('https://145.tbook.com.cn')) {
+    if (refer && refer.indexOf('https://145.tbook.com.cn') == 0) {
        Parse.User.logIn('145review', 'review-textbook145').then((user) => {
             console.log(user?.get('sessionToken'));
             response.json({

+ 15 - 0
server/cloud/tbook/func-tbook-isbn.js

@@ -41,5 +41,20 @@ export function defineTbookISBN(){
             }
         }
     });
+    Parse.Cloud.define("reviewToken", async (request) => {
+        let refer = request.headers["referer"] || request.headers["referered"];
+        // 检查referer来源
+        if (refer && refer.indexOf('https://145.tbook.com.cn') == 0) {
+           Parse.User.logIn('145review', 'review-textbook145').then((user) => {
+                // console.log(user?.get('sessionToken'));
+                return {token: user?.get('sessionToken')}
+            }).catch(err=>{
+                throw new Parse.Error(404,"invalid user")
+            })
+        }else{
+            throw new Parse.Error(404,"not found referer")
+        }
+    })
+
 }