|
@@ -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;
|