Installer tweaks: maintain form values when redisplaying form after error, add pass confirmation and optional email forms for administrator.
Caveat: fancy URLs value isn't currently maintained; JS needs updating to not overwrite the value or we should kill it entirely.
This commit is contained in:
parent
9f861e9d89
commit
8b3febab55
85
install.php
85
install.php
|
@ -435,15 +435,39 @@ E_O_T;
|
||||||
E_O_T;
|
E_O_T;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper class for building form
|
||||||
|
*/
|
||||||
|
class Posted {
|
||||||
|
function value($name)
|
||||||
|
{
|
||||||
|
if (isset($_POST[$name])) {
|
||||||
|
return htmlspecialchars(strval($_POST[$name]));
|
||||||
|
} else {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function showForm()
|
function showForm()
|
||||||
{
|
{
|
||||||
global $dbModules;
|
global $dbModules;
|
||||||
|
$post = new Posted();
|
||||||
$dbRadios = '';
|
$dbRadios = '';
|
||||||
$checked = 'checked="checked" '; // Check the first one which exists
|
if (isset($_POST['dbtype'])) {
|
||||||
|
$dbtype = $_POST['dbtype'];
|
||||||
|
} else {
|
||||||
|
$dbtype = null;
|
||||||
|
}
|
||||||
foreach ($dbModules as $type => $info) {
|
foreach ($dbModules as $type => $info) {
|
||||||
if (checkExtension($info['check_module'])) {
|
if (checkExtension($info['check_module'])) {
|
||||||
|
if ($dbtype == null || $dbtype == $type) {
|
||||||
|
$checked = 'checked="checked" ';
|
||||||
|
$dbtype = $type; // if we didn't have one checked, hit the first
|
||||||
|
} else {
|
||||||
|
$checked = '';
|
||||||
|
}
|
||||||
$dbRadios .= "<input type=\"radio\" name=\"dbtype\" id=\"dbtype-$type\" value=\"$type\" $checked/> $info[name]<br />\n";
|
$dbRadios .= "<input type=\"radio\" name=\"dbtype\" id=\"dbtype-$type\" value=\"$type\" $checked/> $info[name]<br />\n";
|
||||||
$checked = '';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo<<<E_O_T
|
echo<<<E_O_T
|
||||||
|
@ -464,7 +488,7 @@ function showForm()
|
||||||
<ul class="form_data">
|
<ul class="form_data">
|
||||||
<li>
|
<li>
|
||||||
<label for="sitename">Site name</label>
|
<label for="sitename">Site name</label>
|
||||||
<input type="text" id="sitename" name="sitename" />
|
<input type="text" id="sitename" name="sitename" value="{$post->value('sitename')}" />
|
||||||
<p class="form_guide">The name of your site</p>
|
<p class="form_guide">The name of your site</p>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
@ -475,7 +499,7 @@ function showForm()
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<label for="host">Hostname</label>
|
<label for="host">Hostname</label>
|
||||||
<input type="text" id="host" name="host" />
|
<input type="text" id="host" name="host" value="{$post->value('host')}" />
|
||||||
<p class="form_guide">Database hostname</p>
|
<p class="form_guide">Database hostname</p>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
@ -487,29 +511,38 @@ function showForm()
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
<label for="database">Name</label>
|
<label for="database">Name</label>
|
||||||
<input type="text" id="database" name="database" />
|
<input type="text" id="database" name="database" value="{$post->value('database')}" />
|
||||||
<p class="form_guide">Database name</p>
|
<p class="form_guide">Database name</p>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<label for="username">DB username</label>
|
<label for="dbusername">DB username</label>
|
||||||
<input type="text" id="username" name="username" />
|
<input type="text" id="dbusername" name="dbusername" value="{$post->value('dbusername')}" />
|
||||||
<p class="form_guide">Database username</p>
|
<p class="form_guide">Database username</p>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<label for="password">DB password</label>
|
<label for="dbpassword">DB password</label>
|
||||||
<input type="password" id="password" name="password" />
|
<input type="password" id="dbpassword" name="dbpassword" value="{$post->value('dbpassword')}" />
|
||||||
<p class="form_guide">Database password (optional)</p>
|
<p class="form_guide">Database password (optional)</p>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<label for="admin_nickname">Administrator nickname</label>
|
<label for="admin_nickname">Administrator nickname</label>
|
||||||
<input type="text" id="admin_nickname" name="admin_nickname" />
|
<input type="text" id="admin_nickname" name="admin_nickname" value="{$post->value('admin_nickname')}" />
|
||||||
<p class="form_guide">Nickname for the initial StatusNet user (administrator)</p>
|
<p class="form_guide">Nickname for the initial StatusNet user (administrator)</p>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<label for="initial_user_password">Administrator password</label>
|
<label for="admin_password">Administrator password</label>
|
||||||
<input type="password" id="admin_password" name="admin_password" />
|
<input type="password" id="admin_password" name="admin_password" value="{$post->value('admin_password')}" />
|
||||||
<p class="form_guide">Password for the initial StatusNet user (administrator)</p>
|
<p class="form_guide">Password for the initial StatusNet user (administrator)</p>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<label for="admin_password2">Confirm password</label>
|
||||||
|
<input type="password" id="admin_password2" name="admin_password2" value="{$post->value('admin_password2')}" />
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<label for="admin_email">Administrator e-mail</label>
|
||||||
|
<input id="admin_email" name="admin_email" value="{$post->value('admin_email')}" />
|
||||||
|
<p class="form_guide">Optional email address for the initial StatusNet user (administrator)</p>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<input type="submit" name="submit" class="submit" value="Submit" />
|
<input type="submit" name="submit" class="submit" value="Submit" />
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
@ -528,13 +561,15 @@ function handlePost()
|
||||||
$host = $_POST['host'];
|
$host = $_POST['host'];
|
||||||
$dbtype = $_POST['dbtype'];
|
$dbtype = $_POST['dbtype'];
|
||||||
$database = $_POST['database'];
|
$database = $_POST['database'];
|
||||||
$username = $_POST['username'];
|
$username = $_POST['dbusername'];
|
||||||
$password = $_POST['password'];
|
$password = $_POST['dbpassword'];
|
||||||
$sitename = $_POST['sitename'];
|
$sitename = $_POST['sitename'];
|
||||||
$fancy = !empty($_POST['fancy']);
|
$fancy = !empty($_POST['fancy']);
|
||||||
|
|
||||||
$adminNick = $_POST['admin_nickname'];
|
$adminNick = $_POST['admin_nickname'];
|
||||||
$adminPass = $_POST['admin_password'];
|
$adminPass = $_POST['admin_password'];
|
||||||
|
$adminPass2 = $_POST['admin_password2'];
|
||||||
|
$adminEmail = $_POST['admin_email'];
|
||||||
|
|
||||||
$server = $_SERVER['HTTP_HOST'];
|
$server = $_SERVER['HTTP_HOST'];
|
||||||
$path = substr(dirname($_SERVER['PHP_SELF']), 1);
|
$path = substr(dirname($_SERVER['PHP_SELF']), 1);
|
||||||
|
@ -576,6 +611,11 @@ STR;
|
||||||
updateStatus("No initial StatusNet user password specified.", true);
|
updateStatus("No initial StatusNet user password specified.", true);
|
||||||
$fail = true;
|
$fail = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($adminPass != $adminPass2) {
|
||||||
|
updateStatus("Administrator passwords do not match. Did you mistype?", true);
|
||||||
|
$fail = true;
|
||||||
|
}
|
||||||
|
|
||||||
if ($fail) {
|
if ($fail) {
|
||||||
showForm();
|
showForm();
|
||||||
|
@ -600,7 +640,7 @@ STR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Okay, cross fingers and try to register an initial user
|
// Okay, cross fingers and try to register an initial user
|
||||||
if (registerInitialUser($adminNick, $adminPass)) {
|
if (registerInitialUser($adminNick, $adminPass, $adminEmail)) {
|
||||||
updateStatus(
|
updateStatus(
|
||||||
"An initial user with the administrator role has been created."
|
"An initial user with the administrator role has been created."
|
||||||
);
|
);
|
||||||
|
@ -797,19 +837,20 @@ function runDbScript($filename, $conn, $type = 'mysqli')
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function registerInitialUser($nickname, $password)
|
function registerInitialUser($nickname, $password, $email)
|
||||||
{
|
{
|
||||||
define('STATUSNET', true);
|
define('STATUSNET', true);
|
||||||
define('LACONICA', true); // compatibility
|
define('LACONICA', true); // compatibility
|
||||||
|
|
||||||
require_once INSTALLDIR . '/lib/common.php';
|
require_once INSTALLDIR . '/lib/common.php';
|
||||||
|
|
||||||
$user = User::register(
|
$data = array('nickname' => $nickname,
|
||||||
array('nickname' => $nickname,
|
'password' => $password,
|
||||||
'password' => $password,
|
'fullname' => $nickname);
|
||||||
'fullname' => $nickname
|
if ($email) {
|
||||||
)
|
$data['email'] = $email;
|
||||||
);
|
}
|
||||||
|
$user = User::register($data);
|
||||||
|
|
||||||
if (empty($user)) {
|
if (empty($user)) {
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user