mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
MINOR Separate some areas of logic in LostPasswordHandler to make them more overridable
This commit is contained in:
parent
168db412de
commit
6044579a3f
@ -283,7 +283,10 @@ class ChangePasswordHandler extends RequestHandler
|
|||||||
|
|
||||||
// Redirect to backurl
|
// Redirect to backurl
|
||||||
$backURL = $this->getBackURL();
|
$backURL = $this->getBackURL();
|
||||||
if ($backURL) {
|
if ($backURL
|
||||||
|
// Don't redirect back to itself
|
||||||
|
&& $backURL !== Security::singleton()->Link('changepassword')
|
||||||
|
) {
|
||||||
return $this->redirect($backURL);
|
return $this->redirect($backURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,23 +165,14 @@ class LostPasswordHandler extends RequestHandler
|
|||||||
*/
|
*/
|
||||||
public function forgotPassword($data, $form)
|
public function forgotPassword($data, $form)
|
||||||
{
|
{
|
||||||
// Ensure password is given
|
// Run a first pass validation check on the data
|
||||||
if (empty($data['Email'])) {
|
$dataValidation = $this->validateForgotPasswordData($data, $form);
|
||||||
$form->sessionMessage(
|
if ($dataValidation instanceof HTTPResponse) {
|
||||||
_t(
|
return $dataValidation;
|
||||||
'SilverStripe\\Security\\Member.ENTEREMAIL',
|
|
||||||
'Please enter an email address to get a password reset link.'
|
|
||||||
),
|
|
||||||
'bad'
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this->redirectToLostPassword();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find existing member
|
|
||||||
$field = Member::config()->get('unique_identifier_field');
|
|
||||||
/** @var Member $member */
|
/** @var Member $member */
|
||||||
$member = Member::get()->filter([$field => $data['Email']])->first();
|
$member = $this->getMemberFromData($data);
|
||||||
|
|
||||||
// Allow vetoing forgot password requests
|
// Allow vetoing forgot password requests
|
||||||
$results = $this->extend('forgotPassword', $member);
|
$results = $this->extend('forgotPassword', $member);
|
||||||
@ -195,15 +186,45 @@ class LostPasswordHandler extends RequestHandler
|
|||||||
$this->sendEmail($member, $token);
|
$this->sendEmail($member, $token);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Avoid information disclosure by displaying the same status,
|
return $this->redirectToSuccess($data);
|
||||||
// regardless wether the email address actually exists
|
}
|
||||||
$link = Controller::join_links(
|
|
||||||
$this->link('passwordsent'),
|
|
||||||
rawurlencode($data['Email']),
|
|
||||||
'/'
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this->redirect($this->addBackURLParam($link));
|
/**
|
||||||
|
* Ensure that the user has provided an email address. Note that the "Email" key is specific to this
|
||||||
|
* implementation, but child classes can override this method to use another unique identifier field
|
||||||
|
* for validation.
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
* @param LostPasswordForm $form
|
||||||
|
* @return HTTPResponse|null
|
||||||
|
*/
|
||||||
|
protected function validateForgotPasswordData(array $data, LostPasswordForm $form)
|
||||||
|
{
|
||||||
|
if (empty($data['Email'])) {
|
||||||
|
$form->sessionMessage(
|
||||||
|
_t(
|
||||||
|
'SilverStripe\\Security\\Member.ENTEREMAIL',
|
||||||
|
'Please enter an email address to get a password reset link.'
|
||||||
|
),
|
||||||
|
'bad'
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this->redirectToLostPassword();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load an existing Member from the provided data
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
* @return Member|null
|
||||||
|
*/
|
||||||
|
protected function getMemberFromData(array $data)
|
||||||
|
{
|
||||||
|
if (!empty($data['Email'])) {
|
||||||
|
$uniqueIdentifier = Member::config()->get('unique_identifier_field');
|
||||||
|
return Member::get()->filter([$uniqueIdentifier => $data['Email']])->first();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -227,4 +248,21 @@ class LostPasswordHandler extends RequestHandler
|
|||||||
->setTo($member->Email);
|
->setTo($member->Email);
|
||||||
return $email->send();
|
return $email->send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Avoid information disclosure by displaying the same status, regardless wether the email address actually exists
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
* @return HTTPResponse
|
||||||
|
*/
|
||||||
|
protected function redirectToSuccess(array $data)
|
||||||
|
{
|
||||||
|
$link = Controller::join_links(
|
||||||
|
$this->link('passwordsent'),
|
||||||
|
rawurlencode($data['Email']),
|
||||||
|
'/'
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this->redirect($this->addBackURLParam($link));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user