diff options
author | Zach Copley <zach@status.net> | 2010-03-03 23:26:45 -0800 |
---|---|---|
committer | Zach Copley <zach@status.net> | 2010-03-04 00:00:46 -0800 |
commit | 44462ac617b315b206f757e3ee7932feabb3ca14 (patch) | |
tree | cf54a32f0a8750972b3d39dde105b1d16c4fad4d | |
parent | 37b106d49c7e6c563a1e7e4932ab5f458572964f (diff) |
Create an initial user during install, and grant owner, moderator and administrator roles.
-rw-r--r-- | install.php | 74 |
1 files changed, 71 insertions, 3 deletions
diff --git a/install.php b/install.php index 435f6d63b..6c0b8d8e6 100644 --- a/install.php +++ b/install.php @@ -31,6 +31,7 @@ * @author Robin Millette <millette@controlyourself.ca> * @author Sarven Capadisli <csarven@status.net> * @author Tom Adams <tom@holizz.com> + * @author Zach Copley <zach@status.net> * @license GNU Affero General Public License http://www.gnu.org/licenses/ * @version 0.9.x * @link http://status.net @@ -490,15 +491,25 @@ function showForm() <p class="form_guide">Database name</p> </li> <li> - <label for="username">Username</label> + <label for="username">DB username</label> <input type="text" id="username" name="username" /> <p class="form_guide">Database username</p> </li> <li> - <label for="password">Password</label> + <label for="password">DB password</label> <input type="password" id="password" name="password" /> <p class="form_guide">Database password (optional)</p> </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> <input type="submit" name="submit" class="submit" value="Submit" /> </fieldset> @@ -521,6 +532,10 @@ function handlePost() $password = $_POST['password']; $sitename = $_POST['sitename']; $fancy = !empty($_POST['fancy']); + + $adminNick = $_POST['admin_nickname']; + $adminPass = $_POST['admin_password']; + $server = $_SERVER['HTTP_HOST']; $path = substr(dirname($_SERVER['PHP_SELF']), 1); @@ -552,6 +567,16 @@ STR; $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) { showForm(); return; @@ -574,13 +599,29 @@ STR; 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 */ $link = "http://".$server.'/'.$path; 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) @@ -756,6 +797,33 @@ function runDbScript($filename, $conn, $type = 'mysqli') 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 "?>"; ?> <!DOCTYPE html |