I have the following code in my site module:
Event::on(
User::class,
User::EVENT_BEFORE_SAVE,
function (ModelEvent $event) {
/** @var User $user */
$user = $event->sender;
if ($event->isNew === true) {
$user->pending = true;
}
}
);
It was working as expected until I updated from Craft 3.0.25 to 3.0.27.1
I think this issue is related to a change in the src/controllers/UsersController.php
file as per GitHub https://github.com/craftcms/cms/commit/db089251994329d0fbe082c0d3ff234a01d82c98
Also, I replaced my 3.0.27.1 UsersController.php
with one from a 3.0.25 install, and my code works again.
What is the best/correct/official way to set new user accounts to pending status in a module that won't break with future Craft updates?
I tried this:
Event::on(
Users::class,
Users::EVENT_BEFORE_ACTIVATE_USER,
function (UserEvent $event) {
$event->isValid = false;
}
);
but got There was a problem activating the user.
when trying to activate the user account.
P.S: Verify email addresses?
is disabled in User Settings
.