Cambio de contraseña
This commit is contained in:
@@ -7,10 +7,10 @@ import {
|
||||
UnauthorizedException,
|
||||
} from '@nestjs/common';
|
||||
import { AuthService } from './auth.service';
|
||||
|
||||
|
||||
@Controller('auth')
|
||||
export class AuthController {
|
||||
constructor(private readonly authService: AuthService) {}
|
||||
constructor(private readonly authService: AuthService) { }
|
||||
|
||||
// ===================== LOGIN =====================
|
||||
@Post('login')
|
||||
@@ -36,4 +36,15 @@ export class AuthController {
|
||||
throw new UnauthorizedException(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// ===================== ACTUALIZAR CONTRASEÑA ADMIN =====================
|
||||
@Post('update-password')
|
||||
async updatePassword() {
|
||||
try {
|
||||
const newPassword = await this.authService.update_password();
|
||||
return { message: 'Contraseña actualizada correctamente.', contraseña: newPassword };
|
||||
} catch (error) {
|
||||
throw new UnauthorizedException(error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,6 +73,20 @@ export class AuthService {
|
||||
return password;
|
||||
}
|
||||
|
||||
async update_password() {
|
||||
let user = await this.userRepo.findOne({ where: { tipoUsuario: { idTipoUsuario: 1 } } })
|
||||
|
||||
if (!user) throw new NotFoundException('No se encontró el usuario administrador.');
|
||||
const newPassword = await this.generarPassword();
|
||||
const hashedPassword = await this.encriptar(newPassword);
|
||||
user.password = hashedPassword;
|
||||
await this.userRepo.save(user);
|
||||
return newPassword;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
async login(usuario: string, password: string) {
|
||||
const user = await this.userRepo.findOne({
|
||||
where: { usuario },
|
||||
|
||||
@@ -91,6 +91,11 @@ export class UsuarioController {
|
||||
);
|
||||
}
|
||||
|
||||
@Get('tipos-usuario')
|
||||
async findTiposUsuario() {
|
||||
return await this.usuarioService.findAll();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -361,6 +361,10 @@ export class UsuarioService {
|
||||
};
|
||||
}
|
||||
|
||||
async findAll() {
|
||||
return await this.tipoUsurioRepo.find()
|
||||
}
|
||||
|
||||
/*c obtenerTodosLosUsuarios() {
|
||||
return await this.userRepo.find({
|
||||
relations: ['tipoUsuario'],
|
||||
|
||||
Reference in New Issue
Block a user