|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
namespace Derhansen\FeChangePwd\Controller; |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Extension "fe_change_pwd" for TYPO3 CMS. |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please read the |
|
9
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
use Derhansen\FeChangePwd\Domain\Model\Dto\ChangePassword; |
|
13
|
|
|
use Derhansen\FeChangePwd\Service\FrontendUserService; |
|
14
|
|
|
use TYPO3\CMS\Extbase\Utility\LocalizationUtility; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class PasswordController |
|
18
|
|
|
*/ |
|
19
|
|
|
class PasswordController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var FrontendUserService |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $frontendUserService = null; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @param FrontendUserService $frontendUserService |
|
28
|
|
|
*/ |
|
29
|
|
|
public function injectFrontendUserService( |
|
30
|
|
|
\Derhansen\FeChangePwd\Service\FrontendUserService $frontendUserService |
|
31
|
|
|
) { |
|
32
|
|
|
$this->frontendUserService = $frontendUserService; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Edit action |
|
37
|
|
|
* |
|
38
|
|
|
* @return void |
|
39
|
|
|
*/ |
|
40
|
|
|
public function editAction() |
|
41
|
|
|
{ |
|
42
|
|
|
$changePassword = $this->objectManager->get(ChangePassword::class); |
|
43
|
|
|
$changePassword->setChangeHmac($this->frontendUserService->getChangeHmac()); |
|
44
|
|
|
$this->view->assignMultiple([ |
|
45
|
|
|
'changePasswordReason' => $this->frontendUserService->getMustChangePasswordReason(), |
|
46
|
|
|
'changePassword' => $changePassword |
|
47
|
|
|
]); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Ensure a valid changeHmac is provided |
|
52
|
|
|
* |
|
53
|
|
|
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException |
|
54
|
|
|
* @throws \TYPO3\CMS\Extbase\Security\Exception\InvalidHashException |
|
55
|
|
|
*/ |
|
56
|
|
|
public function initializeUpdateAction() |
|
57
|
|
|
{ |
|
58
|
|
|
$changePasswordArray = $this->request->getArgument('changePassword'); |
|
59
|
|
|
$changeHmac = $changePasswordArray['changeHmac'] ? (string)$changePasswordArray['changeHmac'] : ''; |
|
60
|
|
|
if (!$this->frontendUserService->validateChangeHmac($changeHmac)) { |
|
61
|
|
|
throw new \TYPO3\CMS\Extbase\Security\Exception\InvalidHashException( |
|
62
|
|
|
'Possible CSRF detected. Ensure a valid "changeHmac" is provided.', |
|
63
|
|
|
1572672118931 |
|
64
|
|
|
); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Update action |
|
70
|
|
|
* |
|
71
|
|
|
* @param \Derhansen\FeChangePwd\Domain\Model\Dto\ChangePassword $changePassword |
|
72
|
|
|
* @validate $changePassword \Derhansen\FeChangePwd\Validation\Validator\ChangePasswordValidator |
|
73
|
|
|
* |
|
74
|
|
|
* @return void |
|
75
|
|
|
*/ |
|
76
|
|
|
public function updateAction(ChangePassword $changePassword) |
|
77
|
|
|
{ |
|
78
|
|
|
$this->frontendUserService->updatePassword($changePassword->getPassword1()); |
|
79
|
|
|
if (isset($this->settings['afterPasswordChangeAction']) && |
|
80
|
|
|
$this->settings['afterPasswordChangeAction'] === 'redirect') { |
|
81
|
|
|
$this->addFlashMessage( |
|
82
|
|
|
LocalizationUtility::translate('passwordUpdated', 'fe_change_pwd'), |
|
83
|
|
|
LocalizationUtility::translate('passwordUpdated.title', 'fe_change_pwd') |
|
84
|
|
|
); |
|
85
|
|
|
$this->redirect('edit'); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Suppress default flash messages |
|
91
|
|
|
* |
|
92
|
|
|
* @return bool |
|
93
|
|
|
*/ |
|
94
|
|
|
protected function getErrorFlashMessage() |
|
95
|
|
|
{ |
|
96
|
|
|
return false; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|