Elgg  Version 6.1
users.php
Go to the documentation of this file.
1 <?php
16 function get_user(int $guid): ?\ElggUser {
17  $result = _elgg_services()->entityTable->get($guid, 'user');
18 
19  return $result instanceof \ElggUser ? $result : null;
20 }
21 
31 function elgg_get_user_by_username(string $username, bool $try_email = false): ?\ElggUser {
32  if (empty($username)) {
33  return null;
34  }
35 
36  if ($try_email && elgg_is_valid_email($username)) {
37  $user = elgg_get_user_by_email($username);
38  if ($user instanceof \ElggUser) {
39  return $user;
40  }
41  }
42 
43  // Fixes #6052. Username is frequently sniffed from the path info, which,
44  // unlike $_GET, is not URL decoded. If the username was not URL encoded,
45  // this is harmless.
46  $username = rawurldecode($username);
47  if (empty($username)) {
48  return null;
49  }
50 
51  $logged_in_user = elgg_get_logged_in_user_entity();
52  if (!empty($logged_in_user) && ($logged_in_user->username === $username)) {
53  return $logged_in_user;
54  }
55 
57  'types' => 'user',
58  'metadata_name_value_pairs' => [
59  [
60  'name' => 'username',
61  'value' => $username,
62  'case_sensitive' => false,
63  ],
64  ],
65  'limit' => 1,
66  ]);
67 
68  return $users ? $users[0] : null;
69 }
70 
79 function elgg_get_user_by_email(string $email): ?\ElggUser {
80  if (empty($email)) {
81  return null;
82  }
83 
85  'types' => 'user',
86  'metadata_name_value_pairs' => [
87  [
88  'name' => 'email',
89  'value' => $email,
90  'case_sensitive' => false,
91  ],
92  ],
93  'limit' => 1,
94  ]);
95 
96  return $users ? $users[0] : null;
97 }
98 
109  _elgg_services()->passwords->requestNewPassword($user);
110 }
111 
123 function elgg_save_new_password(\ElggUser $user, string $conf_code, string $password = null): bool {
124  return _elgg_services()->passwords->saveNewPassword($user, $conf_code, $password);
125 }
126 
134 function elgg_generate_password(): string {
135  return _elgg_services()->passwordGenerator->generatePassword();
136 }
137 
154 function elgg_register_user(array $params = []): \ElggUser {
155  return _elgg_services()->accounts->register($params);
156 }
157 
171 function elgg_validate_registration_data(string $username, string|array $password, string $name, string $email, bool $allow_multiple_emails = false): \Elgg\Validation\ValidationResults {
172  return _elgg_services()->accounts->validateAccountData($username, $password, $name, $email, $allow_multiple_emails);
173 }
174 
184 function elgg_generate_invite_code(string $username): string {
185  return _elgg_services()->hmac->generateInviteCode($username);
186 }
187 
198 function elgg_validate_invite_code(string $username, string $code): bool {
199  return _elgg_services()->hmac->validateInviteCode($username, $code);
200 }
201 
213 function elgg_get_registration_url(array $parameters = [], string $fragment = ''): string {
214  $url = elgg_generate_url('account:register', $parameters) . $fragment;
215 
216  return (string) elgg_trigger_event_results('registration_url', 'site', $parameters, $url);
217 }
218 
228 function elgg_get_login_url(array $query = [], string $fragment = ''): string {
229  $url = elgg_generate_url('account:login');
231  return (string) elgg_trigger_event_results('login_url', 'site', $query, $url);
232 }
233 
245  return _elgg_services()->persistentLogin->getUserFromToken($token);
246 }
elgg_validate_invite_code(string $username, string $code)
Validate a user&#39;s invite code.
Definition: users.php:198
$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:134
elgg_get_user_by_username(string $username, bool $try_email=false)
Get a user by username.
Definition: users.php:31
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:228
elgg_save_new_password(\ElggUser $user, string $conf_code, string $password=null)
Validate and change password for a user.
Definition: users.php:123
elgg_get_user_by_persistent_token(string $token)
Get a user based on a persistent login token.
Definition: users.php:244
elgg_register_user(array $params=[])
Registers a user.
Definition: users.php:154
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:171
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:213
elgg_http_add_url_query_elements(string $url, array $elements)
Sets elements in a URL&#39;s query string.
Definition: elgglib.php:183
$result
Definition: users.php:3
$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:79
elgg_generate_invite_code(string $username)
Generates a unique invite code for a user.
Definition: users.php:184
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:108
elgg_generate_url(string $name, array $parameters=[])
Generate a URL for named route.
_elgg_services()
Get the global service provider.
Definition: elgglib.php:353
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