Elgg  Version 4.3
change_email.php
Go to the documentation of this file.
1 <?php
6 $guid = (int) get_input('user_guid');
7 $email = (string) get_input('email');
8 
9 if (empty($guid) || empty($email)) {
10  return elgg_error_response(elgg_echo('error:missing_data'));
11 }
12 
14  return elgg_error_response(elgg_echo('registration:emailnotvalid'));
15 }
16 
18  return get_user($guid);
19 });
20 if (!$user instanceof ElggUser) {
21  return elgg_error_response(elgg_echo('error:missing_data'));
22 }
23 
25  return get_user_by_email($email);
26 });
27 
28 if (count($users) > 1) {
29  return elgg_error_response(elgg_echo('registration:dupeemail'));
30 } elseif (count($users) === 1) {
31  if ($users[0]->guid !== $user->guid) {
32  // email already taken by other user
33  return elgg_error_response(elgg_echo('registration:dupeemail'));
34  }
35 }
36 
37 if ($user->email === $email) {
38  // no change
39  return elgg_ok_response();
40 }
41 
42 $user->email = $email;
43 $user->save();
44 
45 return elgg_ok_response('', elgg_echo('email:save:success'));
elgg_call(int $flags, Closure $closure)
Calls a callable autowiring the arguments using public DI services and applying logic based on flags...
Definition: elgglib.php:592
get_user($guid)
Get a user object from a GUID.
Definition: users.php:20
get_user_by_email($email)
Get an array of users from an email address.
Definition: users.php:52
$email
Definition: change_email.php:7
if(empty($guid)||empty($email)) if(!elgg_is_valid_email($email)) $user
elgg_echo($message_key, array $args=[], $language="")
Elgg language module Functions to manage language and translations.
Definition: languages.php:18
const ELGG_SHOW_DISABLED_ENTITIES
Definition: constants.php:148
get_input($variable, $default=null, $filter_result=true)
Parameter input functions.
Definition: input.php:20
$guid
Admin action to change the email address of an user.
Definition: change_email.php:6
if(!$user instanceof ElggUser) $users
elgg_is_valid_email(string $address)
Validates an email address.
Definition: input.php:91
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof ElggRelationship) elseif(is_callable([$item, 'getType']))
Definition: item.php:48
elgg_error_response($message= '', $forward_url=REFERRER, int $status_code=ELGG_HTTP_BAD_REQUEST)
Prepare an error response to be returned by a page or an action handler.
elgg_ok_response($content= '', $message= '', $forward_url=null, int $status_code=ELGG_HTTP_OK)
Prepares a successful response to be returned by a page or an action handler.