From b336b5296f234ef2d17dbdb9cfd650bb13645b52 Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 22 Jan 2009 01:39:44 -0800 Subject: [PATCH] delayed user creation --- ext/index/main.php | 11 ++++++++--- ext/index/theme.php | 16 ++++++++++++++++ ext/user/main.php | 8 ++++++-- install.php | 43 +++++-------------------------------------- 4 files changed, 35 insertions(+), 43 deletions(-) diff --git a/ext/index/main.php b/ext/index/main.php index 2cac858e..d781cb4e 100644 --- a/ext/index/main.php +++ b/ext/index/main.php @@ -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) { diff --git a/ext/index/theme.php b/ext/index/theme.php index 8b4b1723..4f596083 100644 --- a/ext/index/theme.php +++ b/ext/index/theme.php @@ -7,6 +7,22 @@ class IndexTheme extends Themelet { $this->search_terms = $search_terms; } + public function display_intro(Page $page) { + $text = << +

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. + +

Once logged in you can play with the settings, install extra features, +and of course start organising your images :-) + +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; diff --git a/ext/user/main.php b/ext/user/main.php index 1b953d78..9da15ff3 100644 --- a/ext/user/main.php +++ b/ext/user/main.php @@ -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) { diff --git a/install.php b/install.php index a91c40e4..aa907085 100644 --- a/install.php +++ b/install.php @@ -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() { // {{{

- -
Database:
Admin Name:
Admin Pass:
@@ -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 = ""; - 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 {