Elgg  Version master
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 
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:304
elgg_ok_response($content= '', string|array $message= '', string $forward_url=null, int $status_code=ELGG_HTTP_OK)
Prepares a successful response to be returned by a page or an action handler.
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
$email
Definition: change_email.php:7
if(empty($guid)||empty($email)) if(!elgg_is_valid_email($email)) $user
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof\ElggRelationship) elseif(is_callable([$item, 'getType']))
Definition: item.php:48
get_input(string $variable, $default=null, bool $filter_result=true)
Parameter input functions.
Definition: input.php:20
elgg_error_response(string|array $message= '', string $forward_url=REFERRER, int $status_code=ELGG_HTTP_BAD_REQUEST)
Prepare an error response to be returned by a page or an action handler.
const ELGG_SHOW_DISABLED_ENTITIES
Definition: constants.php:123
$guid
Admin action to change the email address of an user.
Definition: change_email.php:6
if(!$user instanceof ElggUser) $users
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_is_valid_email(string $address)
Validates an email address.
Definition: input.php:89