Elgg  Version 6.0
users.php
Go to the documentation of this file.
1 <?php
16 function get_user(int $guid): ?\ElggUser {
17  try {
18  return _elgg_services()->entityTable->get($guid, 'user');
19  } catch (\Elgg\Exceptions\DomainException $ex) {
20  elgg_log($ex, 'ERROR');
21 
22  return null;
23  } catch (\Elgg\Exceptions\ClassException $ex) {
24  elgg_log($ex, 'ERROR');
25 
26  return null;
27  }
28 }
29 
39 function elgg_get_user_by_username(string $username, bool $try_email = false): ?\ElggUser {
40  if (empty($username)) {
41  return null;
42  }
43 
44  if ($try_email && elgg_is_valid_email($username)) {
45  $user = elgg_get_user_by_email($username);
46  if ($user instanceof \ElggUser) {
47  return $user;
48  }
49  }
50 
51  // Fixes #6052. Username is frequently sniffed from the path info, which,
52  // unlike $_GET, is not URL decoded. If the username was not URL encoded,
53  // this is harmless.
54  $username = rawurldecode($username);
55  if (empty($username)) {
56  return null;
57  }
58 
59  $logged_in_user = elgg_get_logged_in_user_entity();
60  if (!empty($logged_in_user) && ($logged_in_user->username === $username)) {
61  return $logged_in_user;
62  }
63 
65  'types' => 'user',
66  'metadata_name_value_pairs' => [
67  [
68  'name' => 'username',
69  'value' => $username,
70  'case_sensitive' => false,
71  ],
72  ],
73  'limit' => 1,
74  ]);
75 
76  return $users ? $users[0] : null;
77 }
78 
87 function elgg_get_user_by_email(string $email): ?\ElggUser {
88  if (empty($email)) {
89  return null;
90  }
91 
93  'types' => 'user',
94  'metadata_name_value_pairs' => [
95  [
96  'name' => 'email',
97  'value' => $email,
98  'case_sensitive' => false,
99  ],
100  ],
101  'limit' => 1,
102  ]);
103 
104  return $users ? $users[0] : null;
105 }
106 
117  _elgg_services()->passwords->requestNewPassword($user);
118 }
119 
131 function elgg_save_new_password(\ElggUser $user, string $conf_code, string $password = null): bool {
132  return _elgg_services()->passwords->saveNewPassword($user, $conf_code, $password);
133 }
134 
142 function elgg_generate_password(): string {
143  return _elgg_services()->passwordGenerator->generatePassword();
144 }
145 
162 function elgg_register_user(array $params = []): \ElggUser {
163  return _elgg_services()->accounts->register($params);
164 }
165 
179 function elgg_validate_registration_data(string $username, string|array $password, string $name, string $email, bool $allow_multiple_emails = false): \Elgg\Validation\ValidationResults {
180  return _elgg_services()->accounts->validateAccountData($username, $password, $name, $email, $allow_multiple_emails);
181 }
182 
192 function elgg_generate_invite_code(string $username): string {
193  return _elgg_services()->hmac->generateInviteCode($username);
194 }
195 
206 function elgg_validate_invite_code(string $username, string $code): bool {
207  return _elgg_services()->hmac->validateInviteCode($username, $code);
208 }
209 
221 function elgg_get_registration_url(array $parameters = [], string $fragment = ''): string {
222  $url = elgg_generate_url('account:register', $parameters) . $fragment;
223 
224  return (string) elgg_trigger_event_results('registration_url', 'site', $parameters, $url);
225 }
226 
236 function elgg_get_login_url(array $query = [], string $fragment = ''): string {
237  $url = elgg_generate_url('account:login');
239  return (string) elgg_trigger_event_results('login_url', 'site', $query, $url);
240 }
241 
253  return _elgg_services()->persistentLogin->getUserFromToken($token);
254 }
elgg_validate_invite_code(string $username, string $code)
Validate a user&#39;s invite code.
Definition: users.php:206
$params
Saves global plugin settings.
Definition: save.php:13
if(empty($user_guids)) $users
Definition: ban.php:12
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
elgg_generate_password()
Generate a random 12 character clear text password.
Definition: users.php:142
elgg_get_user_by_username(string $username, bool $try_email=false)
Get a user by username.
Definition: users.php:39
elgg_get_login_url(array $query=[], string $fragment= '')
Returns site&#39;s login URL Triggers a &#39;login_url&#39;, &#39;site&#39; event that can be used by plugins to alter th...
Definition: users.php:236
elgg_save_new_password(\ElggUser $user, string $conf_code, string $password=null)
Validate and change password for a user.
Definition: users.php:131
elgg_get_user_by_persistent_token(string $token)
Get a user based on a persistent login token.
Definition: users.php:252
elgg_register_user(array $params=[])
Registers a user.
Definition: users.php:162
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
Definition: LICENSE.txt:215
$email
Definition: change_email.php:7
$username
Definition: delete.php:23
elgg_trigger_event_results(string $event, string $type, array $params=[], $returnvalue=null)
Triggers an event where it is expected that the mixed return value could be manipulated by event call...
Definition: events.php:117
if(!$user||!$user->canEdit()) $password
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
Definition: entities.php:507
elgg_validate_registration_data(string $username, string|array $password, string $name, string $email, bool $allow_multiple_emails=false)
Assert that given registration details are valid and can be used to register the user.
Definition: users.php:179
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
Definition: elgglib.php:86
elgg_get_registration_url(array $parameters=[], string $fragment= '')
Returns site&#39;s registration URL Triggers a &#39;registration_url&#39;, &#39;site&#39; event that can be used by plugi...
Definition: users.php:221
elgg_http_add_url_query_elements(string $url, array $elements)
Sets elements in a URL&#39;s query string.
Definition: elgglib.php:181
$user
Definition: users.php:11
$token
get_user(int $guid)
Elgg users Functions to manage multiple or single users in an Elgg install.
Definition: users.php:16
elgg_get_user_by_email(string $email)
Get a user from an email address.
Definition: users.php:87
elgg_generate_invite_code(string $username)
Generates a unique invite code for a user.
Definition: users.php:192
elgg_is_valid_email(string $address)
Validates an email address.
Definition: input.php:89
$query
foreach($plugin_guids as $guid) if(empty($deactivated_plugins)) $url
Definition: deactivate.php:39
elgg_request_new_password(\ElggUser $user)
Generate and send a password request email to a given user&#39;s registered email address.
Definition: users.php:116
elgg_generate_url(string $name, array $parameters=[])
Generate a URL for named route.
_elgg_services()
Get the global service provider.
Definition: elgglib.php:351
elgg_get_logged_in_user_entity()
Return the current logged in user, or null if no user is logged in.
Definition: sessions.php:24
$guid
Reset an ElggUpgrade.
Definition: reset.php:6