|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
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
|
|
|
namespace Derhansen\FeChangePwd\Controller; |
|
13
|
|
|
|
|
14
|
|
|
use Derhansen\FeChangePwd\Domain\Model\Dto\ChangePassword; |
|
15
|
|
|
use Derhansen\FeChangePwd\Event\AfterPasswordUpdatedEvent; |
|
16
|
|
|
use Derhansen\FeChangePwd\Service\FrontendUserService; |
|
17
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
18
|
|
|
use TYPO3\CMS\Extbase\Annotation as Extbase; |
|
19
|
|
|
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; |
|
20
|
|
|
use TYPO3\CMS\Extbase\Security\Exception\InvalidHashException; |
|
21
|
|
|
use TYPO3\CMS\Extbase\Utility\LocalizationUtility; |
|
22
|
|
|
use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Class PasswordController |
|
26
|
|
|
*/ |
|
27
|
|
|
class PasswordController extends ActionController |
|
28
|
|
|
{ |
|
29
|
|
|
protected FrontendUserService $frontendUserService; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param FrontendUserService $frontendUserService |
|
33
|
|
|
*/ |
|
34
|
|
|
public function injectFrontendUserService( |
|
35
|
|
|
FrontendUserService $frontendUserService |
|
36
|
|
|
) { |
|
37
|
|
|
$this->frontendUserService = $frontendUserService; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Edit action |
|
42
|
|
|
* |
|
43
|
|
|
* @return ResponseInterface |
|
44
|
|
|
*/ |
|
45
|
|
|
public function editAction(): ResponseInterface |
|
46
|
|
|
{ |
|
47
|
|
|
$changePassword = new ChangePassword(); |
|
48
|
|
|
$changePassword->setChangeHmac($this->frontendUserService->getChangeHmac()); |
|
49
|
|
|
$this->view->assignMultiple([ |
|
50
|
|
|
'changePasswordReason' => $this->frontendUserService->getMustChangePasswordReason(), |
|
51
|
|
|
'changePassword' => $changePassword |
|
52
|
|
|
]); |
|
53
|
|
|
|
|
54
|
|
|
return $this->htmlResponse(); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Ensure a valid changeHmac is provided |
|
59
|
|
|
* |
|
60
|
|
|
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException |
|
61
|
|
|
* @throws InvalidHashException |
|
62
|
|
|
*/ |
|
63
|
|
|
public function initializeUpdateAction() |
|
64
|
|
|
{ |
|
65
|
|
|
$changePasswordArray = $this->request->getArgument('changePassword'); |
|
66
|
|
|
$changeHmac = $changePasswordArray['changeHmac'] ? (string)$changePasswordArray['changeHmac'] : ''; |
|
67
|
|
|
if (!$this->frontendUserService->validateChangeHmac($changeHmac)) { |
|
68
|
|
|
throw new InvalidHashException( |
|
69
|
|
|
'Possible CSRF detected. Ensure a valid "changeHmac" is provided.', |
|
70
|
|
|
1572672118931 |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
$this->setFeUserPasswordHashToArguments($changePasswordArray); |
|
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Update action |
|
78
|
|
|
* |
|
79
|
|
|
* @param \Derhansen\FeChangePwd\Domain\Model\Dto\ChangePassword $changePassword |
|
80
|
|
|
* @return ResponseInterface |
|
81
|
|
|
* @Extbase\Validate(param="changePassword", validator="Derhansen\FeChangePwd\Validation\Validator\ChangePasswordValidator") |
|
82
|
|
|
*/ |
|
83
|
|
|
public function updateAction(ChangePassword $changePassword): ResponseInterface |
|
84
|
|
|
{ |
|
85
|
|
|
$this->frontendUserService->updatePassword($changePassword->getPassword1()); |
|
86
|
|
|
|
|
87
|
|
|
$this->eventDispatcher->dispatch(new AfterPasswordUpdatedEvent($changePassword, $this)); |
|
88
|
|
|
|
|
89
|
|
|
if (isset($this->settings['afterPasswordChangeAction']) && |
|
90
|
|
|
$this->settings['afterPasswordChangeAction'] === 'redirect') { |
|
91
|
|
|
$this->addFlashMessage( |
|
92
|
|
|
LocalizationUtility::translate('passwordUpdated', 'FeChangePwd'), |
|
93
|
|
|
LocalizationUtility::translate('passwordUpdated.title', 'FeChangePwd') |
|
94
|
|
|
); |
|
95
|
|
|
$this->redirect('edit'); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
return $this->htmlResponse(); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Sets the current fe_user password (hashed) to request argument "changePassword" |
|
103
|
|
|
* |
|
104
|
|
|
* @param array $changePasswordArray |
|
105
|
|
|
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException |
|
106
|
|
|
*/ |
|
107
|
|
|
protected function setFeUserPasswordHashToArguments(array $changePasswordArray): void |
|
108
|
|
|
{ |
|
109
|
|
|
$changePasswordArgument = $this->arguments->getArgument('changePassword'); |
|
110
|
|
|
$propertyMapping = $changePasswordArgument->getPropertyMappingConfiguration(); |
|
111
|
|
|
$propertyMapping->allowProperties('feUserPasswordHash'); |
|
112
|
|
|
|
|
113
|
|
|
$changePasswordArray['feUserPasswordHash'] = $this->getFrontendUser()->user['password']; |
|
114
|
|
|
$arguments = $this->request->getArguments(); |
|
115
|
|
|
$arguments['changePassword'] = $changePasswordArray; |
|
116
|
|
|
$this->request->setArguments($arguments); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Suppress default flash messages |
|
121
|
|
|
* |
|
122
|
|
|
* @return bool |
|
123
|
|
|
*/ |
|
124
|
|
|
protected function getErrorFlashMessage(): bool |
|
125
|
|
|
{ |
|
126
|
|
|
return false; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
protected function getFrontendUser(): FrontendUserAuthentication |
|
130
|
|
|
{ |
|
131
|
|
|
return $GLOBALS['TSFE']->fe_user; |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|