30 return get_data_row(
"SELECT * from {$CONFIG->dbprefix}users_entity where guid=$guid");
46 $query =
"UPDATE {$CONFIG->dbprefix}entities
47 set enabled='no' where owner_guid={$owner_guid}
48 or container_guid = {$owner_guid}";
82 static $newentity_cache;
87 if ($newentity_cache) {
92 $query =
"UPDATE {$CONFIG->dbprefix}users_entity set banned='yes' where guid=$user_guid";
121 static $newentity_cache;
123 $newentity_cache =
new ElggMemcache(
'new_entity_cache');
126 if ($newentity_cache) {
131 $query =
"UPDATE {$CONFIG->dbprefix}users_entity set banned='no' where guid=$user_guid";
157 static $newentity_cache;
159 $newentity_cache =
new ElggMemcache(
'new_entity_cache');
162 if ($newentity_cache) {
166 $r =
update_data(
"UPDATE {$CONFIG->dbprefix}users_entity set admin='yes' where guid=$user_guid");
193 static $newentity_cache;
195 $newentity_cache =
new ElggMemcache(
'new_entity_cache');
198 if ($newentity_cache) {
202 $r =
update_data(
"UPDATE {$CONFIG->dbprefix}users_entity set admin='no' where guid=$user_guid");
263 $query =
"SELECT e.* FROM {$CONFIG->dbprefix}users_entity u
264 JOIN {$CONFIG->dbprefix}entities e ON e.guid = u.guid
265 WHERE u.username = '$username' AND $access";
302 $query =
"SELECT e.* FROM {$CONFIG->dbprefix}entities e
303 JOIN {$CONFIG->dbprefix}users_entity u ON e.guid = u.guid
304 WHERE email = '$email' AND $access";
306 return get_data($query,
'entity_row_to_elggstar');
340 'seconds' => $seconds,
347 foreach (array(
'seconds',
'limit',
'offset') as
$key) {
362 if (
$data !==
null) {
367 $time = time() -
$options[
'seconds'];
373 'joins' => array(
"join {$dbprefix}users_entity u on e.guid = u.guid"),
374 'wheres' => array(
"u.last_action >= {$time}"),
375 'order_by' =>
"u.last_action desc",
393 $user->setPrivateSetting(
'passwd_conf_code',
$code);
394 $user->setPrivateSetting(
'passwd_conf_time', time());
436 $user->password = $hash;
470 $saved_code =
$user->getPrivateSetting(
'passwd_conf_code');
471 $code_time = (int)
$user->getPrivateSetting(
'passwd_conf_time');
473 if (!$saved_code || $saved_code != $conf_code) {
478 if (!$code_time || $code_time < time() - 24 * 60 * 60) {
488 $ns =
$reset ?
'resetpassword' :
'changepassword';
549 if (!isset(
$CONFIG->minusername)) {
554 $msg =
elgg_echo(
'registration:usernametooshort', array(
$CONFIG->minusername));
560 $msg =
elgg_echo(
'registration:usernametoolong', array(128));
566 '\x{0080}-\x{009f}' .
568 '\x{2000}-\x{200f}' .
569 '\x{2028}-\x{202f}' .
571 '\x{e000}-\x{f8ff}' .
581 $blacklist2 =
'\'/\\
"*& ?#%^(){}[]~?<>;|¬`@-+=';
583 for ($n = 0; $n < strlen($blacklist2); $n++) {
584 if (strpos($username, $blacklist2[$n]) !== false) {
585 $msg = elgg_echo('registration:invalidchars', array($blacklist2[$n], $blacklist2));
586 $msg = htmlspecialchars($msg, ENT_QUOTES, 'UTF-8');
587 throw new RegistrationException($msg);
592 return elgg_trigger_plugin_hook('registeruser:validate:username', 'all',
593 array('username' => $username), $result);
604 function validate_password($password) {
607 if (!isset($CONFIG->min_password_length)) {
608 $CONFIG->min_password_length = 6;
611 if (strlen($password) < $CONFIG->min_password_length) {
612 $msg = elgg_echo('registration:passwordtooshort', array($CONFIG->min_password_length));
613 throw new RegistrationException($msg);
617 return elgg_trigger_plugin_hook('registeruser:validate:password', 'all',
618 array('password' => $password), $result);
629 function validate_email_address($address) {
630 if (!is_email_address($address)) {
631 throw new RegistrationException(elgg_echo('registration:notemail'));
634 // Got here, so lets try a hook (defaulting to ok)
636 return elgg_trigger_plugin_hook('registeruser:validate:email', 'all',
637 array('email' => $address), $result);
653 function register_user($username, $password, $name, $email, $allow_multiple_emails = false) {
655 // no need to trim password.
656 $username = trim($username);
657 $name = trim(strip_tags($name));
658 $email = trim($email);
660 // A little sanity checking
668 // Make sure a user with conflicting details hasn't registered and been disabled
669 $access_status = access_get_show_hidden_status();
670 access_show_hidden_entities(true);
672 if (!validate_email_address($email)) {
673 throw new RegistrationException(elgg_echo('registration:emailnotvalid'));
676 if (!validate_password($password)) {
677 throw new RegistrationException(elgg_echo('registration:passwordnotvalid'));
680 if (!validate_username($username)) {
681 throw new RegistrationException(elgg_echo('registration:usernamenotvalid'));
684 if ($user = get_user_by_username($username)) {
685 throw new RegistrationException(elgg_echo('registration:userexists'));
688 if ((!$allow_multiple_emails) && (get_user_by_email($email))) {
689 throw new RegistrationException(elgg_echo('registration:dupeemail'));
692 access_show_hidden_entities($access_status);
695 $user = new ElggUser();
696 $user->username = $username;
697 $user->email = $email;
699 $user->access_id = ACCESS_PUBLIC;
700 $user->salt = _elgg_generate_password_salt();
701 $user->password = generate_user_password($user, $password);
702 $user->owner_guid = 0; // Users aren't owned by anyone, even if they are admin created.
703 $user->container_guid = 0; // Users aren't contained by anyone, even if they are admin created.
704 $user->language = get_current_language();
705 if ($user->save() === false) {
709 // Turn on email notifications by default
710 set_user_notification_setting($user->getGUID(), 'email', true);
712 return $user->getGUID();
722 function generate_invite_code($username) {
723 $secret = datalist_get('__site_secret__');
724 return md5($username . $secret);
736 function elgg_set_user_validation_status($user_guid, $status, $method = '') {
737 $result1 = create_metadata($user_guid, 'validated', $status, '', 0, ACCESS_PUBLIC, false);
738 $result2 = create_metadata($user_guid, 'validated_method', $method, '', 0, ACCESS_PUBLIC, false);
739 if ($result1 && $result2) {
753 function elgg_get_user_validation_status($user_guid) {
754 $md = elgg_get_metadata(array(
755 'guid' => $user_guid,
756 'metadata_name' => 'validated'
778 function elgg_user_account_page_handler($page_elements, $handler) {
780 $base_dir = elgg_get_root_path() . 'pages/account';
783 require_once("$base_dir/
login.php
");
785 case 'forgotpassword':
786 require_once("$base_dir/forgotten_password.php
");
788 case 'changepassword':
789 require_once("$base_dir/change_password.php
");
792 require_once("$base_dir/
register.php
");
807 function set_last_action($user_guid) {
808 $user_guid = (int) $user_guid;
812 $query = "UPDATE {
$CONFIG->dbprefix}users_entity
813 set prev_last_action = last_action,
814 last_action = {$time} where guid = {
$user_guid}
";
816 execute_delayed_write_query($query);
826 function set_last_login($user_guid) {
827 $user_guid = (int) $user_guid;
831 $query = "UPDATE {
$CONFIG->dbprefix}users_entity
832 set prev_last_login = last_login, last_login = {$time} where guid = {
$user_guid}
";
834 execute_delayed_write_query($query);
847 function user_create_hook_add_site_relationship($event, $object_type, $object) {
848 add_entity_relationship($object->getGUID(), 'member_of_site', elgg_get_site_entity()->guid);
861 function user_avatar_hook($hook, $entity_type, $returnvalue, $params) {
862 $user = $params['entity'];
863 $size = $params['size'];
865 if (isset($user->icontime)) {
868 return "_graphics/icons/
user/
default{
$size}.gif
";
876 function elgg_user_hover_menu($hook, $type, $return, $params) {
877 $user = $params['entity'];
878 /* @var ElggUser $user */
880 if (elgg_is_logged_in()) {
881 if (elgg_get_logged_in_user_guid() == $user->guid) {
883 $item = new ElggMenuItem('profile:edit', elgg_echo('profile:edit'), $url);
884 $item->setSection('action');
888 $item = new ElggMenuItem('avatar:edit', elgg_echo('avatar:edit'), $url);
889 $item->setSection('action');
894 // prevent admins from banning or deleting themselves
895 if (elgg_get_logged_in_user_guid() == $user->guid) {
899 if (elgg_is_admin_logged_in()) {
901 if (!$user->isBanned()) {
904 $actions[] = 'unban';
906 $actions[] = 'delete';
907 $actions[] = 'resetpassword';
908 if (!$user->isAdmin()) {
909 $actions[] = 'makeadmin';
911 $actions[] = 'removeadmin';
914 foreach ($actions as $action) {
916 $url = elgg_add_action_tokens_to_url($url);
917 $item = new ElggMenuItem($action, elgg_echo($action), $url);
918 $item->setSection('admin');
919 $item->setLinkClass('elgg-requires-confirmation');
925 $item = new ElggMenuItem('profile:edit', elgg_echo('profile:edit'), $url);
926 $item->setSection('admin');
930 $item = new ElggMenuItem('settings:edit', elgg_echo('settings:edit'), $url);
931 $item->setSection('admin');
934 $url = "activity/owner/
$user->username
";
935 $item = new ElggMenuItem('activity:owner', elgg_echo('activity:owner'), $url);
936 $item->setSection('action');
954 function elgg_users_setup_entity_menu($hook, $type, $return, $params) {
955 if (elgg_in_context('widgets')) {
959 $entity = $params['entity'];
960 if (!elgg_instanceof($entity, 'user')) {
963 /* @var ElggUser $entity */
965 if ($entity->isBanned()) {
966 $banned = elgg_echo('banned');
973 $return = array(ElggMenuItem::factory($options));
976 if (isset($entity->location)) {
977 $location = htmlspecialchars($entity->location, ENT_QUOTES, 'UTF-8', false);
979 'name' => 'location',
984 $return[] = ElggMenuItem::factory($options);
999 function elgg_profile_fields_setup() {
1002 $profile_defaults = array (
1003 'description' => 'longtext',
1004 'briefdescription' => 'text',
1005 'location' => 'location',
1006 'interests' => 'tags',
1008 'contactemail' => 'email',
1012 'twitter' => 'text',
1015 $loaded_defaults = array();
1016 $fieldlist = elgg_get_config('profile_custom_fields');
1017 if ($fieldlist || $fieldlist === '0') {
1018 $fieldlistarray = explode(',', $fieldlist);
1019 foreach ($fieldlistarray as $listitem) {
1020 if ($translation = elgg_get_config("admin_defined_profile_{$listitem}
")) {
1021 $type = elgg_get_config("admin_defined_profile_type_{$listitem}
");
1022 $loaded_defaults["admin_defined_profile_{$listitem}
"] = $type;
1023 add_translation(get_current_language(), array("profile:admin_defined_profile_{$listitem}
" => $translation));
1028 if (count($loaded_defaults)) {
1029 $CONFIG->profile_using_custom = true;
1030 $profile_defaults = $loaded_defaults;
1033 $CONFIG->profile_fields = elgg_trigger_plugin_hook('profile:fields', 'profile', null, $profile_defaults);
1035 // register any tag metadata names
1036 foreach ($CONFIG->profile_fields as $name => $type) {
1037 if ($type == 'tags' || $type == 'location' || $type == 'tag') {
1038 elgg_register_tag_metadata_name($name);
1039 // register a tag name translation
1040 add_translation(get_current_language(), array("tag_names:
$name" => elgg_echo("profile:
$name")));
1055 function elgg_avatar_page_handler($page) {
1058 $user = get_user_by_username($page[1]);
1060 elgg_set_page_owner_guid($user->getGUID());
1063 if ($page[0] == 'edit') {
1064 require_once("{
$CONFIG->path}pages/avatar/
edit.php
");
1067 set_input('size', $page[2]);
1068 require_once("{
$CONFIG->path}pages/avatar/
view.php
");
1081 function elgg_profile_page_handler($page) {
1084 $user = get_user_by_username($page[0]);
1085 elgg_set_page_owner_guid($user->guid);
1087 if ($page[1] == 'edit') {
1088 require_once("{
$CONFIG->path}pages/profile/
edit.php
");
1100 function users_pagesetup() {
1102 $owner = elgg_get_page_owner_entity();
1103 $viewer = elgg_get_logged_in_user_entity();
1106 elgg_register_menu_item('page', array(
1107 'name' => 'edit_avatar',
1109 'text' => elgg_echo('avatar:edit'),
1110 'section' => '1_profile',
1111 'contexts' => array('settings'),
1114 elgg_register_menu_item('page', array(
1115 'name' => 'edit_profile',
1117 'text' => elgg_echo('profile:edit'),
1118 'section' => '1_profile',
1119 'contexts' => array('settings'),
1125 elgg_register_menu_item('topbar', array(
1126 'name' => 'profile',
1127 'href' => $viewer->getURL(),
1128 'text' => elgg_view('output/img', array(
1129 'src' => $viewer->getIconURL('topbar'),
1130 'alt' => $viewer->name,
1131 'title' => elgg_echo('profile'),
1132 'class' => 'elgg-border-plain elgg-transition',
1135 'link_class' => 'elgg-topbar-avatar',
1138 elgg_register_menu_item('topbar', array(
1139 'name' => 'usersettings',
1141 'text' => elgg_view_icon('settings') . elgg_echo('settings'),
1146 elgg_register_menu_item('topbar', array(
1149 'text' => elgg_echo('logout'),
1150 'is_action' => true,
1163 function users_init() {
1165 elgg_register_page_handler('register', 'elgg_user_account_page_handler');
1166 elgg_register_page_handler('forgotpassword', 'elgg_user_account_page_handler');
1167 elgg_register_page_handler('changepassword', 'elgg_user_account_page_handler');
1168 elgg_register_page_handler('login', 'elgg_user_account_page_handler');
1169 elgg_register_page_handler('avatar', 'elgg_avatar_page_handler');
1170 elgg_register_page_handler('profile', 'elgg_profile_page_handler');
1172 elgg_register_plugin_hook_handler('register', 'menu:user_hover', 'elgg_user_hover_menu');
1174 elgg_register_action('register', '', 'public');
1175 elgg_register_action('useradd', '', 'admin');
1176 elgg_register_action('avatar/upload');
1177 elgg_register_action('avatar/crop');
1178 elgg_register_action('avatar/remove');
1179 elgg_register_action('profile/edit');
1181 elgg_register_plugin_hook_handler('entity:icon:url', 'user', 'user_avatar_hook');
1183 elgg_register_action('user/changepassword', '', 'public');
1184 elgg_register_action('user/requestnewpassword', '', 'public');
1186 // Register the user type
1187 elgg_register_entity_type('user', '');
1189 elgg_register_plugin_hook_handler('register', 'menu:entity', 'elgg_users_setup_entity_menu', 501);
1191 elgg_register_event_handler('create', 'user', 'user_create_hook_add_site_relationship');
1205 function users_test($hook, $type, $value, $params) {
1207 $value[] = "{
$CONFIG->path}engine/tests/ElggUserTest.php
";
1211 elgg_register_event_handler('init', 'system', 'users_init', 0);
1212 elgg_register_event_handler('init', 'system', 'elgg_profile_fields_setup', 10000); // Ensure this runs after other plugins
1213 elgg_register_event_handler('pagesetup', 'system', 'users_pagesetup', 0);
1214 elgg_register_plugin_hook_handler('unit_test', 'system', 'users_test');
if($guid==elgg_get_logged_in_user_guid()) $name
$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.
elgg_get_site_url($site_guid=0)
Get the URL for the current (or specified) site.
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
$guid
Removes an admin notice.
elgg_trigger_event($event, $object_type, $object=null)
Trigger an Elgg Event and attempt to run all handler callbacks registered to that event,...
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
Trigger a Plugin Hook and run all handler callbacks registered to that hook:type.
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Sends a notice about deprecated use of a function, view, etc.
elgg_set_ignore_access($ignore=true)
Set if Elgg's access system should be ignored.
_elgg_get_access_where_sql(array $options=array())
Returns the SQL where clause for enforcing read access to data.
sanitise_string($string)
Wrapper function for alternate English spelling (.
update_data($query)
Update a row in the database.
get_data_row($query, $callback="")
Retrieve a single row from the database.
get_data($query, $callback="")
Retrieve rows from the database.
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
elgg_instanceof($entity, $type=null, $subtype=null, $class=null)
Checks if $entity is an ElggEntity and optionally for type and subtype.
get_entity($guid)
Loads and returns an entity object from a guid.
_elgg_invalidate_cache_for_entity($guid)
Invalidate this class's entry in the cache.
_elgg_retrieve_cached_entity($guid)
Retrieve a entity from the cache.
elgg_get_entities(array $options=array())
Returns an array of entities with optional filtering.
is_memcache_available()
Return true if memcache is available and configured.
notify_user($to, $from, $subject, $message, array $params=array(), $methods_override="")
Notify a user via their preferences.
remove_private_setting($entity_guid, $name)
Deletes a private setting for an entity.
logout()
Log the current user out.
reset_login_failure_count($user_guid)
Resets the fail login count for $user_guid.
login(ElggUser $user, $persistent=false)
Logs in a specified ElggUser.
elgg_get_site_entity($site_guid=0)
Get an ElggSite entity (default is current site)
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.
unban_user($user_guid)
Unban a user.
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.
_elgg_generate_password_salt()
Generate an 8 character Base64 URL salt for the password.
execute_new_password_request($user_guid, $conf_code, $password=null)
Validate and change password for a user.
get_user_by_email($email)
Get an array of users from an email address.
get_user($guid)
Get a user object from a GUID.
global $USERNAME_TO_GUID_MAP_CACHE
Map a username to a cached 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.
generate_user_password(ElggUser $user, $password)
Hash a password for storage.
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.
elgg button elgg button action