Skip to content

Commit

Permalink
Allow front end users/upload-user-photo requests
Browse files Browse the repository at this point in the history
Resolves #3932
  • Loading branch information
brandonkelly committed May 14, 2019
1 parent 77a6280 commit 1bb9357
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Element URI formats can now conditionally output an empty string, opting the element out of getting its own system URI. ([#4254](https://github.com/craftcms/cms/issues/4254))
- Table fields now get validation errors if any column handles are entered in the format of “colX”.
- Craft no longer clear out users’ verification codes after login. ([#4257](https://github.com/craftcms/cms/issues/4257))
- The `users/upload-user-photo` action is now available to front-end requests. ([#3932](https://github.com/craftcms/cms/issues/3932))

### Fixed
- Fixed a bug where rebuilding the project config could set an incorrect value for the user field layout.
Expand Down
14 changes: 11 additions & 3 deletions src/controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1221,11 +1221,11 @@ public function actionSaveUser()
*/
public function actionUploadUserPhoto()
{
$this->requireCpRequest();
$this->requireAcceptsJson();
$this->requireLogin();

$userId = Craft::$app->getRequest()->getRequiredBodyParam('userId');
$request = Craft::$app->getRequest();
$userId = $request->getRequiredBodyParam('userId');

if ($userId != Craft::$app->getUser()->getIdentity()->id) {
$this->requirePermission('editUsers');
Expand All @@ -1248,10 +1248,18 @@ public function actionUploadUserPhoto()
move_uploaded_file($file->tempName, $fileLocation);
$users->saveUserPhoto($fileLocation, $user, $file->name);

$html = $this->getView()->renderTemplate('users/_photo', [
$view = $this->getView();
$templateMode = $view->getTemplateMode();
if ($templateMode === View::TEMPLATE_MODE_SITE && !$view->doesTemplateExist('users/_photo')) {
$view->setTemplateMode(View::TEMPLATE_MODE_CP);
}

$html = $view->renderTemplate('users/_photo', [
'user' => $user
]);

$view->setTemplateMode($templateMode);

return $this->asJson([
'html' => $html,
]);
Expand Down

0 comments on commit 1bb9357

Please sign in to comment.