Skip to content

Commit

Permalink
Fixed #3206
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Aug 16, 2018
1 parent d5ca010 commit 1167d28
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

### Fixed
- Fixed a SQL error that occurred when saving a user if a `craft\elements\User::EVENT_BEFORE_SAVE` event listener was setting `$event->isValid = false`. ([#3206](https://github.com/craftcms/cms/issues/3206))

### Security
- External links in the Control Panel now set `rel="noopener"`. ([#3201](https://github.com/craftcms/cms/issues/3201))

Expand Down
9 changes: 5 additions & 4 deletions src/controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,11 @@ public function actionSaveUser()
$user->setScenario(Element::SCENARIO_LIVE);
}

if (!$user->validate(null, false)) {
// Manually validate the user so we can pass $clearErrors=false
if (
!$user->validate(null, false) ||
!Craft::$app->getElements()->saveElement($user, false)
) {
Craft::info('User not saved due to validation error.', __METHOD__);

if ($thisIsPublicRegistration) {
Expand All @@ -1059,9 +1063,6 @@ public function actionSaveUser()
return null;
}

// Save the user (but no need to re-validate)
Craft::$app->getElements()->saveElement($user, false);

// Save their preferences too
$preferences = [
'language' => $request->getBodyParam('preferredLanguage', $user->getPreference('language')),
Expand Down

0 comments on commit 1167d28

Please sign in to comment.