Skip to content

Commit

Permalink
Add ability to control ajax response format via request param
Browse files Browse the repository at this point in the history
  • Loading branch information
xemlock committed Mar 16, 2020
1 parent 6154505 commit 0accb15
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions controllers/PasswordController/UpdateAction.php
Expand Up @@ -47,6 +47,7 @@ protected function _prepare()
throw new Maniple_Controller_Exception_NotFound('User was not found');
}

$this->_ajaxFormHtml = $this->getScalarParam('ajaxFormHtml', $this->_ajaxFormHtml);
$this->_form = new ManipleUser_Form_Password($this->_passwordService, $user);
}

Expand All @@ -60,17 +61,20 @@ protected function _process()

$userManager->saveUser($user);

$successMessage = $this->view->translate('Your password has been changed');

if ($this->isAjax()) {
$this->view->success = $this->view->translate('Your password has been changed');
$this->_helper->json(array(
'data' => array(
'html' => $this->renderForm()
),
));
$this->view->success = $successMessage;

$ajaxResponse = $this->getAjaxResponse();
$ajaxResponse->setSuccess($successMessage);
$ajaxResponse->setData($this->_ajaxFormHtml ? $this->renderForm() : null);
$ajaxResponse->sendAndExit();

return false;
}

$this->_helper->flashMessenger->addSuccessMessage($this->view->translate('Your password has been changed'));
$this->_helper->flashMessenger->addSuccessMessage($successMessage);

$config = $this->getResource('modules')->offsetGet('maniple-user')->getOptions();
$continue = isset($config['afterLoginRoute'])
Expand Down

0 comments on commit 0accb15

Please sign in to comment.