1

I have a front end user registration form, and I want users to receive a set password email after they've been activated manually in the back end by an admin. When they submit the user registration form, their account shouldn't be automatically activated, so I've checked the "verify email addresses" option in the user settings. However, with this setting enabled, a new user automatically receives an email to activate their account. Is there a way to prevent this account activation email from being sent when the user is first created in the system?

If I can prevent the initial account activation email from being sent, I can add a trigger to a custom module that sends the set password email after the user is activated by an admin, like so:

    Event::on(
        Users::class,
        Users::EVENT_AFTER_ACTIVATE_USER,
        function (Event $event) {
            $users = Craft::$app->getUsers();
            $users->sendActivationEmail($event->user);
        }
    );

This would allow me to have the set password email sent at the appropriate time.

In short, how can I have a front end registered user receive a set password email only after their account has been activated manually by an admin?

2 Answers 2

1

After a little more work, I came up with this approach that works-

First, I unchecked the verify email addresses option in the user settings.

Then, I added another trigger in my custom module- on before user save- that sets the new user's status to pending. The two triggers combined produce the functionality I'm looking for:

    Event::on(
        User::class,
        User::EVENT_BEFORE_SAVE,
        function (Event $event) {
            if($event->isNew) {
                $event->sender->pending = true;
            }
        }
    );

    Event::on(
        Users::class,
        Users::EVENT_AFTER_ACTIVATE_USER,
        function (Event $event) {
            $users = Craft::$app->getUsers();
            $users->sendActivationEmail($event->user);
        }
    );
1
1

This plugin does what you need i think (it did for me anyway - so i could have manual user approval) - https://concierge.olivierbon.com

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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