delayed user creation

This commit is contained in:
Shish 2009-01-22 01:39:44 -08:00
parent cffbaac039
commit b336b5296f
4 changed files with 35 additions and 43 deletions

View File

@ -83,10 +83,15 @@ class Index implements Extension {
$count = $config->get_int('index_width') * $config->get_int('index_height');
$images = Image::find_images($config, $database, ($page_number-1)*$count, $count, $search_terms);
send_event(new PostListBuildingEvent($event->page, $search_terms));
if(!(count($search_terms) == 0 && count($images) == 0)) {
send_event(new PostListBuildingEvent($event->page, $search_terms));
$this->theme->set_page($page_number, $total_pages, $search_terms);
$this->theme->display_page($event->page, $images);
$this->theme->set_page($page_number, $total_pages, $search_terms);
$this->theme->display_page($event->page, $images);
}
else {
$this->theme->display_intro($event->page);
}
}
if($event instanceof SetupBuildingEvent) {

View File

@ -7,6 +7,22 @@ class IndexTheme extends Themelet {
$this->search_terms = $search_terms;
}
public function display_intro(Page $page) {
$text = <<<EOD
<div style="text-align: left;">
<p>The first thing you'll probably want to do is create a new account; note
that the first account you create will by default be marked as the board's
administrator, and any further accounts will be regular users.
<p>Once logged in you can play with the settings, install extra features,
and of course start organising your images :-)
</div>
EOD;
$page->set_title("Welcome to Shimmie ".VERSION);
$page->set_heading("Welcome to Shimmie");
$page->add_block(new Block("Welcome", $text, "main", 0));
}
public function display_page(Page $page, $images) {
global $config;

View File

@ -233,9 +233,13 @@ class UserPage implements Extension {
$hash = md5(strtolower($event->username) . $event->password);
$email = (!empty($event->email)) ? $event->email : null;
// if there are currently no admins, the new user should be one
$need_admin = ($database->db->GetOne("SELECT COUNT(*) FROM users WHERE admin IN ('Y', 't', '1')") == 0);
$admin = $need_admin ? 'Y' : 'N';
$database->Execute(
"INSERT INTO users (name, pass, joindate, email) VALUES (?, ?, now(), ?)",
array($event->username, $hash, $email));
"INSERT INTO users (name, pass, joindate, email, admin) VALUES (?, ?, now(), ?, ?)",
array($event->username, $hash, $email, $admin));
}
private function set_login_cookie($name, $pass) {

View File

@ -59,16 +59,6 @@ require_once "lib/adodb/adodb-xmlschema03.inc.php";
do_install();
// utilities {{{
function installer_write_file($fname, $data) {
$fp = fopen($fname, "w");
if(!$fp) return false;
fwrite($fp, $data);
fclose($fp);
return true;
}
function check_gd_version() {
$gdversion = 0;
@ -120,8 +110,6 @@ function begin() { // {{{
<center>
<table>
<tr><td>Database:</td><td><input type="text" name="database_dsn" size="40"></td></tr>
<tr><td>Admin Name:</td><td><input type="text" name="admin_name" size="40"></td></tr>
<tr><td>Admin Pass:</td><td><input type="password" name="admin_pass" size="40"></td></tr>
<tr><td colspan="2"><center><input type="submit" value="Go!"></center></td></tr>
</table>
</center>
@ -140,32 +128,13 @@ function begin() { // {{{
EOD;
} // }}}
function install_process() { // {{{
if(!isset($_POST['database_dsn']) || !isset($_POST["admin_name"]) || !isset($_POST["admin_pass"])) {
die("Install is missing some paramaters (database_dsn, admin_name, or admin_pass)");
}
else if(strlen($_POST["admin_name"]) < 1 || strlen($_POST["admin_pass"]) < 1) {
die("Admin name and password must be at least one character each");
}
else {
$database_dsn = $_POST['database_dsn'];
$admin_name = $_POST["admin_name"];
$admin_pass = $_POST["admin_pass"];
}
set_admin_cookie($admin_name, $admin_pass);
$database_dsn = $_POST['database_dsn'];
create_tables($database_dsn);
insert_defaults($database_dsn, $admin_name, $admin_pass);
insert_defaults($database_dsn);
build_dirs();
write_config($database_dsn);
header("Location: index.php?q=setup");
} // }}}
function set_admin_cookie($admin_name, $admin_pass) { // {{{
$addr = $_SERVER['REMOTE_ADDR'];
$addr = inet_ntop(inet_pton($addr) & inet_pton("255.255.0.0"));
$hash = md5(strtolower($admin_name) . $admin_pass);
setcookie("shm_user", $admin_name, time()+60*60*24*365);
setcookie("shm_session", md5($hash.$addr), time()+60*60*24*7, "/");
header("Location: index.php");
} // }}}
function create_tables($dsn) { // {{{
$db = NewADOConnection($dsn);
@ -186,7 +155,7 @@ function create_tables($dsn) { // {{{
}
$db->Close();
} // }}}
function insert_defaults($dsn, $admin_name, $admin_pass) { // {{{
function insert_defaults($dsn) { // {{{
$db = NewADOConnection($dsn);
if(!$db) {
die("Couldn't connect to \"$dsn\"");
@ -194,11 +163,9 @@ function insert_defaults($dsn, $admin_name, $admin_pass) { // {{{
else {
$config_insert = $db->Prepare("INSERT INTO config(name, value) VALUES(?, ?)");
$user_insert = $db->Prepare("INSERT INTO users(name, pass, joindate, admin) VALUES(?, ?, now(), ?)");
$admin_pass = md5(strtolower($admin_name).$admin_pass);
$db->Execute($user_insert, Array('Anonymous', null, 'N'));
$db->Execute($config_insert, Array('anon_id', $db->Insert_ID()));
$db->Execute($user_insert, Array($admin_name, $admin_pass, 'Y'));
if(check_im_version() > 0) {
$db->Execute($config_insert, Array('thumb_engine', 'convert'));
@ -240,7 +207,7 @@ function build_dirs() { // {{{
function write_config($dsn) { // {{{
$file_content = "<?php \$database_dsn='$dsn'; ?>";
if(is_writable("./") && installer_write_file("config.php", $file_content)) {
if(is_writable("./") && file_put_contents("config.php", $file_content)) {
assert(file_exists("config.php"));
}
else {