Ver Fonte

哈哈哈

liuyu há 4 anos atrás
pai
commit
0dce9882fb
1 ficheiros alterados com 21 adições e 4 exclusões
  1. 21 4
      app/service/login.js

+ 21 - 4
app/service/login.js

@@ -19,7 +19,7 @@ class LoginService extends CrudService {
 
   // 用户登录
   async login(data) {
-    const { phone, passwd } = data;
+    const { phone, passwd, roomId } = data;
     // 根据用户输入的手机号查询其他用户表中是否存在相应数据
     const user = await this.model.findOne({ phone });
     // 如果用户不存在抛出异常
@@ -36,6 +36,22 @@ class LoginService extends CrudService {
     if (_user.role === '4') {
       throw new BusinessError(ErrorCode.ACCESS_DENIED);
     }
+    let type = '0';
+    let roomid = '';
+    if (roomId) {
+      const room = await this.roommodel.findOne({ name: roomId });
+      if (!room) {
+        throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '房间号不存在');
+      }
+      // 取出用户的类型,根据用户类型返回相应信息
+      const userzjr_ = _.find(room.zjr, function(o) { return o === _user.uid; });
+      if (!userzjr_) {
+        throw new BusinessError(ErrorCode.USER_NOT_EXIST, '房间号内没有您的直播信息');
+      }
+      roomid = room.id;
+      type = '1';
+    }
+
     // 取出用户的类型,根据用户类型返回相应信息
     const state = uuid();
     const key = `free:auth:state:${state}`;
@@ -47,7 +63,8 @@ class LoginService extends CrudService {
       }
     }
     user.menus = JSON.stringify(_menus);
-    const token = await this.createJwt(user);
+    const newdata = { ...JSON.parse(JSON.stringify(user)), type, roomid, roomname: roomId };
+    const token = await this.createJwt(newdata);
     await this.app.redis.set(key, token, 'EX', 60 * 60 * 24);
     return { key };
   }
@@ -60,10 +77,10 @@ class LoginService extends CrudService {
   }
 
   // 创建登录Token
-  async createJwt({ id, name, uid, phone, role, menus, remark, openid, deptname }) {
+  async createJwt({ id, name, uid, phone, role, menus, remark, openid, deptname, type, roroomid, roomname }) {
     const { secret, expiresIn = '1d', issuer = role } = this.config.jwt;
     const subject = phone;
-    const res = { id, uid, name, phone, role, menus, openid, remark, deptname };
+    const res = { id, uid, name, phone, role, menus, openid, remark, deptname, type, roroomid, roomname };
     const token = await jwt.sign(res, secret, { expiresIn, issuer, subject });
     return token;
   }