[ticket/13740] Login admin when install finished

PHPBB3-13740
This commit is contained in:
Mate Bartus 2015-07-23 20:50:33 +02:00
parent dd31020fb3
commit fbd5929606
7 changed files with 101 additions and 7 deletions

View file

@ -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');

View file

@ -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

View file

@ -43,6 +43,11 @@ class ajax_iohandler extends iohandler_base
*/
protected $nav_data;
/**
* @var array
*/
protected $cookies;
/**
* Constructor
*
@ -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;
}
@ -252,6 +264,17 @@ class ajax_iohandler extends iohandler_base
$this->send_response();
}
/**
* {@inheritdoc}
*/
public function set_cookie($cookie_name, $cookie_value)
{
$this->cookies[] = array(
'name' => $cookie_name,
'value' => $cookie_value
);
}
/**
* Callback function for language replacing
*

View file

@ -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)
{
}
}

View file

@ -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);
}

View file

@ -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');
}

View file

@ -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'];