1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Controller that is used to allow users to manage their accounts via |
5
|
|
|
* the front end of the site. |
6
|
|
|
* |
7
|
|
|
*/ |
8
|
|
|
class Users_Account_Controller extends Controller implements PermissionProvider |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* URL That you can access this from |
13
|
|
|
* |
14
|
|
|
* @config |
15
|
|
|
*/ |
16
|
|
|
private static $url_segment = "users/account"; |
|
|
|
|
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Allowed sub-URL's on this controller |
20
|
|
|
* |
21
|
|
|
* @var array |
22
|
|
|
* @config |
23
|
|
|
*/ |
24
|
|
|
private static $allowed_actions = array( |
|
|
|
|
25
|
|
|
"edit", |
26
|
|
|
"changepassword", |
27
|
|
|
"EditAccountForm", |
28
|
|
|
"ChangePasswordForm", |
29
|
|
|
); |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* User account associated with this controller |
33
|
|
|
* |
34
|
|
|
* @var Member |
35
|
|
|
*/ |
36
|
|
|
protected $member; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Getter for member |
40
|
|
|
* |
41
|
|
|
* @return Member |
42
|
|
|
*/ |
43
|
|
|
public function getMember() |
44
|
|
|
{ |
45
|
|
|
return $this->member; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Setter for member |
50
|
|
|
* |
51
|
|
|
* @param Member $member |
52
|
|
|
* @return self |
53
|
|
|
*/ |
54
|
|
|
public function setMember(Member $member) |
55
|
|
|
{ |
56
|
|
|
$this->member = $member; |
57
|
|
|
return $this; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Determine if current user requires verification (based on their |
62
|
|
|
* account and Users verification setting). |
63
|
|
|
* |
64
|
|
|
* @return boolean |
65
|
|
|
*/ |
66
|
|
|
public function RequireVerification() |
67
|
|
|
{ |
68
|
|
|
if (!$this->member->isVerified() && Users::config()->require_verification) { |
|
|
|
|
69
|
|
|
return true; |
70
|
|
|
} else { |
71
|
|
|
return false; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Perorm setup when this controller is initialised |
77
|
|
|
* |
78
|
|
|
* @return void |
79
|
|
|
*/ |
80
|
|
|
public function init() |
81
|
|
|
{ |
82
|
|
|
parent::init(); |
83
|
|
|
|
84
|
|
|
// Check we are logged in as a user who can access front end management |
85
|
|
|
if (!Permission::check("USERS_MANAGE_ACCOUNT")) { |
86
|
|
|
Security::permissionFailure(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
// Set our member object |
90
|
|
|
$this->member = Member::currentUser(); |
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Get the link to this controller |
95
|
|
|
* |
96
|
|
|
* @param string $action |
|
|
|
|
97
|
|
|
* @return string |
98
|
|
|
*/ |
99
|
|
|
public function Link($action = null) |
100
|
|
|
{ |
101
|
|
|
return Controller::join_links( |
102
|
|
|
$this->config()->url_segment, |
103
|
|
|
$action |
104
|
|
|
); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Get an absolute link to this controller |
109
|
|
|
* |
110
|
|
|
* @param string $action |
|
|
|
|
111
|
|
|
* @return string |
|
|
|
|
112
|
|
|
*/ |
113
|
|
|
public function AbsoluteLink($action = null) |
114
|
|
|
{ |
115
|
|
|
return Director::absoluteURL($this->Link($action)); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Get a relative (to the root url of the site) link to this |
120
|
|
|
* controller |
121
|
|
|
* |
122
|
|
|
* @param string $action |
|
|
|
|
123
|
|
|
* @return string |
124
|
|
|
*/ |
125
|
|
|
public function RelativeLink($action = null) |
126
|
|
|
{ |
127
|
|
|
return Controller::join_links( |
128
|
|
|
$this->Link($action) |
129
|
|
|
); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Display the currently outstanding orders for the current user |
134
|
|
|
* |
135
|
|
|
*/ |
136
|
|
View Code Duplication |
public function index() |
|
|
|
|
137
|
|
|
{ |
138
|
|
|
$member = Member::currentUser(); |
|
|
|
|
139
|
|
|
|
140
|
|
|
$this->customise(array( |
141
|
|
|
"ClassName" => "AccountPage" |
142
|
|
|
)); |
143
|
|
|
|
144
|
|
|
$this->extend("onBeforeIndex"); |
145
|
|
|
|
146
|
|
|
return $this->renderWith(array( |
147
|
|
|
"UserAccount", |
148
|
|
|
"UserAccount", |
149
|
|
|
"Page" |
150
|
|
|
)); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
View Code Duplication |
public function edit() |
|
|
|
|
154
|
|
|
{ |
155
|
|
|
$member = Member::currentUser(); |
156
|
|
|
|
157
|
|
|
$this->customise(array( |
158
|
|
|
"ClassName" => "AccountPage", |
159
|
|
|
"Form" => $this->EditAccountForm()->loadDataFrom($member) |
|
|
|
|
160
|
|
|
)); |
161
|
|
|
|
162
|
|
|
$this->extend("onBeforeEdit"); |
163
|
|
|
|
164
|
|
|
return $this->renderWith(array( |
165
|
|
|
"UserAccount_edit", |
166
|
|
|
"UserAccount", |
167
|
|
|
"Page" |
168
|
|
|
)); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
public function changepassword() |
172
|
|
|
{ |
173
|
|
|
// Set the back URL for this form |
174
|
|
|
$back_url = Controller::join_links( |
175
|
|
|
$this->Link("changepassword"), |
176
|
|
|
"?s=1" |
177
|
|
|
); |
178
|
|
|
|
179
|
|
|
Session::set("BackURL", $back_url); |
180
|
|
|
|
181
|
|
|
$form = $this->ChangePasswordForm(); |
182
|
|
|
|
183
|
|
|
// Is password changed, set a session message. |
184
|
|
|
$password_set = $this->request->getVar("s"); |
185
|
|
|
if($password_set && $password_set == 1) { |
186
|
|
|
$form->sessionMessage( |
187
|
|
|
_t("Users.PasswordChangedSuccessfully","Password Changed Successfully"), |
188
|
|
|
"good" |
189
|
|
|
); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
$this->customise(array( |
193
|
|
|
"ClassName" => "AccountPage", |
194
|
|
|
"Form" => $form |
195
|
|
|
)); |
196
|
|
|
|
197
|
|
|
$this->extend("onBeforeChangePassword"); |
198
|
|
|
|
199
|
|
|
return $this->renderWith(array( |
200
|
|
|
"UserAccount_changepassword", |
201
|
|
|
"UserAccount", |
202
|
|
|
"Page" |
203
|
|
|
)); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Factory for generating a profile form. The form can be expanded using an |
208
|
|
|
* extension class and calling the updateEditProfileForm method. |
209
|
|
|
* |
210
|
|
|
* @return Form |
211
|
|
|
*/ |
212
|
|
|
public function EditAccountForm() |
213
|
|
|
{ |
214
|
|
|
$form = Users_EditAccountForm::create($this, "EditAccountForm"); |
215
|
|
|
|
216
|
|
|
$this->extend("updateEditAccountForm", $form); |
217
|
|
|
|
218
|
|
|
return $form; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* Factory for generating a change password form. The form can be expanded |
223
|
|
|
* using an extension class and calling the updateChangePasswordForm method. |
224
|
|
|
* |
225
|
|
|
* @return Form |
226
|
|
|
*/ |
227
|
|
|
public function ChangePasswordForm() |
228
|
|
|
{ |
229
|
|
|
$form = ChangePasswordForm::create($this, "ChangePasswordForm"); |
230
|
|
|
|
231
|
|
|
$form |
232
|
|
|
->Actions() |
233
|
|
|
->find("name", "action_doChangePassword") |
234
|
|
|
->addExtraClass("btn") |
235
|
|
|
->addExtraClass("btn-green"); |
236
|
|
|
|
237
|
|
|
$cancel_btn = LiteralField::create( |
238
|
|
|
"CancelLink", |
239
|
|
|
'<a href="' . $this->Link() . '" class="btn btn-red">'. _t("Users.CANCEL", "Cancel") .'</a>' |
240
|
|
|
); |
241
|
|
|
|
242
|
|
|
$form |
243
|
|
|
->Actions() |
244
|
|
|
->insertBefore($cancel_btn, "action_doChangePassword"); |
|
|
|
|
245
|
|
|
|
246
|
|
|
$this->extend("updateChangePasswordForm", $form); |
247
|
|
|
|
248
|
|
|
return $form; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* Return a list of nav items for managing a users profile. You can add new |
253
|
|
|
* items to this menu using the "updateAccountMenu" extension |
254
|
|
|
* |
255
|
|
|
* @return ArrayList |
256
|
|
|
*/ |
257
|
|
|
public function getAccountMenu() |
258
|
|
|
{ |
259
|
|
|
$menu = new ArrayList(); |
260
|
|
|
|
261
|
|
|
$curr_action = $this->request->param("Action"); |
262
|
|
|
|
263
|
|
|
$menu->add(new ArrayData(array( |
264
|
|
|
"ID" => 0, |
265
|
|
|
"Title" => _t('Users.PROFILESUMMARY', "Profile Summary"), |
266
|
|
|
"Link" => $this->Link(), |
267
|
|
|
"LinkingMode" => (!$curr_action) ? "current" : "link" |
268
|
|
|
))); |
269
|
|
|
|
270
|
|
|
$menu->add(new ArrayData(array( |
271
|
|
|
"ID" => 10, |
272
|
|
|
"Title" => _t('Users.EDITDETAILS', "Edit account details"), |
273
|
|
|
"Link" => $this->Link("edit"), |
274
|
|
|
"LinkingMode" => ($curr_action == "edit") ? "current" : "link" |
275
|
|
|
))); |
276
|
|
|
|
277
|
|
|
$menu->add(new ArrayData(array( |
278
|
|
|
"ID" => 30, |
279
|
|
|
"Title" => _t('Users.CHANGEPASSWORD', "Change password"), |
280
|
|
|
"Link" => $this->Link("changepassword"), |
281
|
|
|
"LinkingMode" => ($curr_action == "changepassword") ? "current" : "link" |
282
|
|
|
))); |
283
|
|
|
|
284
|
|
|
$this->extend("updateAccountMenu", $menu); |
285
|
|
|
|
286
|
|
|
return $menu->sort("ID", "ASC"); |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
public function providePermissions() |
290
|
|
|
{ |
291
|
|
|
return array( |
292
|
|
|
"USERS_MANAGE_ACCOUNT" => array( |
293
|
|
|
'name' => 'Manage user account', |
294
|
|
|
'help' => 'Allow user to manage their account details', |
295
|
|
|
'category' => 'Frontend Users', |
296
|
|
|
'sort' => 100 |
297
|
|
|
), |
298
|
|
|
"USERS_VERIFIED" => array( |
299
|
|
|
'name' => 'Verified user', |
300
|
|
|
'help' => 'Users have verified their account', |
301
|
|
|
'category' => 'Frontend Users', |
302
|
|
|
'sort' => 100 |
303
|
|
|
), |
304
|
|
|
); |
305
|
|
|
} |
306
|
|
|
} |
307
|
|
|
|
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.