Cambio de contraseña

This commit is contained in:
evenegas
2026-02-26 14:38:21 -06:00
4 changed files with 36 additions and 2 deletions
+13 -2
View File
@@ -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);
}
}
}
+14
View File
@@ -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 },
+5
View File
@@ -91,6 +91,11 @@ export class UsuarioController {
);
}
@Get('tipos-usuario')
async findTiposUsuario() {
return await this.usuarioService.findAll();
}
}
+4
View File
@@ -361,6 +361,10 @@ export class UsuarioService {
};
}
async findAll() {
return await this.tipoUsurioRepo.find()
}
/*c obtenerTodosLosUsuarios() {
return await this.userRepo.find({
relations: ['tipoUsuario'],