Create an initial user during install, and grant owner, moderator and administrator roles.

This commit is contained in:
Zach Copley 2010-03-03 23:26:45 -08:00
parent 37b106d49c
commit 44462ac617

View File

@ -31,6 +31,7 @@
* @author Robin Millette <millette@controlyourself.ca> * @author Robin Millette <millette@controlyourself.ca>
* @author Sarven Capadisli <csarven@status.net> * @author Sarven Capadisli <csarven@status.net>
* @author Tom Adams <tom@holizz.com> * @author Tom Adams <tom@holizz.com>
* @author Zach Copley <zach@status.net>
* @license GNU Affero General Public License http://www.gnu.org/licenses/ * @license GNU Affero General Public License http://www.gnu.org/licenses/
* @version 0.9.x * @version 0.9.x
* @link http://status.net * @link http://status.net
@ -490,15 +491,25 @@ function showForm()
<p class="form_guide">Database name</p> <p class="form_guide">Database name</p>
</li> </li>
<li> <li>
<label for="username">Username</label> <label for="username">DB username</label>
<input type="text" id="username" name="username" /> <input type="text" id="username" name="username" />
<p class="form_guide">Database username</p> <p class="form_guide">Database username</p>
</li> </li>
<li> <li>
<label for="password">Password</label> <label for="password">DB password</label>
<input type="password" id="password" name="password" /> <input type="password" id="password" name="password" />
<p class="form_guide">Database password (optional)</p> <p class="form_guide">Database password (optional)</p>
</li> </li>
<li>
<label for="admin_nickname">Administrator nickname</label>
<input type="text" id="admin_nickname" name="admin_nickname" />
<p class="form_guide">Nickname for the initial StatusNet user (administrator)</p>
</li>
<li>
<label for="initial_user_password">Administrator password</label>
<input type="password" id="admin_password" name="admin_password" />
<p class="form_guide">Password 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>
@ -521,6 +532,10 @@ function handlePost()
$password = $_POST['password']; $password = $_POST['password'];
$sitename = $_POST['sitename']; $sitename = $_POST['sitename'];
$fancy = !empty($_POST['fancy']); $fancy = !empty($_POST['fancy']);
$adminNick = $_POST['admin_nickname'];
$adminPass = $_POST['admin_password'];
$server = $_SERVER['HTTP_HOST']; $server = $_SERVER['HTTP_HOST'];
$path = substr(dirname($_SERVER['PHP_SELF']), 1); $path = substr(dirname($_SERVER['PHP_SELF']), 1);
@ -552,6 +567,16 @@ STR;
$fail = true; $fail = true;
} }
if (empty($adminNick)) {
updateStatus("No initial StatusNet user nickname specified.", true);
$fail = true;
}
if (empty($adminPass)) {
updateStatus("No initial StatusNet user password specified.", true);
$fail = true;
}
if ($fail) { if ($fail) {
showForm(); showForm();
return; return;
@ -574,13 +599,29 @@ STR;
return; return;
} }
// Okay, cross fingers and try to register an initial user
if (registerInitialUser($adminNick, $adminPass)) {
updateStatus(
"An initial user with the administrator role has been created."
);
} else {
updateStatus(
"Could not create initial StatusNet user (administrator).",
true
);
showForm();
return;
}
/* /*
TODO https needs to be considered TODO https needs to be considered
*/ */
$link = "http://".$server.'/'.$path; $link = "http://".$server.'/'.$path;
updateStatus("StatusNet has been installed at $link"); updateStatus("StatusNet has been installed at $link");
updateStatus("You can visit your <a href='$link'>new StatusNet site</a>."); updateStatus(
"You can visit your <a href='$link'>new StatusNet site</a> (login as '$adminNick')."
);
} }
function Pgsql_Db_installer($host, $database, $username, $password) function Pgsql_Db_installer($host, $database, $username, $password)
@ -756,6 +797,33 @@ function runDbScript($filename, $conn, $type = 'mysqli')
return true; return true;
} }
function registerInitialUser($nickname, $password)
{
define('STATUSNET', true);
define('LACONICA', true); // compatibility
require_once INSTALLDIR . '/lib/common.php';
$user = User::register(
array('nickname' => $nickname,
'password' => $password,
'fullname' => $nickname
)
);
if (empty($user)) {
return false;
}
// give initial user carte blanche
$user->grantRole('owner');
$user->grantRole('moderator');
$user->grantRole('administrator');
return true;
}
?> ?>
<?php echo"<?"; ?> xml version="1.0" encoding="UTF-8" <?php echo "?>"; ?> <?php echo"<?"; ?> xml version="1.0" encoding="UTF-8" <?php echo "?>"; ?>
<!DOCTYPE html <!DOCTYPE html