diff options
Diffstat (limited to 'phpBB')
-rw-r--r-- | phpBB/language/en/cli.php | 1 | ||||
-rw-r--r-- | phpBB/phpbb/console/command/user/add.php | 55 |
2 files changed, 56 insertions, 0 deletions
diff --git a/phpBB/language/en/cli.php b/phpBB/language/en/cli.php index 4c0fbde286..6fb637f3c1 100644 --- a/phpBB/language/en/cli.php +++ b/phpBB/language/en/cli.php @@ -86,6 +86,7 @@ $lang = array_merge($lang, array( 'CLI_DESCRIPTION_USER_ADD_OPTION_USERNAME' => 'Username of the new user', 'CLI_DESCRIPTION_USER_ADD_OPTION_PASSWORD' => 'Password of the new user', 'CLI_DESCRIPTION_USER_ADD_OPTION_EMAIL' => 'E-mail address of the new user', + 'CLI_DESCRIPTION_USER_ADD_OPTION_NOTIFY' => 'Send account activation email to the new user', 'CLI_EXTENSION_DISABLE_FAILURE' => 'Could not disable extension %s', 'CLI_EXTENSION_DISABLE_SUCCESS' => 'Successfully disabled extension %s', diff --git a/phpBB/phpbb/console/command/user/add.php b/phpBB/phpbb/console/command/user/add.php index db06037947..57100a773c 100644 --- a/phpBB/phpbb/console/command/user/add.php +++ b/phpBB/phpbb/console/command/user/add.php @@ -78,6 +78,7 @@ class add extends \phpbb\console\command\command ->addOption('username', null, InputOption::VALUE_REQUIRED, $this->user->lang('CLI_DESCRIPTION_USER_ADD_OPTION_USERNAME')) ->addOption('password', null, InputOption::VALUE_REQUIRED, $this->user->lang('CLI_DESCRIPTION_USER_ADD_OPTION_PASSWORD')) ->addOption('email', null, InputOption::VALUE_REQUIRED, $this->user->lang('CLI_DESCRIPTION_USER_ADD_OPTION_EMAIL')) + ->addOption('send-email', null, InputOption::VALUE_NONE, $this->user->lang('CLI_CONFIG_PRINT_WITHOUT_NEWLINE')) ; } @@ -166,6 +167,12 @@ class add extends \phpbb\console\command\command } $user_id = user_add($user_row); + + if ($input->getOption('send-email') && $this->config['email_enable']) + { + $this->send_activation_email($user_id, $data); + } + $io->success($this->user->lang('SUCCESS_ADD_USER', $username)); return 0; @@ -263,4 +270,52 @@ class add extends \phpbb\console\command\command return $row['group_id']; } + + /** + * Send account activation email + * + * @param int $user_id The new user's id + * @param array $data The user data array + * @return null + */ + protected function send_activation_email($user_id, $data) + { + if ($this->config['require_activation'] == USER_ACTIVATION_SELF) + { + $email_template = 'user_welcome_inactive'; + $user_actkey = gen_rand_string(mt_rand(6, 10)); + } + else if ($this->config['require_activation'] == USER_ACTIVATION_ADMIN) + { + $email_template = 'admin_welcome_inactive'; + $user_actkey = gen_rand_string(mt_rand(6, 10)); + } + else + { + $email_template = 'user_welcome'; + $user_actkey = ''; + } + + if (!class_exists('messenger')) + { + require($this->phpbb_root_path . 'includes/functions_messenger.' . $this->php_ext); + } + + $messenger = new \messenger(false); + + $messenger->template($email_template, $this->user->lang_name); + + $messenger->to($data['email'], $data['username']); + + $messenger->anti_abuse_headers($this->config, $this->user); + + $messenger->assign_vars(array( + 'WELCOME_MSG' => htmlspecialchars_decode($this->user->lang('WELCOME_SUBJECT', $this->config['sitename'])), + 'USERNAME' => htmlspecialchars_decode($data['username']), + 'PASSWORD' => htmlspecialchars_decode($data['new_password']), + 'U_ACTIVATE' => generate_board_url() . "/ucp.{$this->php_ext}?mode=activate&u=$user_id&k=$user_actkey") + ); + + $messenger->send(NOTIFY_EMAIL); + } } |