aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB
diff options
context:
space:
mode:
authorMatt Friedman <maf675@gmail.com>2016-02-29 11:42:23 -0800
committerMatt Friedman <maf675@gmail.com>2016-02-29 11:42:23 -0800
commitf32b4c0547a596fcdd935560b23ed660f3d3f87c (patch)
tree5b20f4d74280586cd7632a0710f208409918e9ec /phpBB
parentd373428180e884f03a830aa69fe8ff2cd6a5140a (diff)
downloadforums-f32b4c0547a596fcdd935560b23ed660f3d3f87c.tar
forums-f32b4c0547a596fcdd935560b23ed660f3d3f87c.tar.gz
forums-f32b4c0547a596fcdd935560b23ed660f3d3f87c.tar.bz2
forums-f32b4c0547a596fcdd935560b23ed660f3d3f87c.tar.xz
forums-f32b4c0547a596fcdd935560b23ed660f3d3f87c.zip
[ticket/12684] Add send email option
PHPBB3-12684
Diffstat (limited to 'phpBB')
-rw-r--r--phpBB/language/en/cli.php1
-rw-r--r--phpBB/phpbb/console/command/user/add.php55
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);
+ }
}