Skip to content

Commit

Permalink
Merge pull request #13272 from craftcms/bugfix/13267-save-user-json-a…
Browse files Browse the repository at this point in the history
…s-model-success

save-user json success response to contain model data
  • Loading branch information
brandonkelly authored Jun 12, 2023
2 parents 31e28db + b90cf84 commit 40ada56
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Fixed a SQL error that could occur when upgrading to 4.4 on PostgreSQL, if the database was converted from MySQL. ([#12855](https://github.com/craftcms/cms/issues/12855))
- Fixed a bug where `craft\db\Query::collect()` was returning a `craft\elements\ElementCollection` instance.
- Fixed a SQL error that could occur when upgrading to Craft 4 if any database tables had foreign keys to `entryversions` or other now-unused tables that are removed during the upgrade.
- Fixed a bug where the `users/save-user` action wasn’t including user details in successful responses. ([#13267](https://github.com/craftcms/cms/issues/13267))

## 4.4.13 - 2023-05-24

Expand Down
19 changes: 11 additions & 8 deletions src/controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1561,14 +1561,17 @@ public function actionSaveUser(): ?Response
$returnCsrfToken = $returnCsrfToken || $loggedIn;

if ($this->request->getAcceptsJson()) {
$return = [
'id' => $user->id,
];
if ($returnCsrfToken && $generalConfig->enableCsrfProtection) {
$return['csrfTokenValue'] = $this->request->getCsrfToken();
}

return $this->asSuccess(data: $return);
return $this->asModelSuccess(
$user,
Craft::t('app', '{type} saved.', ['type' => User::displayName()]),
$userVariable,
array_filter([
'id' => $user->id, // todo: remove
'csrfTokenValue' => $returnCsrfToken && $generalConfig->enableCsrfProtection
? $this->request->getCsrfToken()
: null,
]),
);
}

if ($isPublicRegistration) {
Expand Down

0 comments on commit 40ada56

Please sign in to comment.