[ Index ]

PHP Cross Reference of phpBB-3.3.3-deutsch

title

Body

[close]

/phpbb/console/command/user/ -> activate.php (source)

   1  <?php
   2  /**
   3   *
   4   * This file is part of the phpBB Forum Software package.
   5   *
   6   * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7   * @license GNU General Public License, version 2 (GPL-2.0)
   8   *
   9   * For full copyright and license information, please see
  10   * the docs/CREDITS.txt file.
  11   *
  12   */
  13  
  14  namespace phpbb\console\command\user;
  15  
  16  use phpbb\config\config;
  17  use phpbb\console\command\command;
  18  use phpbb\db\driver\driver_interface;
  19  use phpbb\language\language;
  20  use phpbb\log\log_interface;
  21  use phpbb\notification\manager;
  22  use phpbb\user;
  23  use phpbb\user_loader;
  24  use Symfony\Component\Console\Input\InputArgument;
  25  use Symfony\Component\Console\Input\InputInterface;
  26  use Symfony\Component\Console\Input\InputOption;
  27  use Symfony\Component\Console\Output\OutputInterface;
  28  use Symfony\Component\Console\Style\SymfonyStyle;
  29  
  30  class activate extends command
  31  {
  32      /** @var driver_interface */
  33      protected $db;
  34  
  35      /** @var config */
  36      protected $config;
  37  
  38      /** @var language */
  39      protected $language;
  40  
  41      /** @var log_interface */
  42      protected $log;
  43  
  44      /** @var manager */
  45      protected $notifications;
  46  
  47      /** @var user_loader */
  48      protected $user_loader;
  49  
  50      /**
  51       * phpBB root path
  52       *
  53       * @var string
  54       */
  55      protected $phpbb_root_path;
  56  
  57      /**
  58       * PHP extension.
  59       *
  60       * @var string
  61       */
  62      protected $php_ext;
  63  
  64      /**
  65       * Construct method
  66       *
  67       * @param user             $user
  68       * @param driver_interface $db
  69       * @param config           $config
  70       * @param language         $language
  71       * @param log_interface    $log
  72       * @param manager          $notifications
  73       * @param user_loader      $user_loader
  74       * @param string           $phpbb_root_path
  75       * @param string           $php_ext
  76       */
  77  	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)
  78      {
  79          $this->db = $db;
  80          $this->config = $config;
  81          $this->language = $language;
  82          $this->log = $log;
  83          $this->notifications = $notifications;
  84          $this->user_loader = $user_loader;
  85          $this->phpbb_root_path = $phpbb_root_path;
  86          $this->php_ext = $php_ext;
  87  
  88          $this->language->add_lang('acp/users');
  89          parent::__construct($user);
  90      }
  91  
  92      /**
  93       * Sets the command name and description
  94       *
  95       * @return null
  96       */
  97  	protected function configure()
  98      {
  99          $this
 100              ->setName('user:activate')
 101              ->setDescription($this->language->lang('CLI_DESCRIPTION_USER_ACTIVATE'))
 102              ->setHelp($this->language->lang('CLI_HELP_USER_ACTIVATE'))
 103              ->addArgument(
 104                  'username',
 105                  InputArgument::REQUIRED,
 106                  $this->language->lang('CLI_DESCRIPTION_USER_ACTIVATE_USERNAME')
 107              )
 108              ->addOption(
 109                  'deactivate',
 110                  'd',
 111                  InputOption::VALUE_NONE,
 112                  $this->language->lang('CLI_DESCRIPTION_USER_ACTIVATE_DEACTIVATE')
 113              )
 114              ->addOption(
 115                  'send-email',
 116                  null,
 117                  InputOption::VALUE_NONE,
 118                  $this->language->lang('CLI_DESCRIPTION_USER_ADD_OPTION_NOTIFY')
 119              )
 120          ;
 121      }
 122  
 123      /**
 124       * Executes the command user:activate
 125       *
 126       * Activate (or deactivate) a user account
 127       *
 128       * @param InputInterface  $input  The input stream used to get the options
 129       * @param OutputInterface $output The output stream, used to print messages
 130       *
 131       * @return int 0 if all is well, 1 if any errors occurred
 132       */
 133  	protected function execute(InputInterface $input, OutputInterface $output)
 134      {
 135          $io = new SymfonyStyle($input, $output);
 136  
 137          $name = $input->getArgument('username');
 138          $mode = ($input->getOption('deactivate')) ? 'deactivate' : 'activate';
 139  
 140          $user_id  = $this->user_loader->load_user_by_username($name);
 141          $user_row = $this->user_loader->get_user($user_id);
 142  
 143          if ($user_row['user_id'] == ANONYMOUS)
 144          {
 145              $io->error($this->language->lang('NO_USER'));
 146              return 1;
 147          }
 148  
 149          // Check if the user is already active (or inactive)
 150          if ($mode == 'activate' && $user_row['user_type'] != USER_INACTIVE)
 151          {
 152              $io->error($this->language->lang('CLI_DESCRIPTION_USER_ACTIVATE_ACTIVE'));
 153              return 1;
 154          }
 155          else if ($mode == 'deactivate' && $user_row['user_type'] == USER_INACTIVE)
 156          {
 157              $io->error($this->language->lang('CLI_DESCRIPTION_USER_ACTIVATE_INACTIVE'));
 158              return 1;
 159          }
 160  
 161          // Activate the user account
 162          if (!function_exists('user_active_flip'))
 163          {
 164              require($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext);
 165          }
 166  
 167          user_active_flip($mode, $user_row['user_id']);
 168  
 169          // Notify the user upon activation
 170          if ($mode == 'activate' && $this->config['require_activation'] == USER_ACTIVATION_ADMIN)
 171          {
 172              $this->send_notification($user_row, $input);
 173          }
 174  
 175          // Log and display the result
 176          $msg = ($mode == 'activate') ? 'USER_ADMIN_ACTIVATED' : 'USER_ADMIN_DEACTIVED';
 177          $log = ($mode == 'activate') ? 'LOG_USER_ACTIVE' : 'LOG_USER_INACTIVE';
 178  
 179          $this->log->add('admin', ANONYMOUS, '', $log, false, array($user_row['username']));
 180          $this->log->add('user', ANONYMOUS, '', $log . '_USER', false, array(
 181              'reportee_id' => $user_row['user_id']
 182          ));
 183  
 184          $io->success($this->language->lang($msg));
 185  
 186          return 0;
 187      }
 188  
 189      /**
 190       * Send account activation notification to user
 191       *
 192       * @param array           $user_row The user data array
 193       * @param InputInterface  $input    The input stream used to get the options
 194       * @return null
 195       */
 196  	protected function send_notification($user_row, InputInterface $input)
 197      {
 198          $this->notifications->delete_notifications('notification.type.admin_activate_user', $user_row['user_id']);
 199  
 200          if ($input->getOption('send-email'))
 201          {
 202              if (!class_exists('messenger'))
 203              {
 204                  require($this->phpbb_root_path . 'includes/functions_messenger.' . $this->php_ext);
 205              }
 206  
 207              $messenger = new \messenger(false);
 208              $messenger->template('admin_welcome_activated', $user_row['user_lang']);
 209              $messenger->set_addresses($user_row);
 210              $messenger->anti_abuse_headers($this->config, $this->user);
 211              $messenger->assign_vars(array(
 212                      'USERNAME'    => htmlspecialchars_decode($user_row['username']))
 213              );
 214  
 215              $messenger->send(NOTIFY_EMAIL);
 216          }
 217      }
 218  }


Generated: Sun Feb 14 20:08:31 2021 Cross-referenced by PHPXref 0.7.1