logins en auth

This commit is contained in:
xXpuma99Xx
2022-04-21 20:33:05 -05:00
parent 844f290737
commit d38bd391d0
11 changed files with 58 additions and 42 deletions
+31 -2
View File
@@ -1,9 +1,38 @@
import { Injectable } from '@nestjs/common';
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { BcryptService } from '../bcrypt/bcrypt.service';
import { OperadorService } from '../operador/operador.service';
import { UsuarioService } from '../usuario/usuario.service';
@Injectable()
export class AuthService {
constructor() {}
constructor(
private bcryptService: BcryptService,
private operadorService: OperadorService,
private usuarioService: UsuarioService,
) {}
validate() {}
loginUsuario(usuario: string, password: string) {
return this.usuarioService.findByUsuario(usuario).then((usuario) => {
if (!this.bcryptService.comparar(password, usuario.password))
throw new UnauthorizedException(
'Usuario y/o contraseña incorrectos, trata de nuevo.',
);
/* Crear JWT y regresarlo */
return usuario;
});
}
loginOperador(operador: string, password: string) {
return this.operadorService.findByOperador(operador).then((operador) => {
if (!this.bcryptService.comparar(password, operador.password))
throw new UnauthorizedException(
'Usuario y/o contraseña incorrectos, trata de nuevo.',
);
/* Crear JWT y regresarlo */
return operador;
});
}
}