1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-04-13 20:32:11 +02:00

[ticket/12684] Add send email option

PHPBB3-12684
This commit is contained in:
Matt Friedman 2016-02-29 11:42:23 -08:00
parent d373428180
commit f32b4c0547
3 changed files with 57 additions and 0 deletions

View File

@ -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',

View File

@ -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);
}
}

View File

@ -49,6 +49,7 @@ class phpbb_console_command_user_add_test extends phpbb_database_test_case
$config = $this->config = new \phpbb\config\config(array(
'board_timezone' => 'UTC',
'default_lang' => 'en',
'email_enable' => false,
'min_name_chars' => 3,
'max_name_chars' => 10,
'min_pass_chars' => 3,