mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
[ticket/14561] Use the user loader where appropriate
PHPBB3-14561
This commit is contained in:
parent
ed0f151d86
commit
4b789c0418
6 changed files with 29 additions and 40 deletions
|
@ -229,6 +229,7 @@ services:
|
||||||
- '@language'
|
- '@language'
|
||||||
- '@log'
|
- '@log'
|
||||||
- '@notification_manager'
|
- '@notification_manager'
|
||||||
|
- '@user_loader'
|
||||||
- '%core.root_path%'
|
- '%core.root_path%'
|
||||||
- '%core.php_ext%'
|
- '%core.php_ext%'
|
||||||
tags:
|
tags:
|
||||||
|
@ -254,6 +255,7 @@ services:
|
||||||
- '@dbal.conn'
|
- '@dbal.conn'
|
||||||
- '@language'
|
- '@language'
|
||||||
- '@log'
|
- '@log'
|
||||||
|
- '@user_loader'
|
||||||
- '%core.root_path%'
|
- '%core.root_path%'
|
||||||
- '%core.php_ext%'
|
- '%core.php_ext%'
|
||||||
tags:
|
tags:
|
||||||
|
|
|
@ -20,6 +20,7 @@ use phpbb\language\language;
|
||||||
use phpbb\log\log_interface;
|
use phpbb\log\log_interface;
|
||||||
use phpbb\notification\manager;
|
use phpbb\notification\manager;
|
||||||
use phpbb\user;
|
use phpbb\user;
|
||||||
|
use phpbb\user_loader;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
@ -43,6 +44,9 @@ class activate extends command
|
||||||
/** @var manager */
|
/** @var manager */
|
||||||
protected $notifications;
|
protected $notifications;
|
||||||
|
|
||||||
|
/** @var user_loader */
|
||||||
|
protected $user_loader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* phpBB root path
|
* phpBB root path
|
||||||
*
|
*
|
||||||
|
@ -66,16 +70,18 @@ class activate extends command
|
||||||
* @param language $language
|
* @param language $language
|
||||||
* @param log_interface $log
|
* @param log_interface $log
|
||||||
* @param manager $notifications
|
* @param manager $notifications
|
||||||
|
* @param user_loader $user_loader
|
||||||
* @param string $phpbb_root_path
|
* @param string $phpbb_root_path
|
||||||
* @param string $php_ext
|
* @param string $php_ext
|
||||||
*/
|
*/
|
||||||
public function __construct(user $user, driver_interface $db, config $config, language $language, log_interface $log, manager $notifications, $phpbb_root_path, $php_ext)
|
public function __construct(user $user, driver_interface $db, config $config, language $language, log_interface $log, manager $notifications, user_loader $user_loader, $phpbb_root_path, $php_ext)
|
||||||
{
|
{
|
||||||
$this->db = $db;
|
$this->db = $db;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->language = $language;
|
$this->language = $language;
|
||||||
$this->log = $log;
|
$this->log = $log;
|
||||||
$this->notifications = $notifications;
|
$this->notifications = $notifications;
|
||||||
|
$this->user_loader = $user_loader;
|
||||||
$this->phpbb_root_path = $phpbb_root_path;
|
$this->phpbb_root_path = $phpbb_root_path;
|
||||||
$this->php_ext = $php_ext;
|
$this->php_ext = $php_ext;
|
||||||
|
|
||||||
|
@ -132,7 +138,10 @@ class activate extends command
|
||||||
$name = $input->getArgument('username');
|
$name = $input->getArgument('username');
|
||||||
$mode = ($input->getOption('deactivate')) ? 'deactivate' : 'activate';
|
$mode = ($input->getOption('deactivate')) ? 'deactivate' : 'activate';
|
||||||
|
|
||||||
if (!$user_row = $this->get_user_data($name))
|
$user_id = $this->user_loader->load_user_by_username($name);
|
||||||
|
$user_row = $this->user_loader->get_user($user_id);
|
||||||
|
|
||||||
|
if ($user_row['user_id'] == ANONYMOUS)
|
||||||
{
|
{
|
||||||
$io->error($this->language->lang('NO_USER'));
|
$io->error($this->language->lang('NO_USER'));
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -207,22 +216,4 @@ class activate extends command
|
||||||
$messenger->send(NOTIFY_EMAIL);
|
$messenger->send(NOTIFY_EMAIL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the user's data from the database
|
|
||||||
*
|
|
||||||
* @param string $name A user name
|
|
||||||
* @return mixed The user's data array if they exist, false otherwise.
|
|
||||||
*/
|
|
||||||
protected function get_user_data($name)
|
|
||||||
{
|
|
||||||
$sql = 'SELECT *
|
|
||||||
FROM ' . USERS_TABLE . "
|
|
||||||
WHERE username_clean = '" . $this->db->sql_escape(utf8_clean_string($name)) . "'";
|
|
||||||
$result = $this->db->sql_query_limit($sql, 1);
|
|
||||||
$user_row = $this->db->sql_fetchrow($result);
|
|
||||||
$this->db->sql_freeresult($result);
|
|
||||||
|
|
||||||
return $user_row;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ use phpbb\db\driver\driver_interface;
|
||||||
use phpbb\language\language;
|
use phpbb\language\language;
|
||||||
use phpbb\log\log_interface;
|
use phpbb\log\log_interface;
|
||||||
use phpbb\user;
|
use phpbb\user;
|
||||||
|
use phpbb\user_loader;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
@ -36,6 +37,9 @@ class delete extends command
|
||||||
/** @var log_interface */
|
/** @var log_interface */
|
||||||
protected $log;
|
protected $log;
|
||||||
|
|
||||||
|
/** @var user_loader */
|
||||||
|
protected $user_loader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* phpBB root path
|
* phpBB root path
|
||||||
*
|
*
|
||||||
|
@ -57,14 +61,16 @@ class delete extends command
|
||||||
* @param driver_interface $db
|
* @param driver_interface $db
|
||||||
* @param language $language
|
* @param language $language
|
||||||
* @param log_interface $log
|
* @param log_interface $log
|
||||||
|
* @param user_loader $user_loader
|
||||||
* @param string $phpbb_root_path
|
* @param string $phpbb_root_path
|
||||||
* @param string $php_ext
|
* @param string $php_ext
|
||||||
*/
|
*/
|
||||||
public function __construct(user $user, driver_interface $db, language $language, log_interface $log, $phpbb_root_path, $php_ext)
|
public function __construct(user $user, driver_interface $db, language $language, log_interface $log, user_loader $user_loader, $phpbb_root_path, $php_ext)
|
||||||
{
|
{
|
||||||
$this->db = $db;
|
$this->db = $db;
|
||||||
$this->language = $language;
|
$this->language = $language;
|
||||||
$this->log = $log;
|
$this->log = $log;
|
||||||
|
$this->user_loader = $user_loader;
|
||||||
$this->phpbb_root_path = $phpbb_root_path;
|
$this->phpbb_root_path = $phpbb_root_path;
|
||||||
$this->php_ext = $php_ext;
|
$this->php_ext = $php_ext;
|
||||||
|
|
||||||
|
@ -116,7 +122,10 @@ class delete extends command
|
||||||
{
|
{
|
||||||
$io = new SymfonyStyle($input, $output);
|
$io = new SymfonyStyle($input, $output);
|
||||||
|
|
||||||
if (!$user_row = $this->get_user_data($name))
|
$user_id = $this->user_loader->load_user_by_username($name);
|
||||||
|
$user_row = $this->user_loader->get_user($user_id);
|
||||||
|
|
||||||
|
if ($user_row['user_id'] == ANONYMOUS)
|
||||||
{
|
{
|
||||||
$io->error($this->language->lang('NO_USER'));
|
$io->error($this->language->lang('NO_USER'));
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -158,22 +167,4 @@ class delete extends command
|
||||||
$input->setArgument('username', false);
|
$input->setArgument('username', false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the user's data from the database
|
|
||||||
*
|
|
||||||
* @param string $name A user name
|
|
||||||
* @return mixed The user's id and username if they exist, false otherwise.
|
|
||||||
*/
|
|
||||||
protected function get_user_data($name)
|
|
||||||
{
|
|
||||||
$sql = 'SELECT user_id, username
|
|
||||||
FROM ' . USERS_TABLE . "
|
|
||||||
WHERE username_clean = '" . $this->db->sql_escape(utf8_clean_string($name)) . "'";
|
|
||||||
$result = $this->db->sql_query_limit($sql, 1);
|
|
||||||
$user_row = $this->db->sql_fetchrow($result);
|
|
||||||
$this->db->sql_freeresult($result);
|
|
||||||
|
|
||||||
return $user_row;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ class phpbb_console_user_activate_test extends phpbb_console_user_base
|
||||||
$this->language,
|
$this->language,
|
||||||
$this->log,
|
$this->log,
|
||||||
$this->notifications,
|
$this->notifications,
|
||||||
|
$this->user_loader,
|
||||||
$this->phpbb_root_path,
|
$this->phpbb_root_path,
|
||||||
$this->php_ext
|
$this->php_ext
|
||||||
));
|
));
|
||||||
|
|
|
@ -25,6 +25,7 @@ abstract class phpbb_console_user_base extends phpbb_database_test_case
|
||||||
protected $passwords_manager;
|
protected $passwords_manager;
|
||||||
protected $command_name;
|
protected $command_name;
|
||||||
protected $question;
|
protected $question;
|
||||||
|
protected $user_loader;
|
||||||
protected $phpbb_root_path;
|
protected $phpbb_root_path;
|
||||||
protected $php_ext;
|
protected $php_ext;
|
||||||
|
|
||||||
|
@ -70,6 +71,8 @@ abstract class phpbb_console_user_base extends phpbb_database_test_case
|
||||||
'\phpbb\datetime'
|
'\phpbb\datetime'
|
||||||
));
|
));
|
||||||
|
|
||||||
|
$this->user_loader = new \phpbb\user_loader($db, $phpbb_root_path, $phpEx, USERS_TABLE);
|
||||||
|
|
||||||
$driver_helper = new \phpbb\passwords\driver\helper($this->config);
|
$driver_helper = new \phpbb\passwords\driver\helper($this->config);
|
||||||
$passwords_drivers = array(
|
$passwords_drivers = array(
|
||||||
'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($this->config, $driver_helper),
|
'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($this->config, $driver_helper),
|
||||||
|
|
|
@ -27,6 +27,7 @@ class phpbb_console_user_delete_test extends phpbb_console_user_base
|
||||||
$this->db,
|
$this->db,
|
||||||
$this->language,
|
$this->language,
|
||||||
$this->log,
|
$this->log,
|
||||||
|
$this->user_loader,
|
||||||
$this->phpbb_root_path,
|
$this->phpbb_root_path,
|
||||||
$this->php_ext
|
$this->php_ext
|
||||||
));
|
));
|
||||||
|
|
Loading…
Add table
Reference in a new issue