Elgg  Version 1.11
user_settings.php
Go to the documentation of this file.
1 <?php
18  $current_password = get_input('current_password', null, false);
19  $password = get_input('password', null, false);
20  $password2 = get_input('password2', null, false);
21  $user_guid = get_input('guid');
22 
23  if ($user_guid) {
25  } else {
27  }
28 
29  if ($user && $password) {
30  // let admin user change anyone's password without knowing it except his own.
32  $credentials = array(
33  'username' => $user->username,
34  'password' => $current_password
35  );
36 
37  try {
38  pam_auth_userpass($credentials);
39  } catch (LoginException $e) {
40  register_error(elgg_echo('LoginException:ChangePasswordFailure'));
41  return false;
42  }
43  }
44 
45  try {
47  } catch (RegistrationException $e) {
48  register_error($e->getMessage());
49  return false;
50  }
51 
52  if ($result) {
53  if ($password == $password2) {
54  $user->setPassword($password);
55  _elgg_services()->persistentLogin->handlePasswordChange($user, elgg_get_logged_in_user_entity());
56 
57  if ($user->save()) {
58  system_message(elgg_echo('user:password:success'));
59  return true;
60  } else {
61  register_error(elgg_echo('user:password:fail'));
62  }
63  } else {
64  register_error(elgg_echo('user:password:fail:notsame'));
65  }
66  } else {
67  register_error(elgg_echo('user:password:fail:tooshort'));
68  }
69  } else {
70  // no change
71  return null;
72  }
73 
74  return false;
75 }
76 
84 function _elgg_set_user_name() {
85  $name = strip_tags(get_input('name'));
86  $user_guid = get_input('guid');
87 
88  if ($user_guid) {
90  } else {
92  }
93 
94  if (elgg_strlen($name) > 50) {
95  register_error(elgg_echo('user:name:fail'));
96  return false;
97  }
98 
99  if ($user && $user->canEdit() && $name) {
100  if ($name != $user->name) {
101  $user->name = $name;
102  if ($user->save()) {
103  system_message(elgg_echo('user:name:success'));
104  return true;
105  } else {
106  register_error(elgg_echo('user:name:fail'));
107  }
108  } else {
109  // no change
110  return null;
111  }
112  } else {
113  register_error(elgg_echo('user:name:fail'));
114  }
115  return false;
116 }
117 
126  $language = get_input('language');
127  $user_guid = get_input('guid');
128 
129  if ($user_guid) {
131  } else {
133  }
134 
135  if ($user && $language) {
136  if (strcmp($language, $user->language) != 0) {
137  $user->language = $language;
138  if ($user->save()) {
139  system_message(elgg_echo('user:language:success'));
140  return true;
141  } else {
142  register_error(elgg_echo('user:language:fail'));
143  }
144  } else {
145  // no change
146  return null;
147  }
148  } else {
149  register_error(elgg_echo('user:language:fail'));
150  }
151  return false;
152 }
153 
162  $email = get_input('email');
163  $user_guid = get_input('guid');
164 
165  if ($user_guid) {
167  } else {
169  }
170 
171  if (!is_email_address($email)) {
172  register_error(elgg_echo('email:save:fail'));
173  return false;
174  }
175 
176  if ($user) {
177  if (strcmp($email, $user->email) != 0) {
178  if (!get_user_by_email($email)) {
179  if ($user->email != $email) {
180 
181  $user->email = $email;
182  if ($user->save()) {
183  system_message(elgg_echo('email:save:success'));
184  return true;
185  } else {
186  register_error(elgg_echo('email:save:fail'));
187  }
188  }
189  } else {
190  register_error(elgg_echo('registration:dupeemail'));
191  }
192  } else {
193  // no change
194  return null;
195  }
196  } else {
197  register_error(elgg_echo('email:save:fail'));
198  }
199  return false;
200 }
201 
210 
211  if (!elgg_get_config('allow_user_default_access')) {
212  return false;
213  }
214 
215  $default_access = get_input('default_access');
216  $user_guid = get_input('guid');
217 
218  if ($user_guid) {
220  } else {
222  }
223 
224  if ($user) {
225  $current_default_access = $user->getPrivateSetting('elgg_default_access');
226  if ($default_access !== $current_default_access) {
227  if ($user->setPrivateSetting('elgg_default_access', $default_access)) {
228  system_message(elgg_echo('user:default_access:success'));
229  return true;
230  } else {
231  register_error(elgg_echo('user:default_access:failure'));
232  }
233  } else {
234  // no change
235  return null;
236  }
237  } else {
238  register_error(elgg_echo('user:default_access:failure'));
239  }
240 
241  return false;
242 }
243 
252 
253  if (!$user) {
254  return;
255  }
256 
257  if (!elgg_in_context("settings")) {
258  return;
259  }
260 
261  $params = array(
262  'name' => '1_account',
263  'text' => elgg_echo('usersettings:user:opt:linktext'),
264  'href' => "settings/user/{$user->username}",
265  'section' => 'configure',
266  );
268  $params = array(
269  'name' => '1_plugins',
270  'text' => elgg_echo('usersettings:plugins:opt:linktext'),
271  'href' => '#',
272  'section' => 'configure',
273  );
275  $params = array(
276  'name' => '1_statistics',
277  'text' => elgg_echo('usersettings:statistics:opt:linktext'),
278  'href' => "settings/statistics/{$user->username}",
279  'section' => 'configure',
280  );
282 
283  // register plugin user settings menu items
284  $active_plugins = elgg_get_plugins();
285 
286  foreach ($active_plugins as $plugin) {
287  $plugin_id = $plugin->getID();
288  if (elgg_view_exists("usersettings/$plugin_id/edit") || elgg_view_exists("plugins/$plugin_id/usersettings")) {
289  $params = array(
290  'name' => $plugin_id,
291  'text' => $plugin->getFriendlyName(),
292  'href' => "settings/plugins/{$user->username}/$plugin_id",
293  'parent_name' => '1_plugins',
294  'section' => 'configure',
295  );
297  }
298  }
299 
300  elgg_register_plugin_hook_handler("prepare", "menu:page", "_elgg_user_settings_menu_prepare");
301 }
302 
315  if (empty($value)) {
316  return $value;
317  }
318 
319  if (!elgg_in_context("settings")) {
320  return $value;
321  }
322 
323  $configure = elgg_extract("configure", $value);
324  if (empty($configure)) {
325  return $value;
326  }
327 
328  foreach ($configure as $index => $menu_item) {
329  if (!($menu_item instanceof ElggMenuItem)) {
330  continue;
331  }
332 
333  if ($menu_item->getName() == "1_plugins") {
334  if (!$menu_item->getChildren()) {
335  // no need for this menu item if it has no children
336  unset($value["configure"][$index]);
337  }
338  }
339  }
340 
341  return $value;
342 }
343 
353  global $CONFIG;
354 
355  if (!isset($page[0])) {
356  $page[0] = 'user';
357  }
358 
359  if (isset($page[1])) {
360  $user = get_user_by_username($page[1]);
362  } else {
365  }
366 
367  elgg_push_breadcrumb(elgg_echo('settings'), "settings/user/$user->username");
368 
369  switch ($page[0]) {
370  case 'statistics':
371  elgg_push_breadcrumb(elgg_echo('usersettings:statistics:opt:linktext'));
372  $path = $CONFIG->path . "pages/settings/statistics.php";
373  break;
374  case 'plugins':
375  if (isset($page[2])) {
376  set_input("plugin_id", $page[2]);
377  elgg_push_breadcrumb(elgg_echo('usersettings:plugins:opt:linktext'));
378  $path = $CONFIG->path . "pages/settings/tools.php";
379  }
380  break;
381  case 'user':
382  $path = $CONFIG->path . "pages/settings/account.php";
383  break;
384  }
385 
386  if (isset($path)) {
387  require $path;
388  return true;
389  }
390  return false;
391 }
392 
400  elgg_register_page_handler('settings', '_elgg_user_settings_page_handler');
401 
402  elgg_register_event_handler('pagesetup', 'system', '_elgg_user_settings_menu_setup');
403 
404  elgg_register_plugin_hook_handler('usersettings:save', 'user', '_elgg_set_user_language');
405  elgg_register_plugin_hook_handler('usersettings:save', 'user', '_elgg_set_user_password');
406  elgg_register_plugin_hook_handler('usersettings:save', 'user', '_elgg_set_user_default_access');
407  elgg_register_plugin_hook_handler('usersettings:save', 'user', '_elgg_set_user_name');
408  elgg_register_plugin_hook_handler('usersettings:save', 'user', '_elgg_set_user_email');
409 
410  elgg_register_action("usersettings/save");
411 
412  // extend the account settings form
413  elgg_extend_view('forms/account/settings', 'core/settings/account/name', 100);
414  elgg_extend_view('forms/account/settings', 'core/settings/account/password', 100);
415  elgg_extend_view('forms/account/settings', 'core/settings/account/email', 100);
416  elgg_extend_view('forms/account/settings', 'core/settings/account/language', 100);
417  elgg_extend_view('forms/account/settings', 'core/settings/account/default_access', 100);
418 }
419 
420 return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) {
421  $events->registerHandler('init', 'system', '_elgg_user_settings_init');
422 };
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
$password2
Definition: register.php:14
elgg_push_breadcrumb($title, $link=null)
Adds a breadcrumb to the breadcrumbs stack.
Definition: navigation.php:244
_elgg_user_settings_page_handler($page)
Page handler for user settings.
$plugin
get_user_by_email($email)
Get an array of users from an email address.
Definition: users.php:120
get_input($variable, $default=null, $filter_result=true)
Get some input from variables passed submitted through GET or POST.
Definition: input.php:27
_elgg_set_user_language()
Set a user&#39;s language.
elgg_is_admin_logged_in()
Returns whether or not the viewer is currently logged in and an admin user.
Definition: sessions.php:60
if($guid==elgg_get_logged_in_user_guid()) $name
Definition: delete.php:21
$e
Definition: metadata.php:12
$value
Definition: longtext.php:26
elgg_view_exists($view, $viewtype= '', $recurse=true)
Returns whether the specified view exists.
Definition: views.php:318
set_input($variable, $value)
Sets an input value that may later be retrieved by get_input.
Definition: input.php:41
_elgg_user_settings_menu_setup()
Set up the menu for user settings.
elgg_extract($key, array $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:1246
$email
Definition: register.php:15
elgg_register_plugin_hook_handler($hook, $type, $callback, $priority=500)
Definition: elgglib.php:703
pam_auth_userpass(array $credentials=array())
Hook into the PAM system which accepts a username and password and attempts to authenticate it agains...
Definition: sessions.php:158
elgg_set_page_owner_guid($guid)
Set the guid of the entity that owns this page.
Definition: pageowner.php:73
get_user_by_username($username)
Get user by username.
Definition: users.php:98
elgg_strlen()
Wrapper function for mb_strlen().
Definition: mb_wrapper.php:72
$params
Definition: login.php:72
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
_elgg_set_user_name()
Set a user&#39;s display name.
get_user($guid)
Get a user object from a GUID.
Definition: users.php:87
validate_password($password)
Simple validation of a password.
Definition: users.php:267
_elgg_services()
Definition: autoloader.php:14
$plugin_id
Definition: save.php:16
_elgg_user_settings_menu_prepare($hook, $type, $value, $params)
Prepares the page menu to strip out empty plugins menu item for user settings.
global $CONFIG
elgg_extend_view($view, $view_extension, $priority=501, $viewtype= '')
Extends a view with another view.
Definition: views.php:401
$user
Definition: ban.php:13
_elgg_set_user_default_access()
Set a user&#39;s default access level.
elgg_in_context($context)
Check if this context exists anywhere in the stack.
Definition: pageowner.php:250
elgg require
Throw an error if the required package isn&#39;t present.
Definition: elgglib.js:164
elgg_register_page_handler($identifier, $function)
Registers a page handler for a particular identifier.
Definition: pagehandler.php:34
_elgg_set_user_email()
Set a user&#39;s email address.
elgg global
Pointer to the global context.
Definition: elgglib.js:12
elgg_get_page_owner_entity()
Gets the owner entity for the current page.
Definition: pageowner.php:53
_elgg_user_settings_init()
Initialize the user settings library.
$type
Definition: add.php:8
_elgg_set_user_password()
Set a user&#39;s password.
elgg_register_menu_item($menu_name, $menu_item)
Register an item for an Elgg menu.
Definition: navigation.php:92
$password
Definition: login.php:25
elgg system_message
Wrapper function for system_messages.
Definition: elgglib.js:374
elgg_register_event_handler($event, $object_type, $callback, $priority=500)
Definition: elgglib.php:519
elgg_get_plugins($status= 'active', $site_guid=null)
Returns an ordered list of plugins.
Definition: plugins.php:162
elgg register_error
Wrapper function for system_messages.
Definition: elgglib.js:383
elgg_get_logged_in_user_entity()
Return the current logged in user, or null if no user is logged in.
Definition: sessions.php:32
elgg_register_action($action, $filename="", $access= 'logged_in')
Registers an action.
Definition: actions.php:85
$user_guid
Avatar remove action.
Definition: remove.php:6
$language
$vars[&#39;language&#39;]
Definition: languages.php:6
is_email_address($address)
Validates an email address.
Definition: input.php:88
$path
Definition: invalid.php:17
elgg_get_logged_in_user_guid()
Return the current logged in user by guid.
Definition: sessions.php:42