Refatoração do login page

This commit is contained in:
unknown
2025-03-28 17:48:56 -03:00
parent b98b219e52
commit 36aea127c1
15 changed files with 227 additions and 202 deletions

View File

@@ -0,0 +1,23 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { UserRepository } from '../users/UserRepository';
import md5 = require('md5');
@Injectable()
export class ChangePasswordService {
constructor(private readonly userRepository: UserRepository) {}
async execute(userId: number, oldPassword: string, newPassword: string) {
const current = await this.userRepository.findByIdAndPassword(
userId,
md5(oldPassword).toUpperCase(),
);
if (!current) {
throw new NotFoundException('Usuário não encontrado ou senha inválida');
}
const newPasswordHash = md5(newPassword).toUpperCase();
await this.userRepository.updatePassword(userId, newPasswordHash);
return current;
}
}