/
UpdateAction.php
86 lines (67 loc) · 2.44 KB
/
UpdateAction.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
* @property ManipleUser_Form_Password $_form
*/
class ManipleUser_PasswordController_UpdateAction
extends Maniple_Controller_Action_StandaloneForm
{
protected $_actionControllerClass = ManipleUser_PasswordController::className;
protected $_ajaxFormHtml = true;
/**
* @Inject('user.sessionManager')
* @var Maniple_Security_ContextInterface
*/
protected $_securityContext;
/**
* @Inject
* @var ManipleUser_Service_UserManager
*/
protected $_userManager;
/**
* @Inject
* @var ManipleUser_Service_Password
*/
protected $_passwordService;
/**
* @return void
* @throws Maniple_Controller_Exception
*/
protected function _prepare()
{
if (!$this->_securityContext->isAuthenticated()) {
throw new Maniple_Controller_Exception_AuthenticationRequired($this->_request);
}
$user = $this->_userManager->getUser(
$this->_securityContext->getUser()->getId()
);
if (empty($user)) {
// unlikely to happen if user is authenticated
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);
}
protected function _process()
{
$userManager = $this->_userManager;
$password = $this->_passwordService->passwordHash($this->_form->getValue('password'));
$user = $this->_form->getUser();
$user->setPassword($password);
$userManager->saveUser($user);
$successMessage = $this->view->translate('Your password has been changed');
if ($this->isAjax()) {
$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($successMessage);
$config = $this->getResource('modules')->offsetGet('maniple-user')->getOptions();
$continue = isset($config['afterLoginRoute'])
? $this->view->url($config['afterLoginRoute'])
: $this->view->baseUrl('/');
return $continue;
}
}