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() |
32
|
|
|
?: $controller->getRequest()->getSession()->get('BackURL'); |
33
|
|
|
|
34
|
|
|
if (!$fields) { |
35
|
|
|
$fields = $this->getFormFields(); |
36
|
|
|
} |
37
|
|
|
if (!$actions) { |
38
|
|
|
$actions = $this->getFormActions(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
if ($backURL) { |
42
|
|
|
$fields->push(HiddenField::create('BackURL', false, $backURL)); |
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
parent::__construct($controller, $name, $fields, $actions); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return FieldList |
50
|
|
|
*/ |
51
|
|
|
protected function getFormFields() |
52
|
|
|
{ |
53
|
|
|
$fields = FieldList::create(); |
54
|
|
|
|
55
|
|
|
// Security/changepassword?h=XXX redirects to Security/changepassword |
56
|
|
|
// without GET parameter to avoid potential HTTP referer leakage. |
57
|
|
|
// In this case, a user is not logged in, and no 'old password' should be necessary. |
58
|
|
|
if (Security::getCurrentUser()) { |
59
|
|
|
$fields->push(PasswordField::create( |
60
|
|
|
'OldPassword', |
61
|
|
|
_t('SilverStripe\\Security\\Member.YOUROLDPASSWORD', 'Your old password') |
62
|
|
|
)); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$fields->push(PasswordField::create( |
66
|
|
|
'NewPassword1', |
67
|
|
|
_t('SilverStripe\\Security\\Member.NEWPASSWORD', 'New Password') |
68
|
|
|
)); |
69
|
|
|
$fields->push(PasswordField::create( |
70
|
|
|
'NewPassword2', |
71
|
|
|
_t('SilverStripe\\Security\\Member.CONFIRMNEWPASSWORD', 'Confirm New Password') |
72
|
|
|
)); |
73
|
|
|
|
74
|
|
|
return $fields; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return FieldList |
79
|
|
|
*/ |
80
|
|
|
protected function getFormActions() |
81
|
|
|
{ |
82
|
|
|
$actions = FieldList::create( |
83
|
|
|
FormAction::create( |
84
|
|
|
'doChangePassword', |
85
|
|
|
_t('SilverStripe\\Security\\Member.BUTTONCHANGEPASSWORD', 'Change Password') |
86
|
|
|
) |
87
|
|
|
); |
88
|
|
|
|
89
|
|
|
return $actions; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|