Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
obtain_admin_data.php
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\install\module\obtain_data\task;
015
016 use phpbb\install\exception\user_interaction_required_exception;
017
018 /**
019 * This class requests and validates admin account data from the user
020 */
021 class obtain_admin_data extends \phpbb\install\task_base implements \phpbb\install\task_interface
022 {
023 /**
024 * @var \phpbb\install\helper\config
025 */
026 protected $install_config;
027
028 /**
029 * @var \phpbb\install\helper\iohandler\iohandler_interface
030 */
031 protected $io_handler;
032
033 /**
034 * Constructor
035 *
036 * @param \phpbb\install\helper\config $install_config Installer's config helper
037 * @param \phpbb\install\helper\iohandler\iohandler_interface $iohandler Installer's input-output handler
038 */
039 public function __construct(\phpbb\install\helper\config $install_config,
040 \phpbb\install\helper\iohandler\iohandler_interface $iohandler)
041 {
042 $this->install_config = $install_config;
043 $this->io_handler = $iohandler;
044
045 parent::__construct(true);
046 }
047
048 /**
049 * {@inheritdoc}
050 */
051 public function run()
052 {
053 // Check if data is sent
054 if ($this->io_handler->get_input('submit_admin', false))
055 {
056 $this->process_form();
057 }
058 else
059 {
060 $this->request_form_data();
061 }
062 }
063
064 /**
065 * Process form data
066 */
067 protected function process_form()
068 {
069 // Admin data
070 $admin_name = $this->io_handler->get_input('admin_name', '', true);
071 $admin_pass1 = $this->io_handler->get_input('admin_pass1', '', true);
072 $admin_pass2 = $this->io_handler->get_input('admin_pass2', '', true);
073 $board_email = $this->io_handler->get_input('board_email', '', true);
074
075 $admin_data_valid = $this->check_admin_data($admin_name, $admin_pass1, $admin_pass2, $board_email);
076
077 if ($admin_data_valid)
078 {
079 $this->install_config->set('admin_name', $admin_name);
080 $this->install_config->set('admin_passwd', $admin_pass1);
081 $this->install_config->set('board_email', $board_email);
082 }
083 else
084 {
085 $this->request_form_data(true);
086 }
087 }
088
089 /**
090 * Request data from the user
091 *
092 * @param bool $use_request_data Whether to use submited data
093 *
094 * @throws user_interaction_required_exception When the user is required to provide data
095 */
096 protected function request_form_data($use_request_data = false)
097 {
098 if ($use_request_data)
099 {
100 $admin_username = $this->io_handler->get_input('admin_name', '', true);
101 $admin_email = $this->io_handler->get_input('board_email', '', true);
102 }
103 else
104 {
105 $admin_username = '';
106 $admin_email = '';
107 }
108
109 $admin_form = array(
110 'admin_name' => array(
111 'label' => 'ADMIN_USERNAME',
112 'description' => 'ADMIN_USERNAME_EXPLAIN',
113 'type' => 'text',
114 'default' => $admin_username,
115 ),
116 'board_email' => array(
117 'label' => 'CONTACT_EMAIL',
118 'type' => 'email',
119 'default' => $admin_email,
120 ),
121 'admin_pass1' => array(
122 'label' => 'ADMIN_PASSWORD',
123 'description' => 'ADMIN_PASSWORD_EXPLAIN',
124 'type' => 'password',
125 ),
126 'admin_pass2' => array(
127 'label' => 'ADMIN_PASSWORD_CONFIRM',
128 'type' => 'password',
129 ),
130 'submit_admin' => array(
131 'label' => 'SUBMIT',
132 'type' => 'submit',
133 ),
134 );
135
136 $this->io_handler->add_user_form_group('ADMIN_CONFIG', $admin_form);
137
138 // Require user interaction
139 throw new user_interaction_required_exception();
140 }
141
142 /**
143 * Check admin data
144 *
145 * @param string $username Admin username
146 * @param string $pass1 Admin password
147 * @param string $pass2 Admin password confirmation
148 * @param string $email Admin e-mail address
149 *
150 * @return bool True if data is valid, false otherwise
151 */
152 protected function check_admin_data($username, $pass1, $pass2, $email)
153 {
154 $data_valid = true;
155
156 // Check if none of admin data is empty
157 if (in_array('', array($username, $pass1, $pass2, $email), true))
158 {
159 $this->io_handler->add_error_message('INST_ERR_MISSING_DATA');
160 $data_valid = false;
161 }
162
163 if (utf8_strlen($username) < 3)
164 {
165 $this->io_handler->add_error_message('INST_ERR_USER_TOO_SHORT');
166 $data_valid = false;
167 }
168
169 if (utf8_strlen($username) > 20)
170 {
171 $this->io_handler->add_error_message('INST_ERR_USER_TOO_LONG');
172 $data_valid = false;
173 }
174
175 if ($pass1 !== $pass2 && $pass1 !== '')
176 {
177 $this->io_handler->add_error_message('INST_ERR_PASSWORD_MISMATCH');
178 $data_valid = false;
179 }
180
181 // Test against the default password rules
182 if (utf8_strlen($pass1) < 6)
183 {
184 $this->io_handler->add_error_message('INST_ERR_PASSWORD_TOO_SHORT');
185 $data_valid = false;
186 }
187
188 if (utf8_strlen($pass1) > 30)
189 {
190 $this->io_handler->add_error_message('INST_ERR_PASSWORD_TOO_LONG');
191 $data_valid = false;
192 }
193
194 if (!preg_match('/^' . get_preg_expression('email') . '$/i', $email))
195 {
196 $this->io_handler->add_error_message('INST_ERR_EMAIL_INVALID');
197 $data_valid = false;
198 }
199
200 return $data_valid;
201 }
202
203 /**
204 * {@inheritdoc}
205 */
206 static public function get_step_count()
207 {
208 return 0;
209 }
210
211 /**
212 * {@inheritdoc}
213 */
214 public function get_task_lang_name()
215 {
216 return '';
217 }
218 }
219