https://project.mdnd-it.cc/work_packages/94
This commit is contained in:
2025-08-23 04:25:28 +02:00
parent 725516ad6c
commit 19cfa031d0
25823 changed files with 1095587 additions and 2801760 deletions
@@ -0,0 +1,41 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.VerifyEmailCommandHandler = void 0;
const TokenService_1 = require("../../Services/TokenService");
const UserAggregate_1 = require("../../../Domain/User/UserAggregate");
const Logger_1 = require("../../Services/Logger");
class VerifyEmailCommandHandler {
constructor(userRepo) {
this.userRepo = userRepo;
}
async execute(cmd) {
try {
if (!cmd.token) {
throw new Error('Verification token is required');
}
// Hash the token to compare with stored value
const hashedToken = await TokenService_1.TokenService.hashToken(cmd.token);
// Find user with this verification token
const user = await this.userRepo.findByToken(hashedToken);
if (!user) {
throw new Error('Invalid or expired verification token');
}
// Check if token is expired
if (user.TokenExpires && user.TokenExpires < new Date()) {
throw new Error('Verification token has expired');
}
// Update user verification status
user.token = null;
user.TokenExpires = null;
user.state = UserAggregate_1.UserState.VERIFIED_REGULAR;
await this.userRepo.update(user.id, user);
return true;
}
catch (error) {
(0, Logger_1.logError)('Email verification error', error instanceof Error ? error : new Error(String(error)));
throw error;
}
}
}
exports.VerifyEmailCommandHandler = VerifyEmailCommandHandler;
//# sourceMappingURL=VerifyEmailCommandHandler.js.map