Elgg  Version 1.9
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) {
56  _elgg_services()->persistentLogin->handlePasswordChange($user, elgg_get_logged_in_user_entity());
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  $params = array(
258  'name' => '1_account',
259  'text' => elgg_echo('usersettings:user:opt:linktext'),
260  'href' => "settings/user/{$user->username}",
261  'section' => 'configure',
262  'contexts' => array('settings'),
263  );
265  $params = array(
266  'name' => '1_plugins',
267  'text' => elgg_echo('usersettings:plugins:opt:linktext'),
268  'href' => "settings/plugins/{$user->username}",
269  'section' => 'configure',
270  'contexts' => array('settings'),
271  );
273  $params = array(
274  'name' => '1_statistics',
275  'text' => elgg_echo('usersettings:statistics:opt:linktext'),
276  'href' => "settings/statistics/{$user->username}",
277  'section' => 'configure',
278  'contexts' => array('settings'),
279  );
281 }
282 
292  global $CONFIG;
293 
294  if (!isset($page[0])) {
295  $page[0] = 'user';
296  }
297 
298  if (isset($page[1])) {
299  $user = get_user_by_username($page[1]);
301  } else {
304  }
305 
306  elgg_push_breadcrumb(elgg_echo('settings'), "settings/user/$user->username");
307 
308  switch ($page[0]) {
309  case 'statistics':
310  elgg_push_breadcrumb(elgg_echo('usersettings:statistics:opt:linktext'));
311  $path = $CONFIG->path . "pages/settings/statistics.php";
312  break;
313  case 'plugins':
314  elgg_push_breadcrumb(elgg_echo('usersettings:plugins:opt:linktext'));
315  $path = $CONFIG->path . "pages/settings/tools.php";
316  break;
317  case 'user':
318  $path = $CONFIG->path . "pages/settings/account.php";
319  break;
320  }
321 
322  if (isset($path)) {
323  require $path;
324  return true;
325  }
326  return false;
327 }
328 
336  elgg_register_page_handler('settings', '_elgg_user_settings_page_handler');
337 
338  elgg_register_event_handler('pagesetup', 'system', '_elgg_user_settings_menu_setup');
339 
340  elgg_register_plugin_hook_handler('usersettings:save', 'user', '_elgg_set_user_language');
341  elgg_register_plugin_hook_handler('usersettings:save', 'user', '_elgg_set_user_password');
342  elgg_register_plugin_hook_handler('usersettings:save', 'user', '_elgg_set_user_default_access');
343  elgg_register_plugin_hook_handler('usersettings:save', 'user', '_elgg_set_user_name');
344  elgg_register_plugin_hook_handler('usersettings:save', 'user', '_elgg_set_user_email');
345 
346  elgg_register_action("usersettings/save");
347 
348  // extend the account settings form
349  elgg_extend_view('forms/account/settings', 'core/settings/account/name', 100);
350  elgg_extend_view('forms/account/settings', 'core/settings/account/password', 100);
351  elgg_extend_view('forms/account/settings', 'core/settings/account/email', 100);
352  elgg_extend_view('forms/account/settings', 'core/settings/account/language', 100);
353  elgg_extend_view('forms/account/settings', 'core/settings/account/default_access', 100);
354 }
355 
356 elgg_register_event_handler('init', 'system', '_elgg_user_settings_init');
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:221
_elgg_user_settings_page_handler($page)
Page handler for user settings.
get_user_by_email($email)
Get an array of users from an email address.
Definition: users.php:295
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:65
if($guid==elgg_get_logged_in_user_guid()) $name
Definition: delete.php:21
$e
Definition: metadata.php:12
_elgg_user_settings_menu_setup()
Set up the menu for user settings.
$email
Definition: register.php:15
elgg_register_plugin_hook_handler($hook, $type, $callback, $priority=500)
Register a callback as a plugin hook handler.
Definition: elgglib.php:853
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:164
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:246
elgg_strlen()
Wrapper function for mb_strlen().
Definition: mb_wrapper.php:76
$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:222
validate_password($password)
Simple validation of a password.
Definition: users.php:604
_elgg_services()
Definition: autoloader.php:14
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 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.
_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:73
generate_user_password(ElggUser $user, $password)
Hash a password for storage.
Definition: users.php:531
$password
Definition: login.php:25
_elgg_generate_password_salt()
Generate an 8 character Base64 URL salt for the password.
Definition: users.php:519
elgg system_message
Wrapper function for system_messages.
Definition: elgglib.js:374
elgg_register_event_handler($event, $object_type, $callback, $priority=500)
Register a callback as an Elgg event handler.
Definition: elgglib.php:669
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;] $vars[&#39;lc&#39;] if present, client will be sent long expires headers ...
Definition: languages.php:7
is_email_address($address)
Validates an email address.
Definition: input.php:129
$path
Definition: invalid.php:17
elgg_get_logged_in_user_guid()
Return the current logged in user by guid.
Definition: sessions.php:42