login admin mejorado
This commit is contained in:
+15
-17
@@ -21,23 +21,19 @@ export class AuthService {
|
||||
) {}
|
||||
|
||||
loginAdmin(admin: string, password: string) {
|
||||
return this.operadorService.findAdmin(admin, false).then((operador) => {
|
||||
// if (!operador.activo)
|
||||
// throw new ConflictException('Esta cuenta se encuentra desactivada.');
|
||||
|
||||
const payload: JwtPayload = {
|
||||
id_operador: operador.id_operador,
|
||||
nombre: operador.nombre,
|
||||
operador: operador.operador,
|
||||
institucion: operador.institucion
|
||||
? { id_institucion: operador.institucion.id_institucion }
|
||||
: null,
|
||||
tipoUsuario: {
|
||||
id_tipo_usuario: operador.tipoUsuario.id_tipo_usuario,
|
||||
},
|
||||
};
|
||||
|
||||
return { operador, token: this.jwtService.sign(payload) };
|
||||
return this.operadorService.informacionAdmin(admin).then((data) => {
|
||||
if (
|
||||
!data.operador ||
|
||||
!this.bcryptService.comparar(password, data.password)
|
||||
)
|
||||
throw new BadRequestException(
|
||||
'Usuario y/o password incorrectos, ingresa unas credenciales válidas.',
|
||||
);
|
||||
if (!data.activo)
|
||||
throw new UnauthorizedException(
|
||||
'Esta cuenta se encuentra desactivada.',
|
||||
);
|
||||
return { token: this.jwtService.sign(data.operador) };
|
||||
});
|
||||
}
|
||||
|
||||
@@ -64,6 +60,8 @@ export class AuthService {
|
||||
|
||||
loginUsuario(usuario: string, password: string) {
|
||||
return this.usuarioService.informacionUsuario(usuario).then((data) => {
|
||||
if (!data.password)
|
||||
throw new BadRequestException('Este usuario no ha sido registrado.');
|
||||
if (
|
||||
!data.usuario ||
|
||||
!this.bcryptService.comparar(password, data.password)
|
||||
|
||||
@@ -194,12 +194,11 @@ export class OperadorService {
|
||||
});
|
||||
}
|
||||
|
||||
informacionAdmin(institucion: Institucion, admin: string) {
|
||||
informacionAdmin(admin: string) {
|
||||
return this.informacionOperadorView
|
||||
.findOne({
|
||||
where: {
|
||||
operador: admin,
|
||||
id_institucion: institucion.id_institucion,
|
||||
id_tipo_usuario: Between(2, 3),
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user