Create service for email verification

Created on 27 March 2025, 22 days ago

Problem/Motivation

The Verify Email module will need to generate login links, format and send verification emails, confirm and log in existing users, create accounts for new users, redirect to destination.

This functionality will need to be accessed from forms, controllers, and hooks.

To keep the module functionality reasonably self contained and understandable, it should be wrapped up in a service.

Proposed resolution

Create a service with the following functionality:

  1. Function to generate verification email
    • If user exists for email address, generate a login link with user_pass_reset_url. Append ?verify=$entityId to allow password reset to be intercepted
    • If user doesn't exist, hash the email address into a link
    • Generate an email message with the subject and body from entity
    • For now, I think it will be fine to just append the link below the message body, but a future enhancement would be to tie into the Drupal token system.
  2. Function to be called from hook to check for ?verify URL parameter. It should redirect to the redirect_path of the entity
  3. Function to be called from the controller for create user link. It should unhash the email address, check a user hasn't already been created for that email address, create a new user, using the email address as the username, and log the new user in.

Remaining tasks

Create the service
I suggest this issue be limited to the creation of the service. Calling it from other parts of the module should be reserved for follow up tasks.
Tests should be created for as much of the service's functionality as possibility.

User interface changes

None

API changes

None

Data model changes

None

📌 Task
Status

Active

Version

1.0

Component

Code

Created by

🇮🇪Ireland lostcarpark

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024