Skip to content

Conversation

@taiphanvan2k3
Copy link
Member

@taiphanvan2k3 taiphanvan2k3 commented Nov 3, 2025

Summary by CodeRabbit

  • New Features

    • Implemented email verification workflow allowing users to verify their email address after registration.
    • Added email verification endpoint to authenticate verification requests.
    • Enhanced email system with customizable templates for verification, welcome, and password reset communications.
  • Chores

    • Updated development server configuration and endpoint settings.
    • Enabled static file serving for web assets.

@taiphanvan2k3 taiphanvan2k3 self-assigned this Nov 3, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 3, 2025

Walkthrough

The pull request implements email verification functionality by introducing new domain events, command handlers, services, and API endpoints. It refactors the email sending service to support multiple email types via templates and integrates token generation for email confirmation, while updating configuration for the development environment and restructuring email-related services.

Changes

Cohort / File(s) Summary
Configuration & Infrastructure Setup
.vscode/launch.json, src/Web.Api/Program.cs, src/Web.Api/appsettings.json, src/Web.Api/appsettings.Development.json, src/Infrastructure/Extensions/ServiceCollectionExtensions.cs, src/Infrastructure/Infrastructure.csproj
Updated dev server from multi-port HTTPS to single HTTP port (10000); registered HttpContextAccessor and static files middleware; added BaseUrl configuration for development and production; registered ITokenGenerationService, IEmailTemplateService, and IEmailTemplateService; configured template asset copying.
Domain Events
src/Domain/Events/User/EmailVerifiedEvent.cs, src/Domain/Events/User/UserCreatedEvent.cs, src/Domain/Events/User/UserDeactivatedEvent.cs, src/Domain/Events/User/UserUpdatedEvent.cs
Introduced new EmailVerifiedEvent domain event; extended UserCreatedEvent with IsEmailVerified property; removed UserDeactivatedEvent and UserUpdatedEvent.
Application Layer - Event Handlers
src/Application/EventHandlers/EmailVerifiedEventHandler.cs, src/Application/EventHandlers/UserCreatedEventHandler.cs
Renamed UserCreatedSendEmailEventHandler to EmailVerifiedEventHandler (now handles EmailVerifiedEvent); introduced new UserCreatedEventHandler to generate verification tokens and send verification emails on user creation.
Application Layer - Commands & Handlers
src/Application/Features/Auth/VerifyEmail/VerifyEmailCommand.cs, src/Application/Features/Auth/VerifyEmail/VerifyEmailCommandHandler.cs
Added VerifyEmailCommand for email verification requests; introduced VerifyEmailCommandHandler to validate tokens, mark emails verified, and raise EmailVerifiedEvent.
Application Layer - Service Interfaces
src/Application/Interfaces/IEmailService.cs, src/Application/Interfaces/IEmailTemplateService.cs, src/Application/Interfaces/ITokenGenerationService.cs, src/Application/Interfaces/IUserRepository.cs
Extended IEmailService with SendEmailVerificationAsync method; introduced IEmailTemplateService for template generation; introduced ITokenGenerationService for token management; extended IUserRepository with VerifyEmailAsync and IsEmailVerifiedAsync.
Infrastructure Services - Email
src/Infrastructure/Services/Email/EmailService.cs, src/Infrastructure/Services/Email/EmailTemplateService.cs, src/Infrastructure/Services/EmailService.cs
Relocated and refactored EmailService to Email subfolder with template service integration and support for multiple email types; introduced EmailTemplateService for HTML template generation with placeholder replacement; removed legacy EmailService.
Infrastructure Services - Token & Repository
src/Infrastructure/Services/TokenGenerationService.cs, src/Infrastructure/Repositories/UserRepository.cs
Introduced TokenGenerationService delegating to ASP.NET Identity for token generation and validation; extended UserRepository with email verification methods and UserManager integration.
Email Templates
src/Infrastructure/Templates/Email/EmailVerificationEmail.html, src/Infrastructure/Templates/Email/PasswordResetEmail.html, src/Infrastructure/Templates/Email/WelcomeEmail.html
Added three responsive HTML email templates with placeholder support for welcome, password reset, and email verification communications.
API Layer
src/Web.Api/Controllers/V1/AuthController.cs
Added VerifyEmail endpoint accepting userId and token as query parameters, dispatching VerifyEmailCommand via mediator.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant API as AuthController
    participant Mediator
    participant CreateHandler as UserCreatedEventHandler
    participant TokenService as TokenGenerationService
    participant EmailService
    participant Repository as UserRepository
    participant VerifyHandler as VerifyEmailCommandHandler

    User->>API: POST /register (email, password)
    API->>Mediator: Dispatch RegisterCommand
    Mediator->>CreateHandler: User created
    CreateHandler->>TokenService: GenerateEmailConfirmationTokenAsync
    TokenService-->>CreateHandler: token
    CreateHandler->>EmailService: SendEmailVerificationAsync(email, token)
    EmailService-->>CreateHandler: ✓ sent
    CreateHandler-->>API: registration complete

    User->>API: GET /verify-email?userId=X&token=Y
    API->>Mediator: Dispatch VerifyEmailCommand
    Mediator->>VerifyHandler: Handle verification
    VerifyHandler->>TokenService: ConfirmEmailAsync(userId, token)
    TokenService-->>VerifyHandler: true/false
    alt Token valid
        VerifyHandler->>Repository: VerifyEmailAsync(userId)
        Repository-->>VerifyHandler: ✓ verified
        VerifyHandler->>Mediator: Raise EmailVerifiedEvent
        Mediator->>EmailVerifiedEventHandler: Email verified
        EmailVerifiedEventHandler->>EmailService: SendWelcomeEmailAsync
        EmailService-->>EmailVerifiedEventHandler: ✓ sent
        VerifyHandler-->>API: 200 Success
    else Token invalid
        VerifyHandler-->>API: 400 Invalid token
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Areas requiring extra attention:

  • Token Generation & Validation Logic (src/Infrastructure/Services/TokenGenerationService.cs, src/Application/Features/Auth/VerifyEmail/VerifyEmailCommandHandler.cs) — Verify correct ASP.NET Identity token handling and edge cases (expired tokens, already-verified users).
  • Email Service Refactoring (src/Infrastructure/Services/Email/*) — Ensure template loading, placeholder replacement, and SMTP configuration work correctly across all email types; verify error handling preserves non-blocking behavior.
  • Event Handler Coordination (src/Application/EventHandlers/*) — Confirm UserCreatedEventHandler and EmailVerifiedEventHandler execute in correct sequence and handle failures gracefully without breaking registration flow.
  • UserRepository Integration (src/Infrastructure/Repositories/UserRepository.cs) — Validate UserManager constructor injection and email verification state updates are correctly persisted.
  • Configuration & Middleware (src/Web.Api/Program.cs, appsettings*.json) — Check that BaseUrl configuration is accessible to template service and static file paths are correctly served.

🐰 A verification quest, so bright and true,
With tokens, templates, and emails anew,
Where users confirm with a click and a cheer,
The welcome dance draws ever near!


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Free

📥 Commits

Reviewing files that changed from the base of the PR and between 948e24f and 081d3f8.

⛔ Files ignored due to path filters (1)
  • src/Web.Api/wwwroot/images/email/logo.png is excluded by !**/*.png
📒 Files selected for processing (27)
  • .vscode/launch.json (1 hunks)
  • src/Application/EventHandlers/EmailVerifiedEventHandler.cs (1 hunks)
  • src/Application/EventHandlers/UserCreatedEventHandler.cs (1 hunks)
  • src/Application/Features/Auth/VerifyEmail/VerifyEmailCommand.cs (1 hunks)
  • src/Application/Features/Auth/VerifyEmail/VerifyEmailCommandHandler.cs (1 hunks)
  • src/Application/Interfaces/IEmailService.cs (1 hunks)
  • src/Application/Interfaces/IEmailTemplateService.cs (1 hunks)
  • src/Application/Interfaces/ITokenGenerationService.cs (1 hunks)
  • src/Application/Interfaces/IUserRepository.cs (1 hunks)
  • src/Domain/Events/User/EmailVerifiedEvent.cs (1 hunks)
  • src/Domain/Events/User/UserCreatedEvent.cs (1 hunks)
  • src/Domain/Events/User/UserDeactivatedEvent.cs (0 hunks)
  • src/Domain/Events/User/UserUpdatedEvent.cs (0 hunks)
  • src/Infrastructure/Extensions/ServiceCollectionExtensions.cs (2 hunks)
  • src/Infrastructure/Infrastructure.csproj (1 hunks)
  • src/Infrastructure/Repositories/UserRepository.cs (3 hunks)
  • src/Infrastructure/Services/Email/EmailService.cs (1 hunks)
  • src/Infrastructure/Services/Email/EmailTemplateService.cs (1 hunks)
  • src/Infrastructure/Services/EmailService.cs (0 hunks)
  • src/Infrastructure/Services/TokenGenerationService.cs (1 hunks)
  • src/Infrastructure/Templates/Email/EmailVerificationEmail.html (1 hunks)
  • src/Infrastructure/Templates/Email/PasswordResetEmail.html (1 hunks)
  • src/Infrastructure/Templates/Email/WelcomeEmail.html (1 hunks)
  • src/Web.Api/Controllers/V1/AuthController.cs (2 hunks)
  • src/Web.Api/Program.cs (2 hunks)
  • src/Web.Api/appsettings.Development.json (1 hunks)
  • src/Web.Api/appsettings.json (1 hunks)
💤 Files with no reviewable changes (3)
  • src/Domain/Events/User/UserUpdatedEvent.cs
  • src/Domain/Events/User/UserDeactivatedEvent.cs
  • src/Infrastructure/Services/EmailService.cs

Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands and usage tips.

@taiphanvan2k3 taiphanvan2k3 merged commit dc6ab4c into main Nov 3, 2025
2 checks passed
@taiphanvan2k3 taiphanvan2k3 deleted the feat/implement-verify-email branch November 3, 2025 16:42
taiphanvan2k3 added a commit that referenced this pull request Dec 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants