Se agregaron funciones y cambios en los dto
This commit is contained in:
@@ -14,6 +14,7 @@ import { gmail } from 'src/helpers.services/gmail.service';
|
||||
import { Servicio } from 'src/servicio/entities/servicio.entity';
|
||||
import { Usuario } from 'src/usuario/entities/usuario.entity';
|
||||
import { Like, Not, Repository } from 'typeorm';
|
||||
import * as argon2 from 'argon2';
|
||||
|
||||
@Injectable()
|
||||
export class AuthService {
|
||||
@@ -80,15 +81,15 @@ export class AuthService {
|
||||
}
|
||||
|
||||
async comparar(password, dbPassword) {
|
||||
if (!bcrypt.compareSync(password, dbPassword)) {
|
||||
return false;
|
||||
} else {
|
||||
if (await argon2.verify(password, dbPassword)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async encriptar(password) {
|
||||
return bcrypt.hashSync(password, Number(process.env.SALT_ROUNDS));
|
||||
return await argon2.hash(password);
|
||||
}
|
||||
|
||||
async generarPassword() {
|
||||
@@ -107,7 +108,7 @@ export class AuthService {
|
||||
async login(usuario: string, password: string) {
|
||||
const user = await this.userRepo.findOne({ where: { usuario } });
|
||||
if (!user) throw new UnauthorizedException('No existe este usuario.');
|
||||
const match = await bcrypt.compare(password, user.password);
|
||||
const match = await this.comparar(password, user.password);
|
||||
if (!match) throw new UnauthorizedException('Credenciales inválidas');
|
||||
if (!user.activo) throw new Error('Este usuario no esta activo.');
|
||||
const token = this.jwtCreate(
|
||||
|
||||
Reference in New Issue
Block a user