209 if (!isset($CONFIG->minusername)) {
210 $CONFIG->minusername = 4;
213 if (strlen(
$username) < $CONFIG->minusername) {
214 $msg =
elgg_echo(
'registration:usernametooshort', array($CONFIG->minusername));
215 throw new \RegistrationException($msg);
220 $msg =
elgg_echo(
'registration:usernametoolong', array(128));
221 throw new \RegistrationException($msg);
226 '\x{0080}-\x{009f}' .
228 '\x{2000}-\x{200f}' .
229 '\x{2028}-\x{202f}' .
231 '\x{e000}-\x{f8ff}' .
236 throw new \RegistrationException(
elgg_echo(
'registration:invalidchars'));
241 $blacklist2 =
'\'/\\
"*& ?#%^(){}[]~?<>;|¬`@+='; 243 $blacklist2 = elgg_trigger_plugin_hook('username:character_blacklist', 'user', 244 array('blacklist' => $blacklist2), $blacklist2); 246 for ($n = 0; $n < strlen($blacklist2); $n++) { 247 if (strpos($username, $blacklist2[$n]) !== false) { 248 $msg = elgg_echo('registration:invalidchars', array($blacklist2[$n], $blacklist2)); 249 $msg = htmlspecialchars($msg, ENT_QUOTES, 'UTF-8'); 250 throw new \RegistrationException($msg); 255 return elgg_trigger_plugin_hook('registeruser:validate:username', 'all', 256 array('username' => $username), $result); 267 function validate_password($password) { 270 if (!isset($CONFIG->min_password_length)) { 271 $CONFIG->min_password_length = 6; 274 if (strlen($password) < $CONFIG->min_password_length) { 275 $msg = elgg_echo('registration:passwordtooshort', array($CONFIG->min_password_length)); 276 throw new \RegistrationException($msg); 280 return elgg_trigger_plugin_hook('registeruser:validate:password', 'all', 281 array('password' => $password), $result); 292 function validate_email_address($address) { 293 if (!is_email_address($address)) { 294 throw new \RegistrationException(elgg_echo('registration:notemail')); 297 // Got here, so lets try a hook (defaulting to ok) 299 return elgg_trigger_plugin_hook('registeruser:validate:email', 'all', 300 array('email' => $address), $result); 316 function register_user($username, $password, $name, $email, $allow_multiple_emails = false) { 317 return _elgg_services()->usersTable->register($username, $password, $name, $email, $allow_multiple_emails); 328 function generate_invite_code($username) { 329 return _elgg_services()->usersTable->generateInviteCode($username); 342 function elgg_validate_invite_code($username, $code) { 343 return _elgg_services()->usersTable->validateInviteCode($username, $code); 355 function elgg_set_user_validation_status($user_guid, $status, $method = '') { 356 return _elgg_services()->usersTable->setValidationStatus($user_guid, $status, $method); 366 function elgg_get_user_validation_status($user_guid) { 367 return _elgg_services()->usersTable->getValidationStatus($user_guid); 379 function elgg_user_account_page_handler($page_elements, $handler) { 381 $base_dir = elgg_get_root_path() . 'pages/account'; 384 require_once("$base_dir/
login.php
"); 386 case 'forgotpassword': 387 require_once("$base_dir/forgotten_password.php
"); 389 case 'changepassword': 390 require_once("$base_dir/change_password.php
"); 393 require_once("$base_dir/
register.php
"); 408 function set_last_action($user_guid) { 409 _elgg_services()->usersTable->setLastAction($user_guid); 419 function set_last_login($user_guid) { 420 _elgg_services()->usersTable->setLastLogin($user_guid); 433 function user_create_hook_add_site_relationship($event, $object_type, $object) { 434 add_entity_relationship($object->getGUID(), 'member_of_site', elgg_get_site_entity()->guid); 447 function user_avatar_hook($hook, $entity_type, $returnvalue, $params) { 448 $user = $params['entity']; 449 $size = $params['size']; 451 if (isset($user->icontime)) { 454 return "_graphics/icons/
user/
default{
$size}.gif
"; 462 function elgg_user_hover_menu($hook, $type, $return, $params) { 463 $user = $params['entity']; 464 /* @var \ElggUser $user */ 466 if (elgg_is_logged_in()) { 467 if (elgg_get_logged_in_user_guid() == $user->guid) { 469 $item = new \ElggMenuItem('profile:edit', elgg_echo('profile:edit'), $url); 470 $item->setSection('action'); 474 $item = new \ElggMenuItem('avatar:edit', elgg_echo('avatar:edit'), $url); 475 $item->setSection('action'); 480 // prevent admins from banning or deleting themselves 481 if (elgg_get_logged_in_user_guid() == $user->guid) { 485 if (elgg_is_admin_logged_in()) { 487 if (!$user->isBanned()) { 490 $actions[] = 'unban'; 492 $actions[] = 'delete'; 493 $actions[] = 'resetpassword'; 494 if (!$user->isAdmin()) { 495 $actions[] = 'makeadmin'; 497 $actions[] = 'removeadmin'; 500 foreach ($actions as $action) { 502 $url = elgg_add_action_tokens_to_url($url); 503 $item = new \ElggMenuItem($action, elgg_echo($action), $url); 504 $item->setSection('admin'); 505 $item->setConfirmText(true); 511 $item = new \ElggMenuItem('profile:edit', elgg_echo('profile:edit'), $url); 512 $item->setSection('admin'); 516 $item = new \ElggMenuItem('avatar:edit', elgg_echo('avatar:edit'), $url); 517 $item->setSection('admin'); 521 $item = new \ElggMenuItem('settings:edit', elgg_echo('settings:edit'), $url); 522 $item->setSection('admin'); 525 $url = "activity/owner/
$user->username
"; 526 $item = new \ElggMenuItem('activity:owner', elgg_echo('activity:owner'), $url); 527 $item->setSection('action'); 545 function elgg_users_setup_entity_menu($hook, $type, $return, $params) { 546 if (elgg_in_context('widgets')) { 550 $entity = $params['entity']; 551 if (!elgg_instanceof($entity, 'user')) { 554 /* @var \ElggUser $entity */ 556 if ($entity->isBanned()) { 557 $banned = elgg_echo('banned'); 564 $return = array(\ElggMenuItem::factory($options)); 567 $location = $entity->location; 568 if (is_string($location) && $location !== '') { 569 $location = htmlspecialchars($location, ENT_QUOTES, 'UTF-8', false); 571 'name' => 'location', 576 $return[] = \ElggMenuItem::factory($options); 591 function elgg_profile_fields_setup() { 594 $profile_defaults = array ( 595 'description' => 'longtext', 596 'briefdescription' => 'text', 597 'location' => 'location', 598 'interests' => 'tags', 600 'contactemail' => 'email', 607 $loaded_defaults = array(); 608 $fieldlist = elgg_get_config('profile_custom_fields'); 609 if ($fieldlist || $fieldlist === '0') { 610 $fieldlistarray = explode(',', $fieldlist); 611 foreach ($fieldlistarray as $listitem) { 612 if ($translation = elgg_get_config("admin_defined_profile_{$listitem}
")) { 613 $type = elgg_get_config("admin_defined_profile_type_{$listitem}
"); 614 $loaded_defaults["admin_defined_profile_{$listitem}
"] = $type; 615 add_translation(get_current_language(), array("profile:admin_defined_profile_{$listitem}
" => $translation)); 620 if (count($loaded_defaults)) { 621 $CONFIG->profile_using_custom = true; 622 $profile_defaults = $loaded_defaults; 625 $CONFIG->profile_fields = elgg_trigger_plugin_hook('profile:fields', 'profile', null, $profile_defaults); 627 // register any tag metadata names 628 foreach ($CONFIG->profile_fields as $name => $type) { 629 if ($type == 'tags' || $type == 'location' || $type == 'tag') { 630 elgg_register_tag_metadata_name($name); 631 // register a tag name translation 632 add_translation(get_current_language(), array("tag_names:
$name" => elgg_echo("profile:
$name"))); 647 function elgg_avatar_page_handler($page) { 650 $user = get_user_by_username($page[1]); 652 elgg_set_page_owner_guid($user->getGUID()); 655 if ($page[0] == 'edit') { 656 require_once("{$CONFIG->path}pages/
avatar/
edit.php
"); 659 set_input('size', $page[2]); 660 require_once("{$CONFIG->path}pages/
avatar/
view.php
"); 673 function elgg_profile_page_handler($page) { 676 $user = get_user_by_username($page[0]); 677 elgg_set_page_owner_guid($user->guid); 679 if ($page[1] == 'edit') { 680 require_once("{$CONFIG->path}pages/profile/
edit.php
"); 692 function users_pagesetup() { 694 $owner = elgg_get_page_owner_entity(); 695 $viewer = elgg_get_logged_in_user_entity(); 698 elgg_register_menu_item('page', array( 699 'name' => 'edit_avatar', 701 'text' => elgg_echo('avatar:edit'), 702 'section' => '1_profile', 703 'contexts' => array('settings'), 706 elgg_register_menu_item('page', array( 707 'name' => 'edit_profile', 709 'text' => elgg_echo('profile:edit'), 710 'section' => '1_profile', 711 'contexts' => array('settings'), 717 elgg_register_menu_item('topbar', array( 718 'name' => 'usersettings', 720 'text' => elgg_view_icon('settings') . elgg_echo('settings'), 725 elgg_register_menu_item('topbar', array( 728 'text' => elgg_echo('logout'), 742 function users_init() { 744 elgg_register_page_handler('register', 'elgg_user_account_page_handler'); 745 elgg_register_page_handler('forgotpassword', 'elgg_user_account_page_handler'); 746 elgg_register_page_handler('changepassword', 'elgg_user_account_page_handler'); 747 elgg_register_page_handler('login', 'elgg_user_account_page_handler'); 748 elgg_register_page_handler('avatar', 'elgg_avatar_page_handler'); 749 elgg_register_page_handler('profile', 'elgg_profile_page_handler'); 751 elgg_register_plugin_hook_handler('register', 'menu:user_hover', 'elgg_user_hover_menu'); 753 elgg_register_action('register', '', 'public'); 754 elgg_register_action('useradd', '', 'admin'); 755 elgg_register_action('avatar/upload'); 756 elgg_register_action('avatar/crop'); 757 elgg_register_action('avatar/remove'); 758 elgg_register_action('profile/edit'); 760 elgg_register_plugin_hook_handler('entity:icon:url', 'user', 'user_avatar_hook'); 762 elgg_register_action('user/changepassword', '', 'public'); 763 elgg_register_action('user/requestnewpassword', '', 'public'); 765 // Register the user type 766 elgg_register_entity_type('user', ''); 768 elgg_register_plugin_hook_handler('register', 'menu:entity', 'elgg_users_setup_entity_menu', 501); 770 elgg_register_event_handler('create', 'user', 'user_create_hook_add_site_relationship'); 784 function users_test($hook, $type, $value, $params) { 786 $value[] = "{$CONFIG->path}engine/tests/ElggUserTest.php
"; 790 return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) { 791 $events->registerHandler('init', 'system', 'users_init', 0); 792 $events->registerHandler('init', 'system', 'elgg_profile_fields_setup', 10000); // Ensure this runs after other plugins 793 $events->registerHandler('pagesetup', 'system', 'users_pagesetup', 0); 794 $hooks->registerHandler('unit_test', 'system', 'users_test'); execute_new_password_request($user_guid, $conf_code, $password=null)
Validate and change password for a user.
$CONFIG view
The current view type.
send_new_password_request($user_guid)
Generate and send a password request email to a given user's registered email address.
get_user_by_email($email)
Get an array of users from an email address.
make_user_admin($user_guid)
Makes user $guid an admin.
if($guid==elgg_get_logged_in_user_guid()) $name
const CHARS_PASSWORD
Character set for temp passwords (no risk of embedded profanity/glyphs that look similar) ...
force_user_password_reset($user_guid, $password)
Low level function to reset a given user's password.
find_active_users($options=array(), $limit=10, $offset=0, $count=false)
Return users (or the number of them) who have been active within a recent period. ...
validate_username($username)
Simple function which ensures that a username contains only valid characters.
$guid
Removes an admin notice.
unban_user($user_guid)
Unban a user.
get_user_by_username($username)
Get user by username.
disable_user_entities($owner_guid)
Disables all of a user's entities.
ban_user($user_guid, $reason="")
Ban a user.
get_user_by_code($hash)
Get user by persistent login password.
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
get_user($guid)
Get a user object from a GUID.
get_user_entity_as_row($guid)
Return the user specific details of a user by a row.
elgg global
Pointer to the global context.
logout()
Log the current user out.
login(\ElggUser $user, $persistent=false)
Logs in a specified .
generate_random_cleartext_password()
Generate a random 12 character clear text password.
$user_guid
Avatar remove action.
remove_user_admin($user_guid)
Removes user $guid's admin flag.