Conditions | 4 |
Paths | 4 |
Total Lines | 62 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php declare(strict_types=1); |
||
141 | public function doResetAccount(array $data, Form $form): HTTPResponse |
||
142 | { |
||
143 | $memberID = $this->owner->getRequest()->getSession()->get('MemberID'); |
||
144 | |||
145 | // If the ID isn't in the session, politely assume the session has expired |
||
146 | if (!$memberID) { |
||
147 | $form->sessionMessage( |
||
148 | _t( |
||
149 | __CLASS__ . '.RESETTIMEDOUT', |
||
150 | "The account reset process timed out. Please click the link in the email and try again." |
||
151 | ), |
||
152 | ValidationResult::TYPE_ERROR |
||
153 | ); |
||
154 | |||
155 | return $this->owner->redirectBack(); |
||
156 | } |
||
157 | |||
158 | /** @var Member&MemberExtension $member */ |
||
159 | $member = Member::get()->byID((int) $memberID); |
||
160 | |||
161 | // Fail if passwords do not match |
||
162 | if ($data['NewPassword1'] !== $data['NewPassword2']) { |
||
163 | $form->sessionMessage( |
||
164 | _t( |
||
165 | 'SilverStripe\\Security\\Member.ERRORNEWPASSWORD', |
||
166 | 'You have entered your new password differently, try again' |
||
167 | ), |
||
168 | ValidationResult::TYPE_ERROR |
||
169 | ); |
||
170 | |||
171 | return $this->owner->redirectBack(); |
||
172 | } |
||
173 | |||
174 | // Check if the new password is accepted |
||
175 | $validationResult = $member->changePassword($data['NewPassword1']); |
||
176 | if (!$validationResult->isValid()) { |
||
177 | $form->setSessionValidationResult($validationResult); |
||
178 | |||
179 | return $this->owner->redirectBack(); |
||
180 | } |
||
181 | |||
182 | // Clear locked out status |
||
183 | $member->LockedOutUntil = null; |
||
184 | $member->FailedLoginCount = null; |
||
185 | |||
186 | // Clear account reset data |
||
187 | $member->AccountResetHash = null; |
||
188 | $member->AccountResetExpired = DBDatetime::create()->now(); |
||
189 | $member->write(); |
||
190 | |||
191 | // Pass off to extensions to perform any additional reset actions |
||
192 | $this->extend('handleAccountReset', $member); |
||
193 | |||
194 | // Send the user along to the login form (allowing any additional factors to kick in as needed) |
||
195 | $this->owner->setSessionMessage( |
||
196 | _t( |
||
197 | __CLASS__ . '.RESETSUCCESSMESSAGE', |
||
198 | 'Reset complete. Please log in with your new password.' |
||
199 | ), |
||
200 | ValidationResult::TYPE_GOOD |
||
201 | ); |
||
202 | return $this->owner->redirect($this->owner->Link('login')); |
||
203 | } |
||
205 |