silverstripe-framework/src/Security/ChangePasswordForm.php

66 lines
2.3 KiB
PHP
Raw Normal View History

<?php
2016-06-23 01:37:22 +02:00
namespace SilverStripe\Security;
use SilverStripe\Control\Session;
use SilverStripe\Control\RequestHandler;
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
/**
* Standard Change Password Form
*/
2016-11-29 00:31:16 +01:00
class ChangePasswordForm extends Form
{
/**
* Constructor
*
* @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)
{
$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"))
);
}
if ($backURL) {
$fields->push(new HiddenField('BackURL', false, $backURL));
2016-11-29 00:31:16 +01:00
}
parent::__construct($controller, $name, $fields, $actions);
}
/**
* @return ChangePasswordHandler
2016-11-29 00:31:16 +01:00
*/
protected function buildRequestHandler()
2016-11-29 00:31:16 +01:00
{
return ChangePasswordHandler::create($this);
2016-11-29 00:31:16 +01:00
}
}