Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

activate.php

Zuletzt modifiziert: 09.10.2024, 12:55 - Dateigröße: 5.75 KiB


001  <?php
002  /**
003   *
004   * This file is part of the phpBB Forum Software package.
005   *
006   * @copyright (c) phpBB Limited <https://www.phpbb.com>
007   * @license GNU General Public License, version 2 (GPL-2.0)
008   *
009   * For full copyright and license information, please see
010   * the docs/CREDITS.txt file.
011   *
012   */
013   
014  namespace phpbb\console\command\user;
015   
016  use phpbb\config\config;
017  use phpbb\console\command\command;
018  use phpbb\db\driver\driver_interface;
019  use phpbb\language\language;
020  use phpbb\log\log_interface;
021  use phpbb\notification\manager;
022  use phpbb\user;
023  use phpbb\user_loader;
024  use Symfony\Component\Console\Input\InputArgument;
025  use Symfony\Component\Console\Input\InputInterface;
026  use Symfony\Component\Console\Input\InputOption;
027  use Symfony\Component\Console\Output\OutputInterface;
028  use Symfony\Component\Console\Style\SymfonyStyle;
029   
030  class activate extends command
031  {
032      /** @var driver_interface */
033      protected $db;
034   
035      /** @var config */
036      protected $config;
037   
038      /** @var language */
039      protected $language;
040   
041      /** @var log_interface */
042      protected $log;
043   
044      /** @var manager */
045      protected $notifications;
046   
047      /** @var user_loader */
048      protected $user_loader;
049   
050      /**
051       * phpBB root path
052       *
053       * @var string
054       */
055      protected $phpbb_root_path;
056   
057      /**
058       * PHP extension.
059       *
060       * @var string
061       */
062      protected $php_ext;
063   
064      /**
065       * Construct method
066       *
067       * @param user             $user
068       * @param driver_interface $db
069       * @param config           $config
070       * @param language         $language
071       * @param log_interface    $log
072       * @param manager          $notifications
073       * @param user_loader      $user_loader
074       * @param string           $phpbb_root_path
075       * @param string           $php_ext
076       */
077      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)
078      {
079          $this->db = $db;
080          $this->config = $config;
081          $this->language = $language;
082          $this->log = $log;
083          $this->notifications = $notifications;
084          $this->user_loader = $user_loader;
085          $this->phpbb_root_path = $phpbb_root_path;
086          $this->php_ext = $php_ext;
087   
088          $this->language->add_lang('acp/users');
089          parent::__construct($user);
090      }
091   
092      /**
093       * Sets the command name and description
094       *
095       * @return null
096       */
097      protected function configure()
098      {
099          $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  }
219