lrf402788946 4 years ago
parent
commit
754a0a52d2
4 changed files with 46 additions and 27 deletions
  1. 4 0
      app/controller/.trainlive.js
  2. 1 0
      app/router.js
  3. 11 3
      app/service/trainlive.js
  4. 30 24
      config/config.default.js

+ 4 - 0
app/controller/.trainlive.js

@@ -90,5 +90,9 @@ module.exports = {
   login:{
     requestBody: ["room_id", "password"],
     service: "login",
+  },
+  userLonger:{
+    params: ["!id"],
+    service: "userLonger",
   }
 };

+ 1 - 0
app/router.js

@@ -115,6 +115,7 @@ module.exports = app => {
   router.post('imgtxtdock', '/api/live/imgtxtdock/update/:id', controller.imgtxtdock.update);
 
   // 培训问诊表
+  router.get('trainlive', '/api/live/trainlive/user/longer/:id', controller.trainlive.userLonger);
   router.post('trainlive', '/api/live/trainlive/login', controller.trainlive.login);
   router.post('trainlive', '/api/live/trainlive/user/login/:id', controller.trainlive.userLogin);
   router.post('trainlive', '/api/live/trainlive/user/logout/:id', controller.trainlive.userLogout);

+ 11 - 3
app/service/trainlive.js

@@ -96,19 +96,27 @@ class TrainliveService extends CrudService {
     if (!object) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到指定的培训问诊信息!');
     const user = object.user_data.find(f => f.user_phone === user_phone);
     if (!user) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到培训问诊下该手机号的用户信息!');
-    const is_login = await this.app.redis.get(`trainlive/${user._id}`);
+    // const is_login = await this.app.redis.get(`trainlive/${user._id}`);
+    const is_login = this.ctx.session[`trainlive/${user._id}`];
     if (is_login) throw new BusinessError(ErrorCode.BUSINESS, '用户已登录');
     if (user.user_password !== user_password) throw new BusinessError(ErrorCode.BAD_PASSWORD, '用户密码错误!');
-    await this.app.redis.set(`trainlive/${user._id}`, user);
+    this.ctx.session[`trainlive/${user._id}`] = user;
+    // await this.app.redis.set(`trainlive/${user._id}`, user);
     return user;
   }
 
+  async userLonger({ id }) {
+    const is_login = this.ctx.session[`trainlive/${id}`];
+    if (!is_login) throw new BusinessError(ErrorCode.BUSINESS, '用户登陆已失效,请重新登陆');
+  }
+
   /**
    * 参会人员注销
    * @param {String} {id} 参会人员id
    */
   async userLogout({ id }) {
-    await this.app.redis.del(`trainlive/${id}`);
+    this.ctx.session[`trainlive/${id}`] = null;
+    // await this.app.redis.del(`trainlive/${id}`);
   }
 }
 

+ 30 - 24
config/config.default.js

@@ -40,24 +40,24 @@ module.exports = appInfo => {
   config.mongoose = {
     url: 'mongodb://localhost:27017/platform',
     options: {
-      user: 'admin',
-      pass: 'admin',
-      authSource: 'admin',
-      useNewUrlParser: true,
-      useCreateIndex: true,
-      useUnifiedTopology: true,
+      // user: 'admin',
+      // pass: 'admin',
+      // authSource: 'admin',
+      // useNewUrlParser: true,
+      // useCreateIndex: true,
+      // useUnifiedTopology: true,
     },
   };
-  config.amqp = {
-    client: {
-      hostname: '127.0.0.1',
-      username: 'visit',
-      password: 'visit',
-      vhost: 'visit',
-    },
-    app: true,
-    agent: true,
-  };
+  // config.amqp = {
+  //   client: {
+  //     hostname: '127.0.0.1',
+  //     username: 'visit',
+  //     password: 'visit',
+  //     vhost: 'visit',
+  //   },
+  //   app: true,
+  //   agent: true,
+  // };
 
   // // JWT config
   config.jwt = {
@@ -67,14 +67,20 @@ module.exports = appInfo => {
   };
 
   // redis config
-  // config.redis = {
-  //   client: {
-  //     port: 6379, // Redis port
-  //     host: '127.0.0.1', // Redis host
-  //     password: 123456,
-  //     db: 0,
-  //   },
-  // };
+  config.redis = {
+    client: {
+      port: 6379, // Redis port
+      host: '127.0.0.1', // Redis host
+      password: 123456,
+      db: 0,
+    },
+  };
+
+  config.session = {
+    maxAge: 1000 * 60 * 30, // 30=>30min
+    renew: true,
+  };
+
 
   return {
     ...config,