2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
2016-06-23 01:37:22 +02:00
|
|
|
|
|
|
|
namespace SilverStripe\Security;
|
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Control\Session;
|
2017-03-02 03:24:38 +01:00
|
|
|
use SilverStripe\Control\RequestHandler;
|
2016-08-19 00:51:35 +02: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;
|
2016-06-23 01:37:22 +02:00
|
|
|
|
2007-09-16 02:32:48 +02:00
|
|
|
/**
|
|
|
|
* Standard Change Password Form
|
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
class ChangePasswordForm extends Form
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
2017-03-02 03:24:38 +01:00
|
|
|
* @param RequestHandler $controller The parent controller, necessary to create the appropriate form action tag.
|
2016-11-29 00:31:16 +01: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 03:24:38 +01:00
|
|
|
$backURL = $controller->getBackURL() ?: Session::get('BackURL');
|
2016-11-29 00:31:16 +01: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.
|
|
|
|
if (Member::currentUser()) {
|
|
|
|
$fields->push(new PasswordField("OldPassword", _t('Member.YOUROLDPASSWORD', "Your old password")));
|
|
|
|
}
|
|
|
|
|
|
|
|
$fields->push(new PasswordField("NewPassword1", _t('Member.NEWPASSWORD', "New Password")));
|
|
|
|
$fields->push(new PasswordField("NewPassword2", _t('Member.CONFIRMNEWPASSWORD', "Confirm New Password")));
|
|
|
|
}
|
|
|
|
if (!$actions) {
|
|
|
|
$actions = new FieldList(
|
|
|
|
new FormAction("doChangePassword", _t('Member.BUTTONCHANGEPASSWORD', "Change Password"))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-03-02 03:24:38 +01:00
|
|
|
if ($backURL) {
|
|
|
|
$fields->push(new HiddenField('BackURL', false, $backURL));
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
parent::__construct($controller, $name, $fields, $actions);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-03-02 03:24:38 +01:00
|
|
|
* @return ChangePasswordHandler
|
2016-11-29 00:31:16 +01:00
|
|
|
*/
|
2017-03-02 03:24:38 +01:00
|
|
|
protected function buildRequestHandler()
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-03-02 03:24:38 +01:00
|
|
|
return ChangePasswordHandler::create($this);
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|