[Astrospaces-commits] SF.net SVN: astrospaces: [6] trunk
Brought to you by:
p3net
From: <p3...@us...> - 2007-03-11 18:12:55
|
Revision: 6 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=6&view=rev Author: p3net Date: 2007-03-11 11:12:54 -0700 (Sun, 11 Mar 2007) Log Message: ----------- -Add basic profile functions --Login --Logout -Add installer Modified Paths: -------------- trunk/common.php trunk/includes/db.php trunk/includes/profile.php trunk/includes/template.php trunk/profile.php trunk/styles/default/outer.tpl Added Paths: ----------- trunk/install/install.php trunk/styles/default/install.tpl trunk/styles/default/login.tpl Modified: trunk/common.php =================================================================== --- trunk/common.php 2007-03-11 15:53:11 UTC (rev 5) +++ trunk/common.php 2007-03-11 18:12:54 UTC (rev 6) @@ -71,8 +71,8 @@ define('SESSION_LEVEL', $level); //Unload the two vars we just used as temps - $id=null; - $level=null; + unset($id); + unset($level); } //Construct and include everything needed on every page. @@ -103,7 +103,7 @@ while($temp=$db->array($query)) { //Put it in a lovely 'define' variable... - define($temp["config_name"], $temp["config_value"]); + define(strtoupper("CONFIG_" . $temp["config_name"]), $temp["config_value"]); } $temp=null; //Unload the $temp var } @@ -113,6 +113,7 @@ { $head =& new template('outer.tpl'); $head->set('level', SESSION_LEVEL); + $head->set('name', CONFIG_SITE_NAME); $head->set('content', $content); } Modified: trunk/includes/db.php =================================================================== --- trunk/includes/db.php 2007-03-11 15:53:11 UTC (rev 5) +++ trunk/includes/db.php 2007-03-11 18:12:54 UTC (rev 6) @@ -41,13 +41,13 @@ } //Connecting to the db is important - function connect() + function connect($db_server="",$db_user="",$db_password="",$db_database="",$dbms="") { //Include the config file include('../config.php'); //Connect to a MySQL database - if($dmbs == "mysql") + if($dbms == "mysql") { mysql_connect($db_server, $db_user, $db_password) or general_error("Could not connect to database"); @@ -55,13 +55,13 @@ } //Connect to a Postgre SQL database - else if($dmbs == "pgsql") + else if($dbms == "pgsql") { pg_connect("host=" . $db_server . " dbname=" . $db_database . " dbuser=" . $db_user . " db_password=" . $db_password) or general_error("Could not connect to database"); } } - function schema() + function schema($prefix="") { //Now we have to setup our schema layout into defined constants include('../config.php'); @@ -71,8 +71,10 @@ define('DB_PM', $prefix . "private_message"); define('DB_CONFIG', $prefix . "config"); define('DB_THEMES', $prefix . "themes"); + define('DB_SPACE', $prefix . "space"); + define('DB_BLOG', $prefix . "blogs"); } - function query($query) + function query($query="") { //Query for SQL databases @@ -84,7 +86,7 @@ } //PostgreSQL - else if($dmbs == "pgsql") + else if($dbms == "pgsql") { $_query=pg_query($query) or die("Error executing query " . $query . ": " . pg_last_error()); } Modified: trunk/includes/profile.php =================================================================== --- trunk/includes/profile.php 2007-03-11 15:53:11 UTC (rev 5) +++ trunk/includes/profile.php 2007-03-11 18:12:54 UTC (rev 6) @@ -53,15 +53,79 @@ $outer->set('message', "Your passwords did not match"); } //Time to insert... - $_query="INSERT INTO " . DB_USERS . " VALUES('', '" . $var["username"] . "', '" . md5($var["password"]) . + $_query="INSERT INTO " . DB_USERS . " VALUES('', '1', '" . $var["username"] . "', '" . md5($var["password"]) . "', '" . $var["email"] . "', '" . $var["aim"] . "', '" . $var["msn"] . "', '" . $var["irc"] . - "', '" . $var["icq"] . "', '" . $var["yahoo"] . "', '" . $var["website"] ."');"; + "', '" . $var["icq"] . "', '" . $var["yahoo"] . "', '" . $var["website"] .", '" . time() . "');"; //Run the query $db->query($_query); + //Put some default information into his space + $_defspace="INSERT INTO `" . DB_SPACE . "` VALUES('', 'Welcome to AstroSPACES!', 'You can edit " . + "these areas and more in your edit profile page!'); + + $db->query($_defspace); + //Display a thankyou thankyou("registering", "login", "profile.php?mode=login"); } + function login() + { + //First make sure we're not logged in + if(login_check) + { + //We are, so redirect to our space + header('location: space.php'); + } + //Just display the TPL's. Pretty simple + $form =& new template('login.tpl'); + $outer =& new template('outer.tpl'); + $outer->set('content', $form); + } + function loginGo($vars) + { + if(login_check) + { + //We are, so redirect to our space + header('location: space.php'); + } + foreach($vars as $scrub) + { + $scrub=sanitize($scrub); + } + $vars["password"] = md5($password); + $_query="SELECT * FROM `" . DB_USERS . "` WHERE `password`='" . $vars["password"] . + "' AND `email`=$vars["email"]"; + $_query=$db->query($_query); + if(count($db->array($_query)) < 1) + { + $form =& new template('login.tpl'); + $outer =& new template('outer.tpl'); + $outer->set('message', "Username or password incorrect."); + $outer->set('content', $form); + die(); + } + while($array=$db->array($_query)) + { + $_SESSION["id"]=$array["id"]; + $_SESSION["level"]=$array["level"]; + } + thankyou("logging in", "your space", "space.php", "go to the index", "index.php"); + } + function logout() + { + //First make sure we are logged in + if(login_check) + { + session_destroy; + unset($_SESSION); + thankyou("visting", "go to the index", "index.php"); + } + //If we're not, redirect to login + else + { + header('location: profile.php?mode=login'); + } + } } ?> \ No newline at end of file Modified: trunk/includes/template.php =================================================================== --- trunk/includes/template.php 2007-03-11 15:53:11 UTC (rev 5) +++ trunk/includes/template.php 2007-03-11 18:12:54 UTC (rev 6) @@ -58,7 +58,7 @@ } function fetch($file = null) { - $stylename = is_defined('STYLE_NAME') ? STYLE_NAME : 'default'; + $stylename = is_defined('STYLE_NAME') ? STYLE_NAME : CONFIG_DEFAULT_STYLE; if(!$file) $file = $this->file; extract($this->vars); // Extract the vars to local namespace Added: trunk/install/install.php =================================================================== --- trunk/install/install.php (rev 0) +++ trunk/install/install.php 2007-03-11 18:12:54 UTC (rev 6) @@ -0,0 +1,206 @@ + +<?php +/****************************************************************************** +* install/install.php +* AstroSPACES 2 +* +* Description: install/installer.php is the installer for AstroSPACES +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +* +* ID: $Id$ +* Author: $Author$ +******************************************************************************/ +define('IN_ASTRO', 1); +require("../common.php"); +require('../includes/template.php'); +//No need to construct as we don't have any DB information yet +$stage = !(empty($_REQUEST["stage"])) ? $_REQUEST["stage"] : 1; + +//We could use a switch here but things might get slightly confusing + +//Stage 1 -- Collect Information +if($stage=="1") +{ + //Just display the form :D + + $page =& new template('install.tpl'); + $outer =& new template('outer.tpl'); + $outer->set('content', $page); +} +else if($stage=="2") +{ + require("../includes/db.php"); + $db =& new db(); + + //Santize the information we got for db and the admin user + foreach($_POST as $scrub) + { + $scrub=sanitize($scrub); + } + + //Put all the information we got into variables + $dbms=$_POST["dbtype"]; + $db_server=$_POST["dbhost"]; + $db_user=$_POST["dbuser"]; + $db_password=$_POST["dbpass"]; + $prefix=$_POST["prefix"]; + $username=$_POST["user"]; + $password=$_POST["password"]; + $password2=$_POST["password2"]; + + //We don't need the $_POST array anymore + //So we'll unset it + unset($_POST); + + //Let's try to connect to the database + $db->connect($db_server,$db_user,$db_password,$db_database,$dbms); + $db->schema($prefix); + + //We could, so let's setup our installation queries... + $_users="CREATE TABLE IF NOT EXISTS `" . DB_USERS . "` ( + `id` int(11) NOT NULL auto_increment, + `user_level` int(1) NOT NULL default 1, + `username` text NOT NULL, + `password` text NOT NULL, + `email` varchar(25) NOT NULL, + `aim` text, + `msn` text, + `irc` text, + `irc` text, + `yahoo` text, + `website` text, + `last_login` int(15) NOT NULL default 0, + PRIMARY KEY (`id`) + ) TYPE=MyISAM AUTO_INCREMENT=1 ;"; + + $_comment="CREATE TABLE IF NOT EXISTS `" . DB_COMMENT . "` ( + `id` int(11) NOT NULL auto_increment, + `time` int(15) NOT NULL default 0, + `from` int(11) NOT NULL, + `to` int(11) NOT NULL, + `content` TEXT NOT NULL, + PRIMARY KEY (`id`) + ) TYPE=MyISAM AUTO_INCREMENT=1 ;"; + + $_friends="CREATE TABLE IF NOT EXISTS `" . DB_FRIENDS . "` ( + `from` int(11) NOT NULL, + `to` int(11) NOT NULL, + `approved` int(1) NOT NULL default 0 + ) TYPE=MyISAM ;"; + + $_pm="CREATE TABLE IF NOT EXISTS `" . DB_PM . "` ( + `id` int(11) NOT NULL auto_increment, + `to` int(11) NOT NULL, + `from` int(11) NOT NULL, + `time` int(15) NOT NULL default 0, + `content` text NOT NULL, + PRIMARY KEY (`id`) + ) TYPE=MyISAM AUTO_INCREMENT=1 ;"; + + $_config="CREATE TABLE IF NOT EXISTS `" . DB_CONFIG . "` ( + `config_name` text NOT NULL, + `config_value` text NOT NULL + ) TYPE=MyISAM ;"; + + $_themes="CREATE TABLE IF NOT EXISTS `" . DB_THEMES ."` ( + `id` int(11) NOT NULL auto_increment, + `name` text, + PRIMARY KEY (`id`) + ) TYPE=MyISAM AUTO_INCREMENT=1 ;"; + + $_space="CREATE TABLE IF NOT EXISTS `" . DB_SPACE . "` ( + `id` int(11) NOT NULL, + `left` text, + `right` text, + PRIMARY KEY (`id`) + ) TYPE=MyISAM AUTO_INCREMENT=1 ;"; + + $_blog="CREATE TABLE IF NOT EXISTS `" . DB_BLOG . "` ( + `by` int(11) NOT NULL, + `time` int(15) NOT NULL, + `post` text NOT NULL + ) TYPE=MyISAM ;"; + + //We've got all the queries setup -- time to run them! + //It would be more efficient to group them into one large + //query, but it'd make debugging harder. So, we'll run + //them one-by-one + + $db->query($_users); + $db->query($_comment); + $db->query($_friends); + $db->query($_pm); + $db->query($_config); + $db->query($_themes); + $db->query($_space); + $db->query($_blog); + + //Now let's register our admin user + $_reg="INSERT INTO `" . DB_USERS ."` (user_level, username, password, last_login) VALUES('2', '" . + $username . "', '" . md5($password) . "', '" . time() ."');"; + $db->query($_reg); + + //Put some default information into his space + $_defspace="INSERT INTO `" . DB_SPACE . "` VALUES('', 'Welcome to AstroSPACES!', 'You can edit " . + "these areas and more in your edit profile page!'); + + $db->query($_defspace); + + //Now let's insert some values into the config table + $_config = "INSERT INTO `" . DB_CONFIG . "` VALUES('site_name', 'AstroSPACES');"; + $_config .= " INSERT INTO `" . DB_CONFIG . "` VALUES('version', '2.0.0');"; + $_config .= " INSERT INTO `" . DB_CONFIG . "` VALUES('default_style', 'default');"; + $_config .= " INSERT INTO `" . DB_CONFIG . "` VALUES('created' , time());"; + $_config .= " INSERT INTO `" . DB_CONFIG . "` VALUES('time_format', 'd M Y h:i a');"; + $_config .= " INSERT INTO `" . DB_CONFIG . "` VALUES('time_offset', '0');"; + + $db->query($_config); + + //Now it's time for our default theme + $_theme="INSERT INTO `" . DB_THEMES . "` VALUES('', 'default'); + $db->query($_theme); + + //Now it's time to try and write our config file... + $config_file = " +<?php +//AstroSPACES auto-generated this file +//Do not change it unless you know what you are doing +$dbms = " . $dbms . "; +$db_server= " . $db_server . "; +$db_user= " . $db_user . "; +$db_password=" . $db_password . "; +$prefix=" . $prefix . "; +?>"; + $file="../config.php"; + if(is_writable($file)) + { + $handle=fopen('../config.php', 'w'); + if(fwrite($handle, $config_file === FALSE)) + { + general_error("Could not write config file. Please rerun installer."); + } + else + { + thankyou("installing AstroSPACES","the index","../index.php"); + } + } + else + { + general_error("Could not open config file for writing. Please ensure that" . + " is CHMOD'd 755 and rerun the installer."); + } +} +?> \ No newline at end of file Modified: trunk/profile.php =================================================================== --- trunk/profile.php 2007-03-11 15:53:11 UTC (rev 5) +++ trunk/profile.php 2007-03-11 18:12:54 UTC (rev 6) @@ -50,5 +50,14 @@ case 'process': $profile->regsub($_POST); break; + case 'login': + $profile->login(); + break; + case 'loginpro': + $profile->loginGo($_POST); + break; + case 'logout': + $profile->logout(); + break; } ?> \ No newline at end of file Added: trunk/styles/default/install.tpl =================================================================== --- trunk/styles/default/install.tpl (rev 0) +++ trunk/styles/default/install.tpl 2007-03-11 18:12:54 UTC (rev 6) @@ -0,0 +1,16 @@ +<form action="install.php?step=2" method="post"> +--Database Information-- + +Database Type: <select name="dbtype"><option value="mysql">MySQL</option><option value="pgsql">PostgreSQL</option></select> +Database Name: <input type="text" name="dbname"> +Database Username: <input type="text" name="dbuser"> +Database Password: <input type="text" name="dbpass"> +Database Host: <input type="text" name="dbhost"> +Table Prefix: <input type="text" name="prefix" value="astro_"> + +--Admin Account-- +Username: <input type="text" name="user"> +Password: <input type="text" name="password"> +Password [Confirm]: <input type="text" name="password2"> +<input type="submit" name="install" value="Install"> +</form> \ No newline at end of file Added: trunk/styles/default/login.tpl =================================================================== --- trunk/styles/default/login.tpl (rev 0) +++ trunk/styles/default/login.tpl 2007-03-11 18:12:54 UTC (rev 6) @@ -0,0 +1,2 @@ +Email Address: <input type="text" name="email"> +Password: <input type="password" name="password"> \ No newline at end of file Modified: trunk/styles/default/outer.tpl =================================================================== --- trunk/styles/default/outer.tpl 2007-03-11 15:53:11 UTC (rev 5) +++ trunk/styles/default/outer.tpl 2007-03-11 18:12:54 UTC (rev 6) @@ -1,6 +1,6 @@ <html> <head> - <title>AstroSPACES</title> + <title><?php echo $name; ?></title> <meta name="generator" content="Bluefish 1.0.6"> <style type="text/css"> @import('style.css'); @@ -11,9 +11,14 @@ <!--All Users--> <a href="index.php">Home</a> <!--/All Users--> + <!--Unauth'd Only--> + <?php if($level==-1) { ?> + <a href="profile.php?mode=login">Login</a> + <?php } ?> + <!--/Unauth'd Only--> <!--Auth'd Only--> <?php if($level>-1) { ?> - <!--Links here--> + <a href="profile.php?mode=logout">Logout</a> <?php } ?> <!--/Auth'd Only--> <!--Admin--> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |