diff --git a/CHANGELOG-v3.md b/CHANGELOG-v3.md index ed7772c4cd5..8b22d1e1085 100644 --- a/CHANGELOG-v3.md +++ b/CHANGELOG-v3.md @@ -28,6 +28,7 @@ - Fixed an error that occurred if a Quick Post widget contained a Matrix field that had Min Blocks set and only had one block type. - Fixed a bug where the Plugin Store was not working properly with Internet Explorer. - Fixed a bug where disabled Matrix blocks were getting validated as live. ([#3354](https://github.com/craftcms/cms/issues/3354)) +- Fixed a bug where the `EVENT_AFTER_ACTIVATE_USER` event wasn’t getting triggered on user registration when email verification isn’t required. ([craftcms/commerce-digital-products#18](https://github.com/craftcms/commerce-digital-products/issues/18)) ### Security - The `svg()` Twig function no longer sanitizes SVGs or namespaces their IDs or class names by default when a file path (or alias) was passed in. ([#3337](https://github.com/craftcms/cms/issues/3337)) diff --git a/src/controllers/UsersController.php b/src/controllers/UsersController.php index 173a9225124..472d7b3a301 100644 --- a/src/controllers/UsersController.php +++ b/src/controllers/UsersController.php @@ -995,9 +995,9 @@ public function actionSaveUser() $user->firstName = $request->getBodyParam('firstName', $user->firstName); $user->lastName = $request->getBodyParam('lastName', $user->lastName); - // If email verification is required, then new users will be saved in a pending state, + // New users should always be initially saved in a pending state, // even if an admin is doing this and opted to not send the verification email - if ($isNewUser && $requireEmailVerification) { + if ($isNewUser) { $user->pending = true; } @@ -1062,6 +1062,12 @@ public function actionSaveUser() return null; } + // If this is a new user and email verification isn't required, + // go ahead and activate them now. + if ($isNewUser && !$requireEmailVerification) { + Craft::$app->getUsers()->activateUser($user); + } + // Save their preferences too $preferences = [ 'language' => $request->getBodyParam('preferredLanguage', $user->getPreference('language')),