diff options
author | Mate Bartus <mate.bartus@gmail.com> | 2015-07-23 20:50:33 +0200 |
---|---|---|
committer | Mate Bartus <mate.bartus@gmail.com> | 2015-07-23 20:50:33 +0200 |
commit | fbd5929606169d3f780f0a59760c171b20bd906d (patch) | |
tree | f7aa8cc2ad7933df8ef2b16cf08a01c3051ffcc5 /phpBB | |
parent | dd31020fb3dd4ab96b48dd1854f73190900319b1 (diff) | |
download | forums-fbd5929606169d3f780f0a59760c171b20bd906d.tar forums-fbd5929606169d3f780f0a59760c171b20bd906d.tar.gz forums-fbd5929606169d3f780f0a59760c171b20bd906d.tar.bz2 forums-fbd5929606169d3f780f0a59760c171b20bd906d.tar.xz forums-fbd5929606169d3f780f0a59760c171b20bd906d.zip |
[ticket/13740] Login admin when install finished
PHPBB3-13740
Diffstat (limited to 'phpBB')
-rw-r--r-- | phpBB/assets/javascript/installer.js | 18 | ||||
-rw-r--r-- | phpBB/phpbb/install/helper/container_factory.php | 5 | ||||
-rw-r--r-- | phpBB/phpbb/install/helper/iohandler/ajax_iohandler.php | 23 | ||||
-rw-r--r-- | phpBB/phpbb/install/helper/iohandler/cli_iohandler.php | 7 | ||||
-rw-r--r-- | phpBB/phpbb/install/helper/iohandler/iohandler_interface.php | 8 | ||||
-rw-r--r-- | phpBB/phpbb/install/module/install_finish/task/notify_user.php | 43 | ||||
-rw-r--r-- | phpBB/phpbb/session.php | 6 |
7 files changed, 102 insertions, 8 deletions
diff --git a/phpBB/assets/javascript/installer.js b/phpBB/assets/javascript/installer.js index 91e8eb4797..4640d03de7 100644 --- a/phpBB/assets/javascript/installer.js +++ b/phpBB/assets/javascript/installer.js @@ -165,6 +165,19 @@ } } + // Set cookies + function setCookies(cookies) { + var cookie; + + for (var i = 0; i < cookies.length; i++) { + // Set cookie name and value + cookie = encodeURIComponent(cookies[i].name) + '=' + encodeURIComponent(cookies[i].value); + // Set path + cookie += '; path=/'; + document.cookie = cookie; + } + } + /** * Parse messages from the response object * @@ -199,6 +212,10 @@ if (responseObject.hasOwnProperty('nav')) { updateNavbarStatus(responseObject.nav); } + + if (responseObject.hasOwnProperty('cookies')) { + setCookies(responseObject.cookies); + } } /** @@ -321,6 +338,7 @@ $contentWrapper.append($spinner); } + // Submits a form function submitForm($form, $submitBtn) { $form.css('display', 'none'); diff --git a/phpBB/phpbb/install/helper/container_factory.php b/phpBB/phpbb/install/helper/container_factory.php index eb44b470b7..e09e43be34 100644 --- a/phpBB/phpbb/install/helper/container_factory.php +++ b/phpBB/phpbb/install/helper/container_factory.php @@ -13,6 +13,7 @@ namespace phpbb\install\helper; +use phpbb\cache\driver\dummy; use phpbb\install\exception\cannot_build_container_exception; class container_factory @@ -152,6 +153,10 @@ class container_factory // this container $this->container->register('request')->setSynthetic(true); $this->container->set('request', $this->request); + + // Replace cache service, as config gets cached, and we don't want that + $this->container->register('cache.driver')->setSynthetic(true); + $this->container->set('cache.driver', new dummy()); $this->container->compile(); // Restore super globals to previous state diff --git a/phpBB/phpbb/install/helper/iohandler/ajax_iohandler.php b/phpBB/phpbb/install/helper/iohandler/ajax_iohandler.php index ce1112c7a1..fa628f3365 100644 --- a/phpBB/phpbb/install/helper/iohandler/ajax_iohandler.php +++ b/phpBB/phpbb/install/helper/iohandler/ajax_iohandler.php @@ -44,6 +44,11 @@ class ajax_iohandler extends iohandler_base protected $nav_data; /** + * @var array + */ + protected $cookies; + + /** * Constructor * * @param \phpbb\request\request_interface $request HTTP request interface @@ -55,6 +60,7 @@ class ajax_iohandler extends iohandler_base $this->template = $template; $this->form = ''; $this->nav_data = array(); + $this->cookies = array(); parent::__construct(); } @@ -214,6 +220,12 @@ class ajax_iohandler extends iohandler_base $this->request_client_refresh = false; } + if (!empty($this->cookies)) + { + $json_array['cookies'] = $this->cookies; + $this->cookies = array(); + } + return $json_array; } @@ -253,6 +265,17 @@ class ajax_iohandler extends iohandler_base } /** + * {@inheritdoc} + */ + public function set_cookie($cookie_name, $cookie_value) + { + $this->cookies[] = array( + 'name' => $cookie_name, + 'value' => $cookie_value + ); + } + + /** * Callback function for language replacing * * @param array $matches diff --git a/phpBB/phpbb/install/helper/iohandler/cli_iohandler.php b/phpBB/phpbb/install/helper/iohandler/cli_iohandler.php index bf68f363c3..c5b2bb06bc 100644 --- a/phpBB/phpbb/install/helper/iohandler/cli_iohandler.php +++ b/phpBB/phpbb/install/helper/iohandler/cli_iohandler.php @@ -255,4 +255,11 @@ class cli_iohandler extends iohandler_base public function set_finished_stage_menu($menu_path) { } + + /** + * {@inheritdoc} + */ + public function set_cookie($cookie_name, $cookie_value) + { + } } diff --git a/phpBB/phpbb/install/helper/iohandler/iohandler_interface.php b/phpBB/phpbb/install/helper/iohandler/iohandler_interface.php index 44b409bb0a..5f5f8499d6 100644 --- a/phpBB/phpbb/install/helper/iohandler/iohandler_interface.php +++ b/phpBB/phpbb/install/helper/iohandler/iohandler_interface.php @@ -163,4 +163,12 @@ interface iohandler_interface * @param string $message_lang_key Language key for the message */ public function finish_progress($message_lang_key); + + /** + * Sends and sets cookies + * + * @param string $cookie_name Name of the cookie to set + * @param string $cookie_value Value of the cookie to set + */ + public function set_cookie($cookie_name, $cookie_value); } diff --git a/phpBB/phpbb/install/module/install_finish/task/notify_user.php b/phpBB/phpbb/install/module/install_finish/task/notify_user.php index baffaf2228..a433d342d0 100644 --- a/phpBB/phpbb/install/module/install_finish/task/notify_user.php +++ b/phpBB/phpbb/install/module/install_finish/task/notify_user.php @@ -12,6 +12,7 @@ */ namespace phpbb\install\module\install_finish\task; +use phpbb\config\db; /** * Logs installation and sends an email to the admin @@ -73,11 +74,17 @@ class notify_user extends \phpbb\install\task_base $this->iohandler = $iohandler; $this->auth = $container->get('auth'); - $this->config = $container->get('config'); $this->log = $container->get('log'); $this->user = $container->get('user'); $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; + + // We need to reload config for cases when it doesn't have all values + $this->config = new db( + $container->get('dbal.conn'), + $container->get('cache.driver'), + $container->get_parameter('tables.config') + ); } /** @@ -85,11 +92,8 @@ class notify_user extends \phpbb\install\task_base */ public function run() { - // @todo Login user after installation has been finished - //$this->user->setup('common'); - - //$this->user->session_begin(); - //$this->auth->login($this->install_config->get('admin_name'), $this->install_config->get('admin_pass1'), false, true, true); + $this->user->session_begin(); + $this->user->setup('common'); if ($this->config['email_enable']) { @@ -106,8 +110,31 @@ class notify_user extends \phpbb\install\task_base $messenger->send(NOTIFY_EMAIL); } - $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_INSTALL_INSTALLED', false, array($this->config['version'])); - + // Login admin + // Ugly but works + $this->auth->login( + $this->install_config->get('admin_name'), + $this->install_config->get('admin_passwd'), + false, + true, + true + ); + + $this->iohandler->set_cookie($this->config['cookie_name'] . '_sid', $this->user->session_id); + $this->iohandler->set_cookie($this->config['cookie_name'] . '_u', $this->user->cookie_data['u']); + $this->iohandler->set_cookie($this->config['cookie_name'] . '_k', $this->user->cookie_data['k']); + + // Create log + $this->log->add( + 'admin', + $this->user->data['user_id'], + $this->user->ip, + 'LOG_INSTALL_INSTALLED', + false, + array($this->config['version']) + ); + + // Remove install_lock @unlink($this->phpbb_root_path . 'cache/install_lock'); } diff --git a/phpBB/phpbb/session.php b/phpBB/phpbb/session.php index 6154f384f3..91b657262c 100644 --- a/phpBB/phpbb/session.php +++ b/phpBB/phpbb/session.php @@ -1076,6 +1076,12 @@ class session { global $config; + // If headers are already set, we just return + if (headers_sent()) + { + return; + } + $name_data = rawurlencode($config['cookie_name'] . '_' . $name) . '=' . rawurlencode($cookiedata); $expire = gmdate('D, d-M-Y H:i:s \\G\\M\\T', $cookietime); $domain = (!$config['cookie_domain'] || $config['cookie_domain'] == '127.0.0.1' || strpos($config['cookie_domain'], '.') === false) ? '' : '; domain=' . $config['cookie_domain']; |