feat: implement JWT token generation in VerifyOtpTokenCommandHandler and update related configurations

This commit is contained in:
masoodafar-web
2026-02-03 00:02:04 +03:30
parent c3eeb16856
commit b41342dcad
4 changed files with 21 additions and 6 deletions
@@ -5,10 +5,12 @@ namespace CMSMicroservice.Application.UserCQ.Commands.VerifyOtpToken;
public class VerifyOtpTokenCommandHandler : IRequestHandler<VerifyOtpTokenCommand, VerifyOtpTokenResponseDto>
{
private readonly IApplicationDbContext _context;
private readonly IGenerateJwtToken _generateJwt;
public VerifyOtpTokenCommandHandler(IApplicationDbContext context)
public VerifyOtpTokenCommandHandler(IApplicationDbContext context, IGenerateJwtToken generateJwt)
{
_context = context;
_generateJwt = generateJwt;
}
public async Task<VerifyOtpTokenResponseDto> Handle(VerifyOtpTokenCommand request, CancellationToken cancellationToken)
@@ -22,6 +24,11 @@ public class VerifyOtpTokenCommandHandler : IRequestHandler<VerifyOtpTokenComman
return new VerifyOtpTokenResponseDto { IsSuccess = false, Message = "کد تایید نامعتبر است" };
var user = await _context.Users
.Include(u => u.UserContracts)
.ThenInclude(uc => uc.Contract)
.Include(u => u.UserRoles)
.ThenInclude(ur => ur.Role)
.Include(u => u.ClubMembership)
.Where(x => x.Mobile == request.Mobile)
.FirstOrDefaultAsync(cancellationToken);
@@ -32,12 +39,14 @@ public class VerifyOtpTokenCommandHandler : IRequestHandler<VerifyOtpTokenComman
otpToken.IsUsed = true;
await _context.SaveChangesAsync(cancellationToken);
// TODO: Implement JWT token generation
// Generate JWT token
var token = await _generateJwt.GenerateJwtToken(user);
return new VerifyOtpTokenResponseDto
{
IsSuccess = true,
Message = "کد تایید با موفقیت تایید شد",
Token = "TODO_IMPLEMENT_JWT_GENERATION"
Token = token
};
}
}
@@ -14,9 +14,9 @@ public class GetJwtTokenQueryHandler : IRequestHandler<GetJwtTokenQuery, GetJwtT
{
var user = await _context.Users
.Include(u => u.UserContracts)
.ThenInclude(u => u.Contract)
.ThenInclude(uc => uc.Contract)
.Include(u => u.UserRoles)
.ThenInclude(ur => ur.Role)
.ThenInclude(ur => ur.Role)
.Include(u => u.ClubMembership)
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(User), request.Id);
return new GetJwtTokenResponseDto()
@@ -15,6 +15,8 @@ public class ContractConfiguration : IEntityTypeConfiguration<Contract>
builder.Property(entity => entity.Description).IsRequired(true);
builder.Property(entity => entity.HtmlContent).IsRequired(true);
builder.Property(entity => entity.Type).IsRequired(true);
// Map legacy Code column from database as shadow property (not used in C# code)
builder.Property<string>("Code").IsRequired(false);
}
}
@@ -13,6 +13,10 @@ public class OtpTokenConfiguration : IEntityTypeConfiguration<OtpToken>
builder.Property(entity => entity.Id).UseIdentityColumn();
builder.Property(entity => entity.Mobile).IsRequired(true);
builder.Property(entity => entity.Purpose).IsRequired(true);
// Code is not persisted to database, only used in-memory before hashing
builder.Ignore(entity => entity.Code);
builder.Property(entity => entity.CodeHash).IsRequired(true);
builder.Property(entity => entity.ExpiresAt).IsRequired(true);
builder.Property(entity => entity.Attempts).IsRequired(true);