209 if (!isset(
$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) {
383 echo elgg_view_resource("account/
login");
385 case 'forgotpassword':
386 echo elgg_view_resource("account/forgotten_password
");
388 case 'changepassword':
389 echo elgg_view_resource("account/change_password
");
392 echo elgg_view_resource("account/
register");
411 function elgg_get_registration_url(array $query = [], $fragment = '') {
412 $url = elgg_normalize_url('register');
413 $url = elgg_http_add_url_query_elements($url, $query) . $fragment;
414 return elgg_trigger_plugin_hook('registration_url', 'site', $query, $url);
426 function elgg_get_login_url(array $query = [], $fragment = '') {
427 $url = elgg_normalize_url('login');
428 $url = elgg_http_add_url_query_elements($url, $query) . $fragment;
429 return elgg_trigger_plugin_hook('login_url', 'site', $query, $url);
438 function set_last_action($user_guid) {
439 $user = get_user($user_guid);
443 _elgg_services()->usersTable->setLastAction($user);
452 function set_last_login($user_guid) {
453 $user = get_user($user_guid);
457 _elgg_services()->usersTable->setLastLogin($user);
470 function user_create_hook_add_site_relationship($event, $object_type, $object) {
471 add_entity_relationship($object->getGUID(), 'member_of_site', elgg_get_site_entity()->guid);
484 function user_avatar_hook($hook, $entity_type, $returnvalue, $params) {
485 $user = elgg_extract('entity', $params);
486 $size = elgg_extract('size', $params, 'medium');
488 if (!$user instanceof ElggUser) {
492 $default_url = elgg_get_simplecache_url("icons/
user/
default{
$size}.gif
");
493 if (!isset($user->icontime)) {
497 if (_elgg_view_may_be_altered('resources/avatar/view', 'resources/avatar/view.php')) {
498 // For BC with 2.0 if a plugin is suspected of using this view/page handler we need to use it.
499 // /avatar page handler will issue a deprecation notice.
503 $filehandler = new ElggFile();
504 $filehandler->owner_guid = $user->guid;
505 $filehandler->setFilename("profile/{
$user->guid}{
$size}.jpg
");
506 $use_cookie = elgg_get_config('walled_garden'); // don't serve avatars with public URLs in a walled garden mode
507 $avatar_url = elgg_get_inline_url($filehandler, $use_cookie);
509 return $avatar_url ? : $default_url;
516 function elgg_user_hover_menu($hook, $type, $return, $params) {
517 $user = elgg_extract('entity', $params);
518 /* @var \ElggUser $user */
520 if (!$user instanceof \ElggUser) {
524 if (!elgg_is_logged_in()) {
528 if (elgg_get_logged_in_user_guid() == $user->guid) {
530 $item = new \ElggMenuItem('profile:edit', elgg_echo('profile:edit'), $url);
531 $item->setSection('action');
535 $item = new \ElggMenuItem('avatar:edit', elgg_echo('avatar:edit'), $url);
536 $item->setSection('action');
540 // prevent admins from banning or deleting themselves
541 if (elgg_get_logged_in_user_guid() == $user->guid) {
545 if (elgg_is_admin_logged_in()) {
547 if (!$user->isBanned()) {
550 $actions[] = 'unban';
552 $actions[] = 'delete';
553 $actions[] = 'resetpassword';
554 if (!$user->isAdmin()) {
555 $actions[] = 'makeadmin';
557 $actions[] = 'removeadmin';
560 foreach ($actions as $action) {
562 $url = elgg_add_action_tokens_to_url($url);
563 $item = new \ElggMenuItem($action, elgg_echo($action), $url);
564 $item->setSection('admin');
565 $item->setConfirmText(true);
571 $item = new \ElggMenuItem('profile:edit', elgg_echo('profile:edit'), $url);
572 $item->setSection('admin');
576 $item = new \ElggMenuItem('avatar:edit', elgg_echo('avatar:edit'), $url);
577 $item->setSection('admin');
581 $item = new \ElggMenuItem('settings:edit', elgg_echo('settings:edit'), $url);
582 $item->setSection('admin');
585 $url = "activity/owner/
$user->username
";
586 $item = new \ElggMenuItem('activity:owner', elgg_echo('activity:owner'), $url);
587 $item->setSection('action');
605 function elgg_users_setup_entity_menu($hook, $type, $return, $params) {
606 if (elgg_in_context('widgets')) {
610 $entity = $params['entity'];
611 if (!elgg_instanceof($entity, 'user')) {
614 /* @var \ElggUser $entity */
616 if ($entity->isBanned()) {
617 $banned = elgg_echo('banned');
624 $return = array(\ElggMenuItem::factory($options));
627 $location = $entity->location;
628 if (is_string($location) && $location !== '') {
629 $location = htmlspecialchars($location, ENT_QUOTES, 'UTF-8', false);
631 'name' => 'location',
636 $return[] = \ElggMenuItem::factory($options);
651 function elgg_profile_fields_setup() {
654 $profile_defaults = array (
655 'description' => 'longtext',
656 'briefdescription' => 'text',
657 'location' => 'location',
658 'interests' => 'tags',
660 'contactemail' => 'email',
667 $loaded_defaults = array();
668 $fieldlist = elgg_get_config('profile_custom_fields');
669 if ($fieldlist || $fieldlist === '0') {
670 $fieldlistarray = explode(',', $fieldlist);
671 foreach ($fieldlistarray as $listitem) {
672 if ($translation = elgg_get_config("admin_defined_profile_{$listitem}
")) {
673 $type = elgg_get_config("admin_defined_profile_type_{$listitem}
");
674 $loaded_defaults["admin_defined_profile_{$listitem}
"] = $type;
675 add_translation(get_current_language(), array("profile:admin_defined_profile_{$listitem}
" => $translation));
680 if (count($loaded_defaults)) {
681 $CONFIG->profile_using_custom = true;
682 $profile_defaults = $loaded_defaults;
685 $CONFIG->profile_fields = elgg_trigger_plugin_hook('profile:fields', 'profile', null, $profile_defaults);
687 // register any tag metadata names
688 foreach ($CONFIG->profile_fields as $name => $type) {
689 if ($type == 'tags' || $type == 'location' || $type == 'tag') {
690 elgg_register_tag_metadata_name($name);
691 // register a tag name translation
692 add_translation(get_current_language(), array("tag_names:
$name" => elgg_echo("profile:
$name")));
706 function elgg_avatar_page_handler($page) {
707 $user = get_user_by_username(elgg_extract(1, $page));
709 elgg_set_page_owner_guid($user->getGUID());
712 if ($page[0] == 'edit') {
713 echo elgg_view_resource("avatar/
edit");
715 elgg_deprecated_notice("/avatar/
view page handler has been deprecated and will be removed. Use
elgg_get_inline_url() instead.", '2.2');
735 if ($page[1] ==
'edit') {
755 'name' =>
'edit_avatar',
756 'href' =>
"avatar/edit/{$owner->username}",
758 'section' =>
'1_profile',
759 'contexts' => array(
'settings'),
763 'name' =>
'edit_profile',
764 'href' =>
"profile/{$owner->username}/edit",
766 'section' =>
'1_profile',
767 'contexts' => array(
'settings'),
774 'name' =>
'usersettings',
775 'href' =>
"settings/user/{$viewer->username}",
783 'href' =>
"action/logout",
807 $icon->setFilename(
"profile/{$entity->guid}{$size}.jpg");
864 $value[] =
"{$CONFIG->path}engine/tests/ElggUserTest.php";
869 $events->registerHandler(
'init',
'system',
'users_init', 0);
870 $events->registerHandler(
'init',
'system',
'elgg_profile_fields_setup', 10000);
871 $events->registerHandler(
'pagesetup',
'system',
'users_pagesetup', 0);
872 $hooks->registerHandler(
'unit_test',
'system',
'users_test');
elgg_register_action($action, $filename="", $access='logged_in')
Registers an action.
if($guid==elgg_get_logged_in_user_guid()) $name
elgg button elgg button action
$user_guid
Avatar remove action.
const CHARS_PASSWORD
Character set for temp passwords (no risk of embedded profanity/glyphs that look similar)
$CONFIG view
The current view type.
$guid
Removes an admin notice.
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
elgg_register_plugin_hook_handler($hook, $type, $callback, $priority=500)
elgg_register_event_handler($event, $object_type, $callback, $priority=500)
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
elgg_register_entity_type($type, $subtype=null)
Registers an entity type and subtype as a public-facing entity that should be shown in search and by ...
if(! $display_name) $type
elgg_get_inline_url(\ElggFile $file, $use_cookie=false, $expires='')
Returns file's URL for inline display Suitable for displaying cacheable resources,...
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
elgg_view_resource($name, array $vars=[])
Render a resource view.
elgg_view_icon($name, $vars=array())
View one of the icons.
elgg_register_menu_item($menu_name, $menu_item)
Register an item for an Elgg menu.
elgg_register_page_handler($identifier, $function)
Registers a page handler for a particular identifier.
elgg_get_page_owner_entity()
Gets the owner entity for the current page.
elgg_set_page_owner_guid($guid)
Set the guid of the entity that owns this page.
login(\ElggUser $user, $persistent=false)
Logs in a specified \ElggUser.
elgg_get_logged_in_user_entity()
Return the current logged in user, or null if no user is logged in.
get_user_by_code($hash)
Get user by persistent login password.
force_user_password_reset($user_guid, $password)
Low level function to reset a given user's password.
elgg_profile_page_handler($page)
Profile page handler.
users_init()
Users initialisation function, which establishes the page handler.
users_test($hook, $type, $value, $params)
Runs unit tests for \ElggUser.
unban_user($user_guid)
Unban a user.
users_pagesetup()
Sets up user-related menu items.
get_user_entity_as_row($guid)
Return the user specific details of a user by a row.
disable_user_entities($owner_guid)
Disables all of a user's entities.
return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks)
execute_new_password_request($user_guid, $conf_code, $password=null)
Validate and change password for a user.
_elgg_user_set_icon_file($hook, $type, $icon, $params)
Set user icon file.
get_user_by_email($email)
Get an array of users from an email address.
get_user($guid)
Get a user object from a GUID.
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.
generate_random_cleartext_password()
Generate a random 12 character clear text password.
validate_username($username)
Simple function which ensures that a username contains only valid characters.
get_user_by_username($username)
Get user by username.
send_new_password_request($user_guid)
Generate and send a password request email to a given user's registered email address.
make_user_admin($user_guid)
Makes user $guid an admin.
remove_user_admin($user_guid)
Removes user $guid's admin flag.
ban_user($user_guid, $reason="")
Ban a user.