logins en auth
This commit is contained in:
@@ -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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user