|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\Security\MemberAuthenticator; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Control\RequestHandler; |
|
6
|
|
|
use SilverStripe\Control\Session; |
|
7
|
|
|
use SilverStripe\Forms\FieldList; |
|
8
|
|
|
use SilverStripe\Forms\Form; |
|
9
|
|
|
use SilverStripe\Forms\FormAction; |
|
10
|
|
|
use SilverStripe\Forms\FormField; |
|
11
|
|
|
use SilverStripe\Forms\HiddenField; |
|
12
|
|
|
use SilverStripe\Forms\PasswordField; |
|
13
|
|
|
use SilverStripe\Security\Security; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Standard Change Password Form |
|
17
|
|
|
*/ |
|
18
|
|
|
class ChangePasswordForm extends Form |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* Constructor |
|
22
|
|
|
* |
|
23
|
|
|
* @param RequestHandler $controller The parent controller, necessary to create the appropriate form action tag. |
|
24
|
|
|
* @param string $name The method on the controller that will return this form object. |
|
25
|
|
|
* @param FieldList|FormField $fields All of the fields in the form - a {@link FieldList} of |
|
26
|
|
|
* {@link FormField} objects. |
|
27
|
|
|
* @param FieldList|FormAction $actions All of the action buttons in the form - a {@link FieldList} of |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct($controller, $name, $fields = null, $actions = null) |
|
30
|
|
|
{ |
|
31
|
|
|
$backURL = $controller->getBackURL() ?: Session::get('BackURL'); |
|
32
|
|
|
|
|
33
|
|
|
if (!$fields) { |
|
34
|
|
|
$fields = $this->getFormFields(); |
|
35
|
|
|
} |
|
36
|
|
|
if (!$actions) { |
|
37
|
|
|
$actions = $this->getFormActions(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
if ($backURL) { |
|
41
|
|
|
$fields->push(HiddenField::create('BackURL', false, $backURL)); |
|
|
|
|
|
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
parent::__construct($controller, $name, $fields, $actions); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @return FieldList |
|
49
|
|
|
*/ |
|
50
|
|
|
protected function getFormFields() |
|
51
|
|
|
{ |
|
52
|
|
|
$fields = FieldList::create(); |
|
53
|
|
|
|
|
54
|
|
|
// Security/changepassword?h=XXX redirects to Security/changepassword |
|
55
|
|
|
// without GET parameter to avoid potential HTTP referer leakage. |
|
56
|
|
|
// In this case, a user is not logged in, and no 'old password' should be necessary. |
|
57
|
|
|
if (Security::getCurrentUser()) { |
|
58
|
|
|
$fields->push(PasswordField::create('OldPassword', _t('SilverStripe\\Security\\Member.YOUROLDPASSWORD', 'Your old password'))); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$fields->push(PasswordField::create('NewPassword1', _t('SilverStripe\\Security\\Member.NEWPASSWORD', 'New Password'))); |
|
62
|
|
|
$fields->push(PasswordField::create('NewPassword2', _t('SilverStripe\\Security\\Member.CONFIRMNEWPASSWORD', 'Confirm New Password'))); |
|
63
|
|
|
|
|
64
|
|
|
return $fields; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @return FieldList |
|
69
|
|
|
*/ |
|
70
|
|
|
protected function getFormActions() |
|
71
|
|
|
{ |
|
72
|
|
|
$actions = FieldList::create( |
|
73
|
|
|
FormAction::create( |
|
74
|
|
|
'doChangePassword', |
|
75
|
|
|
_t('SilverStripe\\Security\\Member.BUTTONCHANGEPASSWORD', 'Change Password') |
|
76
|
|
|
) |
|
77
|
|
|
); |
|
78
|
|
|
|
|
79
|
|
|
return $actions; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: