mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 22:28:51 +00:00
[ticket/12684] Use interactive method correctly
PHPBB3-12684
This commit is contained in:
parent
693664f278
commit
5917a8e72e
1 changed files with 25 additions and 30 deletions
|
@ -22,6 +22,9 @@ use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
|
|
||||||
class add extends \phpbb\console\command\command
|
class add extends \phpbb\console\command\command
|
||||||
{
|
{
|
||||||
|
/** @var array Array of interactively acquired options */
|
||||||
|
protected $data;
|
||||||
|
|
||||||
/** @var \phpbb\db\driver\driver_interface */
|
/** @var \phpbb\db\driver\driver_interface */
|
||||||
protected $db;
|
protected $db;
|
||||||
|
|
||||||
|
@ -125,11 +128,9 @@ class add extends \phpbb\console\command\command
|
||||||
{
|
{
|
||||||
$io = new SymfonyStyle($input, $output);
|
$io = new SymfonyStyle($input, $output);
|
||||||
|
|
||||||
$data = $this->interact($input, $output);
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$this->validate_user_data($data);
|
$this->validate_user_data();
|
||||||
$group_id = $this->get_group_id();
|
$group_id = $this->get_group_id();
|
||||||
}
|
}
|
||||||
catch (runtime_exception $e)
|
catch (runtime_exception $e)
|
||||||
|
@ -139,9 +140,9 @@ class add extends \phpbb\console\command\command
|
||||||
}
|
}
|
||||||
|
|
||||||
$user_row = array(
|
$user_row = array(
|
||||||
'username' => $data['username'],
|
'username' => $this->data['username'],
|
||||||
'user_password' => $this->password_manager->hash($data['new_password']),
|
'user_password' => $this->password_manager->hash($this->data['new_password']),
|
||||||
'user_email' => $data['email'],
|
'user_email' => $this->data['email'],
|
||||||
'group_id' => $group_id,
|
'group_id' => $group_id,
|
||||||
'user_timezone' => $this->config['board_timezone'],
|
'user_timezone' => $this->config['board_timezone'],
|
||||||
'user_lang' => $this->config['default_lang'],
|
'user_lang' => $this->config['default_lang'],
|
||||||
|
@ -159,39 +160,37 @@ class add extends \phpbb\console\command\command
|
||||||
|
|
||||||
if ($input->getOption('send-email') && $this->config['email_enable'])
|
if ($input->getOption('send-email') && $this->config['email_enable'])
|
||||||
{
|
{
|
||||||
$this->send_activation_email($user_id, $data);
|
$this->send_activation_email($user_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
$io->success($this->language->lang('CLI_USER_ADD_SUCCESS', $data['username']));
|
$io->success($this->language->lang('CLI_USER_ADD_SUCCESS', $this->data['username']));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interact with the user to obtain the required options
|
* Interacts with the user.
|
||||||
*
|
*
|
||||||
* @param InputInterface $input The input stream used to get the options
|
* @param InputInterface $input An InputInterface instance
|
||||||
* @param OutputInterface $output The output stream, used to print messages
|
* @param OutputInterface $output An OutputInterface instance
|
||||||
*
|
|
||||||
* @return array Array of required user options
|
|
||||||
*/
|
*/
|
||||||
protected function interact(InputInterface $input, OutputInterface $output)
|
protected function interact(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
$helper = $this->getHelper('question');
|
$helper = $this->getHelper('question');
|
||||||
|
|
||||||
$data = array(
|
$this->data = array(
|
||||||
'username' => $input->getOption('username'),
|
'username' => $input->getOption('username'),
|
||||||
'new_password' => $input->getOption('password'),
|
'new_password' => $input->getOption('password'),
|
||||||
'email' => $input->getOption('email'),
|
'email' => $input->getOption('email'),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!$data['username'])
|
if (!$this->data['username'])
|
||||||
{
|
{
|
||||||
$question = new Question($this->ask_user('USERNAME'));
|
$question = new Question($this->ask_user('USERNAME'));
|
||||||
$data['username'] = $helper->ask($input, $output, $question);
|
$this->data['username'] = $helper->ask($input, $output, $question);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$data['new_password'])
|
if (!$this->data['new_password'])
|
||||||
{
|
{
|
||||||
$question = new Question($this->ask_user('PASSWORD'));
|
$question = new Question($this->ask_user('PASSWORD'));
|
||||||
$question->setValidator(function ($value) use ($helper, $input, $output) {
|
$question->setValidator(function ($value) use ($helper, $input, $output) {
|
||||||
|
@ -206,33 +205,30 @@ class add extends \phpbb\console\command\command
|
||||||
$question->setHidden(true);
|
$question->setHidden(true);
|
||||||
$question->setMaxAttempts(5);
|
$question->setMaxAttempts(5);
|
||||||
|
|
||||||
$data['new_password'] = $helper->ask($input, $output, $question);
|
$this->data['new_password'] = $helper->ask($input, $output, $question);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$data['email'])
|
if (!$this->data['email'])
|
||||||
{
|
{
|
||||||
$question = new Question($this->ask_user('EMAIL_ADDRESS'));
|
$question = new Question($this->ask_user('EMAIL_ADDRESS'));
|
||||||
$data['email'] = $helper->ask($input, $output, $question);
|
$this->data['email'] = $helper->ask($input, $output, $question);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate the submitted user data
|
* Validate the submitted user data
|
||||||
*
|
*
|
||||||
* @param array $data The user data array
|
|
||||||
* @throws runtime_exception if any data fails validation
|
* @throws runtime_exception if any data fails validation
|
||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
protected function validate_user_data($data)
|
protected function validate_user_data()
|
||||||
{
|
{
|
||||||
if (!function_exists('validate_data'))
|
if (!function_exists('validate_data'))
|
||||||
{
|
{
|
||||||
require($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext);
|
require($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
$error = validate_data($data, array(
|
$error = validate_data($this->data, array(
|
||||||
'username' => array(
|
'username' => array(
|
||||||
array('string', false, $this->config['min_name_chars'], $this->config['max_name_chars']),
|
array('string', false, $this->config['min_name_chars'], $this->config['max_name_chars']),
|
||||||
array('username', '')),
|
array('username', '')),
|
||||||
|
@ -280,10 +276,9 @@ class add extends \phpbb\console\command\command
|
||||||
* Send account activation email
|
* Send account activation email
|
||||||
*
|
*
|
||||||
* @param int $user_id The new user's id
|
* @param int $user_id The new user's id
|
||||||
* @param array $data The user data array
|
|
||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
protected function send_activation_email($user_id, $data)
|
protected function send_activation_email($user_id)
|
||||||
{
|
{
|
||||||
if ($this->config['require_activation'] == USER_ACTIVATION_SELF)
|
if ($this->config['require_activation'] == USER_ACTIVATION_SELF)
|
||||||
{
|
{
|
||||||
|
@ -308,12 +303,12 @@ class add extends \phpbb\console\command\command
|
||||||
|
|
||||||
$messenger = new \messenger(false);
|
$messenger = new \messenger(false);
|
||||||
$messenger->template($email_template, $this->user->lang_name);
|
$messenger->template($email_template, $this->user->lang_name);
|
||||||
$messenger->to($data['email'], $data['username']);
|
$messenger->to($this->data['email'], $this->data['username']);
|
||||||
$messenger->anti_abuse_headers($this->config, $this->user);
|
$messenger->anti_abuse_headers($this->config, $this->user);
|
||||||
$messenger->assign_vars(array(
|
$messenger->assign_vars(array(
|
||||||
'WELCOME_MSG' => htmlspecialchars_decode($this->language->lang('WELCOME_SUBJECT', $this->config['sitename'])),
|
'WELCOME_MSG' => htmlspecialchars_decode($this->language->lang('WELCOME_SUBJECT', $this->config['sitename'])),
|
||||||
'USERNAME' => htmlspecialchars_decode($data['username']),
|
'USERNAME' => htmlspecialchars_decode($this->data['username']),
|
||||||
'PASSWORD' => htmlspecialchars_decode($data['new_password']),
|
'PASSWORD' => htmlspecialchars_decode($this->data['new_password']),
|
||||||
'U_ACTIVATE' => generate_board_url() . "/ucp.{$this->php_ext}?mode=activate&u=$user_id&k=$user_actkey")
|
'U_ACTIVATE' => generate_board_url() . "/ucp.{$this->php_ext}?mode=activate&u=$user_id&k=$user_actkey")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue