include('config.inc');
include('functions.inc');
function dbsave($dbase, $data, $id=0) {
foreach ($data as $key=>$value) {
if ($key == "passwd") { $query .= "$key=PASSWORD('". addslashes($value) ."'), "; }
else { $query .= "$key='". addslashes($value) ."', "; }
}
$query = substr($query, 0, -2);
dbconnect();
if (!empty($id)) { mysql_query("UPDATE $dbase SET $query WHERE id=$id") or die(mysql_error()); return $id; }
else { mysql_query("INSERT INTO $dbase SET $query") or die(mysql_error()); return mysql_insert_id(); }
}
function showLogin($userid = "") {
print("
\n");
}
function showAccess() {
global $user, $access;
foreach ($access as $key=>$value) if ($user->access & $value) $result .= "$key ";
return $result;
}
function showUser() {
include('theme.inc');
$theme->header();
if (!empty($user->userid)) {
print("
Welcome $user->name! This is your user info page. There are many more, but this one is yours. You are probably most interested in editing something, but if you need to kill some time, this place is as good as any other place.
\n");
print("
\n");
print("
Name:
$user->name
\n");
print("
User ID:
$user->userid
\n");
print("
E-mail:
$user->email
\n");
if ($user->access > 0) print("
Access:
". showAccess() ."
\n");
print("
Bio:
$user->bio
\n");
print("
$user->ublock
\n");
print("
\n");
}
else { showLogin($userid); }
$theme->footer();
}
function newUser($user = "", $error="") {
include('theme.inc');
$theme->header();
print("\n");
$theme->footer();
}
function validateUser($user) {
### Verify username and e-mail address:
$user[userid] = trim($user[userid]);
if (empty($user[email]) || (!eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$", $user[email]))) $rval = "the specified e-mail address is not valid. ";
if (empty($user[userid]) || (ereg("[^a-zA-Z0-9_-]", $user[userid]))) $rval = "the specified username '$uname' is not valid. ";
if (strlen($user[userid]) > 15) $rval = "the specified username is too long: it must be less than 15 characters.";
if (eregi("^((root)|(httpd)|(operator)|(admin)|(administrator)|(news)|(deamon)|(nobody)|(ftp))$", $user[userid])) $rval = "the specified username is reserved.";
### Verify whether username and e-mail address are uniqua:
dbconnect();
if (mysql_num_rows(mysql_query("SELECT userid FROM testusers WHERE LOWER(userid)=LOWER('$user[userid]')")) > 0) $rval = "the specified username is already taken.";
if (mysql_num_rows(mysql_query("SELECT email FROM testusers WHERE LOWER(email)=LOWER('$user[email]')")) > 0) $rval = "the specified e-mail address is already registered.";
return($rval);
}
function makePassword($min_length=6) {
mt_srand((double)microtime() * 1000000);
$words = array("foo","bar","guy","neo","geek","nerd","fish","hack","star","moon","hero","cola","girl","fish","java","boss");
while(strlen($password) < $min_length) {
$password .= $words[mt_rand(0, count($words))];
}
return $password;
}
switch ($op) {
case "Login":
session_start();
$user = new User($userid,$passwd);
if ($user->valid()) { session_register("user"); }
showUser();
break;
case "new":
newUser();
break;
case "logout":
session_start();
session_destroy();
unset($user);
showUser();
break;
case "Register":
if ($rval = validateUser($new)) { newUser($new, "Error: $rval"); }
else {
include('theme.inc');
$new[passwd] = makePassword();
dbsave("testusers", $new);
$theme->header();
if ($system == 1) {
print("Your password is: $new[passwd] ");
print("Login to change your personal settings.");
} else {
$message = "Your $sitename member account has been created succesfully. To be able to use it you must login using the information below. Please save this mail for further reference.\n\n username: $new[userid]\n e-mail: $newu[email]\n password: $new[passwd]\n\nThis password is generated by a randomizer. It is recommended that you change this password immediately.\n\n$contact_signature";
$subject = "Account details for $sitename";
mail($new[email], $subject, $message, "From: $contact_email\nX-Mailer: PHP/" . phpversion());
print("Your member account has been created and the details necessary to login have been sent to your e-mail account $email. Once you received the account confirmation, hit this link to login.");
}
$theme->footer();
}
break;
case "edituser":
if ($user->valid() == 0) { showLogin(); }
include('theme.inc');
$theme->header();
print("\n");
$theme->footer();
break;
case "editpage":
include('theme.inc');
$theme->header();
print("\n");
$theme->footer();
break;
case "Save user information":
if ($user->valid()) {
$data[name] = $edit[name];
$data[email] = $edit[email];
$data[femail] = $edit[femail];
$data[url] = $edit[url];
$data[bio] = $edit[bio];
$data[ublock] = $edit[ublock];
$data[ublockon] = $edit[ublockon];
if ($edit[pass1] == $edit[pass2] && !empty($edit[pass1])) { $data[passwd] = $edit[pass1]; }
dbsave("testusers", $data, $user->id);
$user->update();
}
showUser();
break;
case "Save page settings":
if ($user->valid()) {
$data[theme] = $edit[theme];
$data[storynum] = $edit[storynum];
$data[umode] = $edit[umode];
$data[uorder] = $edit[uorder];
$data[thold] = $edit[thold];
$data[signature] = $edit[signature];
dbsave("testusers", $data, $user->id);
$user->update();
}
showUser();
break;
default: showUser();
}
?>