2007-07-19 10:40:28 +00:00
|
|
|
<?php
|
2016-06-23 11:37:22 +12:00
|
|
|
|
2017-04-22 16:30:10 +12:00
|
|
|
namespace SilverStripe\Security\MemberAuthenticator;
|
2016-06-23 11:37:22 +12:00
|
|
|
|
2016-08-19 10:51:35 +12:00
|
|
|
use SilverStripe\Control\Session;
|
2017-03-02 15:24:38 +13:00
|
|
|
use SilverStripe\Control\RequestHandler;
|
2016-08-19 10:51:35 +12:00
|
|
|
use SilverStripe\Forms\FieldList;
|
|
|
|
use SilverStripe\Forms\FormField;
|
|
|
|
use SilverStripe\Forms\PasswordField;
|
|
|
|
use SilverStripe\Forms\FormAction;
|
|
|
|
use SilverStripe\Forms\HiddenField;
|
|
|
|
use SilverStripe\Forms\Form;
|
2017-05-20 16:32:25 +12:00
|
|
|
use SilverStripe\Security\Security;
|
2016-06-23 11:37:22 +12:00
|
|
|
|
2007-09-16 00:32:48 +00:00
|
|
|
/**
|
|
|
|
* Standard Change Password Form
|
|
|
|
*/
|
2016-11-29 12:31:16 +13:00
|
|
|
class ChangePasswordForm extends Form
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
2017-03-02 15:24:38 +13:00
|
|
|
* @param RequestHandler $controller The parent controller, necessary to create the appropriate form action tag.
|
2016-11-29 12:31:16 +13:00
|
|
|
* @param string $name The method on the controller that will return this form object.
|
|
|
|
* @param FieldList|FormField $fields All of the fields in the form - a {@link FieldList} of
|
|
|
|
* {@link FormField} objects.
|
|
|
|
* @param FieldList|FormAction $actions All of the action buttons in the form - a {@link FieldList} of
|
|
|
|
*/
|
|
|
|
public function __construct($controller, $name, $fields = null, $actions = null)
|
|
|
|
{
|
2017-03-02 15:24:38 +13:00
|
|
|
$backURL = $controller->getBackURL() ?: Session::get('BackURL');
|
2016-11-29 12:31:16 +13:00
|
|
|
|
|
|
|
if (!$fields) {
|
|
|
|
$fields = new FieldList();
|
|
|
|
|
|
|
|
// Security/changepassword?h=XXX redirects to Security/changepassword
|
|
|
|
// without GET parameter to avoid potential HTTP referer leakage.
|
|
|
|
// In this case, a user is not logged in, and no 'old password' should be necessary.
|
2017-05-20 16:32:25 +12:00
|
|
|
if (Security::getCurrentUser()) {
|
2017-04-20 13:15:24 +12:00
|
|
|
$fields->push(new PasswordField("OldPassword", _t('SilverStripe\\Security\\Member.YOUROLDPASSWORD', "Your old password")));
|
2016-11-29 12:31:16 +13:00
|
|
|
}
|
|
|
|
|
2017-04-20 13:15:24 +12:00
|
|
|
$fields->push(new PasswordField("NewPassword1", _t('SilverStripe\\Security\\Member.NEWPASSWORD', "New Password")));
|
|
|
|
$fields->push(new PasswordField("NewPassword2", _t('SilverStripe\\Security\\Member.CONFIRMNEWPASSWORD', "Confirm New Password")));
|
2016-11-29 12:31:16 +13:00
|
|
|
}
|
|
|
|
if (!$actions) {
|
|
|
|
$actions = new FieldList(
|
2017-04-20 13:15:24 +12:00
|
|
|
new FormAction("doChangePassword", _t('SilverStripe\\Security\\Member.BUTTONCHANGEPASSWORD', "Change Password"))
|
2016-11-29 12:31:16 +13:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-03-02 15:24:38 +13:00
|
|
|
if ($backURL) {
|
|
|
|
$fields->push(new HiddenField('BackURL', false, $backURL));
|
2016-11-29 12:31:16 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
parent::__construct($controller, $name, $fields, $actions);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-03-02 15:24:38 +13:00
|
|
|
* @return ChangePasswordHandler
|
2016-11-29 12:31:16 +13:00
|
|
|
*/
|
2017-03-02 15:24:38 +13:00
|
|
|
protected function buildRequestHandler()
|
2016-11-29 12:31:16 +13:00
|
|
|
{
|
2017-03-02 15:24:38 +13:00
|
|
|
return ChangePasswordHandler::create($this);
|
2016-11-29 12:31:16 +13:00
|
|
|
}
|
2007-07-19 10:40:28 +00:00
|
|
|
}
|