1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Class LDAPSecurityController |
4
|
|
|
* |
5
|
|
|
* This controller overrides the default Security controller with functionality |
6
|
|
|
* for resetting passwords. |
7
|
|
|
*/ |
8
|
|
|
class LDAPSecurityController extends Security |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var array |
12
|
|
|
*/ |
13
|
|
|
private static $allowed_actions = [ |
|
|
|
|
14
|
|
|
'index', |
15
|
|
|
'lostpassword', |
16
|
|
|
'LostPasswordForm', |
17
|
|
|
'ChangePasswordForm', |
18
|
|
|
'passwordsent' |
19
|
|
|
]; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* This static function is *intentionally* overloaded from Security so |
23
|
|
|
* the user accesses this controller and uses the LDAP change password |
24
|
|
|
* form rather than the "standard" one provided by Security. |
25
|
|
|
* |
26
|
|
|
* @param Member $member |
27
|
|
|
* @param $autologinToken |
28
|
|
|
* @return string |
29
|
|
|
*/ |
30
|
|
|
public static function getPasswordResetLink($member, $autologinToken) |
31
|
|
|
{ |
32
|
|
|
$autologinToken = urldecode($autologinToken); |
33
|
|
|
$selfControllerClass = __CLASS__; |
34
|
|
|
$selfController = new $selfControllerClass(); |
35
|
|
|
return $selfController->Link('changepassword') . "?m={$member->ID}&t=$autologinToken"; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Factory method for the lost password form |
40
|
|
|
* |
41
|
|
|
* @return Form Returns the lost password form |
42
|
|
|
*/ |
43
|
|
|
public function ChangePasswordForm() |
44
|
|
|
{ |
45
|
|
|
return Object::create('LDAPChangePasswordForm', $this, 'ChangePasswordForm'); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function lostpassword() |
49
|
|
|
{ |
50
|
|
|
$controller = $this->getResponseController(_t('LDAPSecurityController.LOSTPASSWORDHEADER', 'Lost password')); |
51
|
|
|
|
52
|
|
|
// if the controller calls Director::redirect(), this will break early |
53
|
|
|
if (($response = $controller->getResponse()) && $response->isFinished()) { |
54
|
|
|
return $response; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if (Config::inst()->get('LDAPAuthenticator', 'allow_email_login')==='yes') { |
58
|
|
|
$customisedController = $controller->customise([ |
59
|
|
|
'Content' => |
60
|
|
|
'<p>' . |
61
|
|
|
_t( |
62
|
|
|
'LDAPSecurityController.NOTERESETPASSWORDUSERNAMEOREMAIL', |
63
|
|
|
'Enter your username or your email address and we will send you a link with which ' |
64
|
|
|
. 'you can reset your password' |
65
|
|
|
) . |
66
|
|
|
'</p>', |
67
|
|
|
'Form' => $this->LostPasswordForm(), |
68
|
|
|
]); |
69
|
|
|
} else { |
70
|
|
|
$customisedController = $controller->customise([ |
71
|
|
|
'Content' => |
72
|
|
|
'<p>' . |
73
|
|
|
_t( |
74
|
|
|
'LDAPSecurityController.NOTERESETPASSWORDUSERNAME', |
75
|
|
|
'Enter your username and we will send you a link with which you can reset your password' |
76
|
|
|
) . |
77
|
|
|
'</p>', |
78
|
|
|
'Form' => $this->LostPasswordForm(), |
79
|
|
|
]); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
//Controller::$currentController = $controller; |
|
|
|
|
83
|
|
|
return $customisedController->renderWith($this->getTemplatesFor('lostpassword')); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Factory method for the lost password form |
88
|
|
|
* |
89
|
|
|
* @return Form Returns the lost password form |
90
|
|
|
*/ |
91
|
|
|
public function LostPasswordForm() |
92
|
|
|
{ |
93
|
|
|
$email = new EmailField('Email', _t('Member.EMAIL', 'Email')); |
94
|
|
|
$action = new FormAction('forgotPassword', _t('Security.BUTTONSEND', 'Send me the password reset link')); |
95
|
|
|
return LDAPLoginForm::create($this, |
96
|
|
|
'LostPasswordForm', |
97
|
|
|
new FieldList([$email]), |
98
|
|
|
new FieldList([$action]), |
99
|
|
|
false |
100
|
|
|
); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param null $action |
105
|
|
|
* @return String |
106
|
|
|
*/ |
107
|
|
|
public function Link($action = null) |
108
|
|
|
{ |
109
|
|
|
return Controller::join_links(Director::baseURL(), 'LDAPSecurity', $action); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Show the "password sent" page, after a user has requested |
114
|
|
|
* to reset their password. |
115
|
|
|
* |
116
|
|
|
* @param SS_HTTPRequest $request The SS_HTTPRequest for this action. |
117
|
|
|
* @return string Returns the "password sent" page as HTML code. |
118
|
|
|
*/ |
119
|
|
|
public function passwordsent($request) |
120
|
|
|
{ |
121
|
|
|
$controller = $this->getResponseController(_t('Security.LOSTPASSWORDHEADER', 'Lost Password')); |
122
|
|
|
|
123
|
|
|
// if the controller calls Director::redirect(), this will break early |
124
|
|
|
if (($response = $controller->getResponse()) && $response->isFinished()) { |
125
|
|
|
return $response; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
$username = Convert::raw2xml(rawurldecode($request->param('ID'))); |
129
|
|
|
|
130
|
|
|
$customisedController = $controller->customise([ |
131
|
|
|
'Title' => _t('LDAPSecurity.PASSWORDSENTHEADER', "Password reset link sent to '{username}'", |
132
|
|
|
['username' => $username]), |
|
|
|
|
133
|
|
|
'Content' => |
134
|
|
|
"<p>" |
135
|
|
|
. _t('LDAPSecurity.PASSWORDSENTTEXT', |
136
|
|
|
"Thank you! A reset link has been sent to '{username}', provided an account exists.", |
137
|
|
|
['username' => $username]) |
|
|
|
|
138
|
|
|
. "</p>", |
139
|
|
|
'Username' => $username |
140
|
|
|
]); |
141
|
|
|
return $customisedController->renderWith($this->getTemplatesFor('passwordsent')); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.