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