Elgg  Version 6.1
useradd.php
Go to the documentation of this file.
1 <?php
7 
8 // Get variables
9 $username = get_input('username');
10 $password = get_input('password', null, false);
11 $password2 = get_input('password2', null, false);
12 $email = get_input('email');
13 $name = get_input('name');
14 
15 // This param is not included in the useradd form by default,
16 // but it allows sites to easily add the feature if necessary.
17 $language = get_input('language', elgg_get_config('language'));
18 
19 $admin = get_input('admin');
20 $admin = is_array($admin) ? $admin[0] : $admin;
21 
22 $autogen_password = get_input('autogen_password');
23 if ($autogen_password) {
26 }
27 
28 // no blank fields
29 if ($username == '' || $password == '' || $password2 == '' || $email == '' || $name == '') {
30  return elgg_error_response(elgg_echo('register:fields'));
31 }
32 
33 if (strcmp($password, $password2) != 0) {
34  return elgg_error_response(elgg_echo('RegistrationException:PasswordMismatch'));
35 }
36 
37 // For now, just try and register the user
38 try {
40  'username' => $username,
41  'password' => $password,
42  'name' => $name,
43  'email' => $email,
44  'language' => $language,
45  ]);
46 
48  $new_user->makeAdmin();
49  }
50 
51  $new_user->admin_created = true;
53 
54  $subject = elgg_echo('useradd:subject', [], $new_user->getLanguage());
55  $body = elgg_echo('useradd:body', [
56  elgg_get_site_entity()->getDisplayName(),
57  elgg_get_site_entity()->getURL(),
58  $username,
59  $password,
60  ], $new_user->getLanguage());
61 
63  'action' => 'useradd',
64  'object' => $new_user,
65  'password' => $password,
66  'apply_muting' => false,
67  ], ['email']);
68 
69  return elgg_ok_response('', elgg_echo('adduser:ok', [elgg_get_site_entity()->getDisplayName()]));
70 } catch (RegistrationException $r) {
71  return elgg_error_response($r->getMessage());
72 }
$name
Definition: useradd.php:13
elgg_get_config(string $name, $default=null)
Get an Elgg configuration value.
elgg_is_admin_logged_in()
Returns whether or not the viewer is currently logged in and an admin user.
Definition: sessions.php:52
Elgg registration action.
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_generate_password()
Generate a random 12 character clear text password.
Definition: users.php:134
$admin
Definition: useradd.php:19
elgg_register_user(array $params=[])
Registers a user.
Definition: users.php:154
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
$username
Definition: useradd.php:9
Could not register a new user for whatever reason.
if($failures) $new_user
Definition: register.php:33
get_input(string $variable, $default=null, bool $filter_result=true)
Parameter input functions.
Definition: input.php:20
$password2
Definition: useradd.php:11
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.
$email
Definition: useradd.php:12
$autogen_password
Definition: useradd.php:22
$language
Definition: useradd.php:17
$body
Definition: useradd.php:55
elgg_get_site_entity()
Get the current site entity.
Definition: entities.php:101
notify_user(int|array $to, int $from=0, string $subject= '', string $message= '', array $params=[], $methods_override=null)
Notify a user via their preferences.
elgg_get_logged_in_user_guid()
Return the current logged in user by guid.
Definition: sessions.php:34
$subject
Definition: useradd.php:54
$password
Definition: useradd.php:10