|
@@ -17,26 +17,11 @@ class LoginService extends CrudService {
|
|
|
async login(data) {
|
|
|
const { mobile, password } = data;
|
|
|
// 根据用户输入的手机号查询其他用户表中是否存在相应数据
|
|
|
- let user = await this.model.findOne({ mobile });
|
|
|
- const flag = true;
|
|
|
- if (!user) {
|
|
|
- user = await this.model.findOne({ mobile });
|
|
|
- }
|
|
|
- // 如果用户不存在抛出异常
|
|
|
+ const user = await this.model.findOne({ mobile }, '+password');
|
|
|
if (!user) {
|
|
|
throw new BusinessError(ErrorCode.USER_NOT_EXIST);
|
|
|
}
|
|
|
- let _user = '';
|
|
|
- // 将用户输入的密码进行加密并与查询到的用户数据密码相比对
|
|
|
- // const pasw = await this.createJwtPwd(password);
|
|
|
- if (flag) {
|
|
|
- // 手机
|
|
|
- _user = await this.model.findOne({ mobile, password });
|
|
|
- } else {
|
|
|
- // 手机
|
|
|
- _user = await this.model.findOne({ mobile, password });
|
|
|
- }
|
|
|
- if (_user === '') {
|
|
|
+ if (user.password.secret !== password) {
|
|
|
throw new BusinessError(ErrorCode.USER_NOT_EXIST);
|
|
|
}
|
|
|
// 取出用户的类型,根据用户类型返回相应信息
|