1

I have a front-end form to update user's email address, like this example:

<form method="post" accept-charset="UTF-8" enctype="multipart/form-data">
    {{ csrfInput() }}
    <input type="hidden" name="action" value="users/save-user">
    <input type="hidden" name="userId" value="{{ currentUser.id }}">

    <label for="newEmail">New email address</label>
    <input type="email" name="email" value="" id="newEmail">

    <label for="password">Password</label>
    <input type="password" name="password">

    <input type="submit">
</form>

Once the form is submitted, Craft send a system message to the user email address, with a confirmation link. Once this link is clicked, the user is redirected to the root URL of the front-end website.

I changed the activateAccountSuccessPath, but whereas it works during account activation, it doesn't works during account email update.

Example:

'activateAccountSuccessPath' => array(
    'en' => 'my-account',
    'fr' => 'mon-compte'
)

Or:

'activateAccountSuccessPath' => 'my-account'

I also tried to enable / disable the autoLoginAfterAccountActivation setting, but the redirection is still not working. Even is user is already logged in, or if he is logged out.

I also checked the Craft logs, but I there's no error, no missing template, etc. ... nothing.

How can I set a custom URI on this link?

1
+50

I can't think of a clean way to do this because of this function

public function actionVerifyEmail(): Response
{
    // ..
    // snip 
    // ..
    if (Craft::$app->getUsers()->verifyEmailForUser($userToProcess)) {
        // ..
        // snip
        // ..
        // Redirect to the site/CP root
        $url = UrlHelper::url('');  // <---- this is where we are
        return $this->redirect($url);  // ALWAYS redirect to root page
    }

    return $this->renderTemplate('_special/emailtaken', [
        'email' => $userToProcess->unverifiedEmail
    ]);
}

A clean way to achieve this is:

  1. Handle it entirely on your own -> custom controller + custom service, send the mail manually
  2. Create a custom route to you'll only take care about activating them and overwrite the actionVerifyEmail - unfortunately you can't replace the controller via Dependency Injection
  3. Create a feature request and hope Pixel and Tonic will be kind enough to create a config variable / event to overwrite this value
  • Thank you for these clarifications Robin. How would you handle the fact that this action would be exclusively for an update of the email and not for the first validation of the email (which works fine natively)? By checking if the user's status is STATUS_ACTIVE instead of STATUS_PENDING? – Romain Poirier Aug 7 '18 at 9:08
  • I would not check it at all and redirect the user wherever I like / wherever my clients wants them to redirect – Robin Schambach Aug 7 '18 at 10:44
  • To be more specific, I need to display a different alert message (by using a custom URI) on the landing page if the user has confirm his email after registration, and a different alert message (by using another custom URI) after the user has confirm his new email (after a profile update on front-end). So it matters to check the user status if it is a new user, or an already active user, to be able to adapt the confirm message of the alert. Do you think I would be able to do it by checking if STATUS_ACTIVE is true instead of STATUS_PENDING? – Romain Poirier Aug 7 '18 at 10:55
  • 1
    Why shouldn't you? But it would be way more cleaner to display a message depending on your session Flash rather than the url since a user would be able to see the message when he/she sends a link or reloads the page – Robin Schambach Aug 7 '18 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.