Skip to content

Commit

Permalink
Throw an exception if a user can't be created
Browse files Browse the repository at this point in the history
Resolves #16437
  • Loading branch information
brandonkelly committed Jan 15, 2025
1 parent 9f4b705 commit 3a6e3b9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- Fixed an error that could occur when setting `relatedTo*` GraphQL arguments to `null`. ([#16433](https://github.com/craftcms/cms/issues/16433))
- Fixed an error that occurred if a new user couldn’t be created due to validation errors. ([#16437](https://github.com/craftcms/cms/issues/16437))

## 5.5.10 - 2025-01-14

Expand Down
6 changes: 5 additions & 1 deletion src/controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1021,9 +1021,13 @@ public function actionCreate(): Response

$user->setScenario(Element::SCENARIO_ESSENTIALS);
if (!Craft::$app->getDrafts()->saveElementAsDraft($user, Craft::$app->getUser()->getId(), null, null, false)) {
return $this->asModelFailure($user, StringHelper::upperCaseFirst(Craft::t('app', 'Couldn’t create {type}.', [
$response = $this->asModelFailure($user, StringHelper::upperCaseFirst(Craft::t('app', 'Couldn’t create {type}.', [
'type' => User::lowerDisplayName(),
])), 'user');
if ($response === null) {
throw new InvalidElementException($user, sprintf('Couldn’t create user: %s', implode(', ', $user->getFirstErrors())));
}
return $response;
}

$editUrl = $user->getCpEditUrl();
Expand Down

0 comments on commit 3a6e3b9

Please sign in to comment.