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
|
|
|
|
2017-03-02 15:24:38 +13:00
|
|
|
use SilverStripe\Control\RequestHandler;
|
2017-06-09 15:07:35 +12:00
|
|
|
use SilverStripe\Control\Session;
|
2016-08-19 10:51:35 +12:00
|
|
|
use SilverStripe\Forms\FieldList;
|
2017-06-09 15:07:35 +12:00
|
|
|
use SilverStripe\Forms\Form;
|
2016-08-19 10:51:35 +12:00
|
|
|
use SilverStripe\Forms\FormAction;
|
2017-06-09 15:07:35 +12:00
|
|
|
use SilverStripe\Forms\FormField;
|
2016-08-19 10:51:35 +12:00
|
|
|
use SilverStripe\Forms\HiddenField;
|
2017-06-09 15:07:35 +12:00
|
|
|
use SilverStripe\Forms\PasswordField;
|
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) {
|
2017-05-30 19:42:00 +12:00
|
|
|
$fields = $this->getFormFields();
|
2016-11-29 12:31:16 +13:00
|
|
|
}
|
|
|
|
if (!$actions) {
|
2017-05-30 19:42:00 +12:00
|
|
|
$actions = $this->getFormActions();
|
2016-11-29 12:31:16 +13:00
|
|
|
}
|
|
|
|
|
2017-03-02 15:24:38 +13:00
|
|
|
if ($backURL) {
|
2017-05-30 19:42:00 +12:00
|
|
|
$fields->push(HiddenField::create('BackURL', false, $backURL));
|
2016-11-29 12:31:16 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
parent::__construct($controller, $name, $fields, $actions);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-05-30 19:42:00 +12:00
|
|
|
* @return FieldList
|
|
|
|
*/
|
|
|
|
protected function getFormFields()
|
|
|
|
{
|
|
|
|
$fields = FieldList::create();
|
|
|
|
|
|
|
|
// 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 (Security::getCurrentUser()) {
|
|
|
|
$fields->push(PasswordField::create('OldPassword', _t('SilverStripe\\Security\\Member.YOUROLDPASSWORD', 'Your old password')));
|
|
|
|
}
|
|
|
|
|
|
|
|
$fields->push(PasswordField::create('NewPassword1', _t('SilverStripe\\Security\\Member.NEWPASSWORD', 'New Password')));
|
|
|
|
$fields->push(PasswordField::create('NewPassword2', _t('SilverStripe\\Security\\Member.CONFIRMNEWPASSWORD', 'Confirm New Password')));
|
|
|
|
|
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return FieldList
|
2016-11-29 12:31:16 +13:00
|
|
|
*/
|
2017-05-30 19:42:00 +12:00
|
|
|
protected function getFormActions()
|
2016-11-29 12:31:16 +13:00
|
|
|
{
|
2017-05-30 19:42:00 +12:00
|
|
|
$actions = FieldList::create(
|
|
|
|
FormAction::create(
|
|
|
|
'doChangePassword',
|
|
|
|
_t('SilverStripe\\Security\\Member.BUTTONCHANGEPASSWORD', 'Change Password')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
return $actions;
|
2016-11-29 12:31:16 +13:00
|
|
|
}
|
2007-07-19 10:40:28 +00:00
|
|
|
}
|