liuyu 4 vuotta sitten
vanhempi
commit
084066bbd6
3 muutettua tiedostoa jossa 39 lisäystä ja 0 poistoa
  1. 5 0
      app/controller/login.js
  2. 2 0
      app/router.js
  3. 32 0
      app/service/login.js

+ 5 - 0
app/controller/login.js

@@ -30,6 +30,11 @@ class LoginController extends Controller {
     const res = await this.service.wxlogin(this.ctx.request.body);
     this.ctx.ok({ data: res });
   }
+
+  async trtclogin() {
+    const res = await this.service.trtclogin(this.ctx.request.body);
+    this.ctx.ok({ data: res });
+  }
 }
 
 module.exports = LoginController;

+ 2 - 0
app/router.js

@@ -69,6 +69,8 @@ module.exports = app => {
 
   // 用户登录
   router.post('/api/onlive/login', controller.login.login);
+  router.post('/api/onlive/trtclogin', controller.login.trtclogin);
+
   // 根据token取得用户信息
   router.post('/api/onlive/token', controller.login.token);
   // 用户退出登录

+ 32 - 0
app/service/login.js

@@ -14,6 +14,7 @@ class LoginService extends CrudService {
     this.model = this.ctx.model.User;
     this.rmodel = this.ctx.model.Role;
     this.umodel = this.ctx.model.Roomuser;
+    this.roommodel = this.ctx.model.Room;
   }
 
   // 用户登录
@@ -84,6 +85,37 @@ class LoginService extends CrudService {
     return res;
   }
 
+  // 程序用户登录
+  async trtclogin(data) {
+    const { roomId, phone, passwd } = data;
+    const room = await this.roommodel.findOne({ name: roomId });
+    if (!room) {
+      throw new BusinessError(ErrorCode.DATA_NOT_EXIST);
+    }
+    // 根据用户输入的手机号查询其他用户表中是否存在相应数据
+    const user = await this.model.findOne({ phone });
+    // 如果用户不存在抛出异常
+    if (!user) {
+      throw new BusinessError(ErrorCode.USER_NOT_EXIST);
+    }
+    const _user = await this.model.findOne({ phone }, '+passwd');
+    // 将用户输入的密码进行加密并与查询到的用户数据密码相比对
+    const pas = await this.createJwtPwd(passwd);
+    // 如果两个密码不一致抛出异常
+    if (pas !== _user.passwd.secret) {
+      throw new BusinessError(ErrorCode.BAD_PASSWORD);
+    }
+    if (_user.role === '4') {
+      throw new BusinessError(ErrorCode.ACCESS_DENIED);
+    }
+    // 取出用户的类型,根据用户类型返回相应信息
+    const user_ = _.find(room.zjr, function(o) { return o === _user.uid; });
+    if (!user_) {
+      throw new BusinessError(ErrorCode.USER_NOT_EXIST);
+    }
+    return { uid: _user.uid };
+  }
+
 
 }
 module.exports = LoginService;