Validación de correo y contraseña

This commit is contained in:
Traym17 2022-07-10 20:46:54 -06:00
parent b8034a875c
commit c2595d919d
2 changed files with 27 additions and 3 deletions

View File

@ -43,6 +43,7 @@ export class UsersController {
@MessagePattern({ cmd: 'loginUser' })
findLogin(@Payload() body:string) {
let pemail= body['email'];
return this.userService.findLogin(pemail);
let ppassword= body['password'];
return this.userService.findHero(pemail,ppassword);
}
}

View File

@ -39,7 +39,30 @@ export class UsersService {
}
//inicio de sesion
async findLogin(email: string): Promise<User> {
return this.userModel.findOne({ email:email}).exec();
async findLogin(email: string, password: string): Promise<User> {
return this.userModel.findOne({ email:email},{ password:password}).exec();
}
async findHero(email: string, password: string) : Promise<User> {
let repo1=this.userModel;
let p = new Promise<User>((resolve, reject) => {
let repo =repo1;
repo.find({ email : email }).exec((err, res) => {
if (err) {
reject(err);
}
else {
if (res[0].password==password) {
resolve(res[0]);
}
else {
resolve(null);
}
}
});
});
return p;
}
}