2004-12-12 03:51:51 +00:00
|
|
|
<?php
|
|
|
|
|
/********************************************/
|
|
|
|
|
/* Account Login / Logout Handler for AppDB */
|
|
|
|
|
/********************************************/
|
2004-03-15 16:22:00 +00:00
|
|
|
|
|
|
|
|
include("path.php");
|
|
|
|
|
include(BASE."include/"."incl.php");
|
|
|
|
|
|
2004-12-12 03:51:51 +00:00
|
|
|
// set http header to not cache
|
2004-03-15 16:22:00 +00:00
|
|
|
header("Pragma: no-cache");
|
|
|
|
|
header("Cache-control: no-cache");
|
|
|
|
|
|
2004-12-12 03:51:51 +00:00
|
|
|
// check command and process
|
2004-12-10 01:07:45 +00:00
|
|
|
if(isset($_POST['cmd']))
|
2004-12-12 03:51:51 +00:00
|
|
|
do_account($_POST['cmd']);
|
2004-12-10 01:07:45 +00:00
|
|
|
else
|
2004-12-12 03:51:51 +00:00
|
|
|
do_account($_GET['cmd']);
|
|
|
|
|
|
2004-03-15 16:22:00 +00:00
|
|
|
|
2004-12-12 03:51:51 +00:00
|
|
|
/**
|
|
|
|
|
* process according to $cmd from URL
|
|
|
|
|
*/
|
2004-03-15 16:22:00 +00:00
|
|
|
function do_account($cmd = null)
|
|
|
|
|
{
|
2004-12-12 03:51:51 +00:00
|
|
|
if (!$cmd) return 0;
|
|
|
|
|
switch($cmd)
|
|
|
|
|
{
|
|
|
|
|
case "new":
|
|
|
|
|
apidb_header("New Account");
|
|
|
|
|
include(BASE."include/"."form_new.php");
|
|
|
|
|
apidb_footer();
|
|
|
|
|
exit;
|
|
|
|
|
|
|
|
|
|
case "do_new":
|
|
|
|
|
cmd_do_new();
|
|
|
|
|
exit;
|
|
|
|
|
|
|
|
|
|
case "login":
|
|
|
|
|
apidb_header("Login");
|
|
|
|
|
include(BASE."include/"."form_login.php");
|
|
|
|
|
apidb_footer();
|
|
|
|
|
exit;
|
|
|
|
|
|
|
|
|
|
case "do_login":
|
|
|
|
|
cmd_do_login();
|
|
|
|
|
exit;
|
|
|
|
|
|
|
|
|
|
case "send_passwd":
|
|
|
|
|
cmd_send_passwd();
|
|
|
|
|
exit;
|
|
|
|
|
|
|
|
|
|
case "logout":
|
2004-12-13 03:50:02 +00:00
|
|
|
$GLOBALS['session']->destroy();
|
2004-12-12 03:51:51 +00:00
|
|
|
addmsg("You are successfully logged out.", "green");
|
|
|
|
|
redirect(apidb_fullurl("index.php"));
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
//not valid command, display error page
|
|
|
|
|
errorpage("Internal Error","This module was called with incorrect parameters");
|
|
|
|
|
exit;
|
2004-03-15 16:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
2004-12-12 03:51:51 +00:00
|
|
|
/**
|
|
|
|
|
* retry
|
|
|
|
|
*/
|
2004-03-15 16:22:00 +00:00
|
|
|
function retry($cmd, $msg)
|
|
|
|
|
{
|
|
|
|
|
addmsg($msg, "red");
|
|
|
|
|
do_account($cmd);
|
|
|
|
|
}
|
|
|
|
|
|
2004-12-12 03:51:51 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* create new account
|
|
|
|
|
*/
|
2004-03-15 16:22:00 +00:00
|
|
|
function cmd_do_new()
|
|
|
|
|
{
|
2004-12-10 01:07:45 +00:00
|
|
|
|
|
|
|
|
if(ereg("^.+@.+\\..+$", $_POST['ext_username']))
|
2004-12-12 03:51:51 +00:00
|
|
|
{
|
|
|
|
|
$_POST['ext_username'] = "";
|
|
|
|
|
retry("new", "Invalid Username, must not contain special characters");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2004-12-10 01:07:45 +00:00
|
|
|
if(strlen($_POST['ext_username']) < 3)
|
2004-12-12 03:51:51 +00:00
|
|
|
{
|
|
|
|
|
$_POST['ext_username'] = "";
|
|
|
|
|
retry("new", "Username must be at least 3 characters");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2004-12-10 01:07:45 +00:00
|
|
|
if(strlen($_POST['ext_password']) < 5)
|
2004-12-12 03:51:51 +00:00
|
|
|
{
|
|
|
|
|
retry("new", "Password must be at least 5 characters");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2004-12-10 01:07:45 +00:00
|
|
|
if($_POST['ext_password'] != $_POST['ext_password2'])
|
2004-12-12 03:51:51 +00:00
|
|
|
{
|
|
|
|
|
retry("new", "Passwords don't match");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2004-12-10 01:07:45 +00:00
|
|
|
if(!isset($_POST['ext_realname']))
|
2004-12-12 03:51:51 +00:00
|
|
|
{
|
|
|
|
|
retry("new", "You don't have a Real name?");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2004-12-10 01:07:45 +00:00
|
|
|
if(!ereg("^.+@.+\\..+$", $_POST['ext_email']))
|
2004-12-12 03:51:51 +00:00
|
|
|
{
|
|
|
|
|
$_POST['ext_email'] = "";
|
|
|
|
|
retry("new", "Invalid email address");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2004-03-15 16:22:00 +00:00
|
|
|
|
|
|
|
|
$user = new User();
|
|
|
|
|
|
2004-12-10 01:07:45 +00:00
|
|
|
if($user->exists($_POST['ext_username']))
|
2004-12-12 03:51:51 +00:00
|
|
|
{
|
|
|
|
|
$_POST['ext_username'] = "";
|
|
|
|
|
retry("new", "That username is already in use");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2004-03-15 16:22:00 +00:00
|
|
|
|
2004-12-10 01:07:45 +00:00
|
|
|
$result = $user->create($_POST['ext_username'], $_POST['ext_password'], $_POST['ext_realname'], $_POST['ext_email']);
|
2004-03-15 16:22:00 +00:00
|
|
|
|
|
|
|
|
if($result == null)
|
2004-12-12 03:51:51 +00:00
|
|
|
{
|
|
|
|
|
$user->login($_POST['ext_username'], $_POST['ext_password']);
|
|
|
|
|
addmsg("Account created! (".$_POST['ext_username'].")", "green");
|
|
|
|
|
redirect(apidb_fullurl());
|
|
|
|
|
}
|
2004-03-15 16:22:00 +00:00
|
|
|
else
|
2004-12-01 22:26:04 +00:00
|
|
|
retry("new", "Failed to create account: $result");
|
2004-03-15 16:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
2004-12-12 03:51:51 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* email lost password
|
|
|
|
|
*/
|
2004-03-15 16:22:00 +00:00
|
|
|
function cmd_send_passwd()
|
|
|
|
|
{
|
|
|
|
|
$user = new User();
|
|
|
|
|
|
2004-12-10 01:07:45 +00:00
|
|
|
$userid = $user->lookup_userid($_POST['ext_username']);
|
2004-03-15 16:22:00 +00:00
|
|
|
$passwd = generate_passwd();
|
|
|
|
|
|
|
|
|
|
if ($userid)
|
2004-12-12 03:51:51 +00:00
|
|
|
{
|
2004-12-01 22:26:04 +00:00
|
|
|
if ($user->update($userid, $passwd))
|
|
|
|
|
{
|
2004-03-15 16:22:00 +00:00
|
|
|
$msg = "Application DB Lost Password\n";
|
|
|
|
|
$msg .= "----------------------------\n";
|
|
|
|
|
$msg .= "We have received a request that you lost your password.\n";
|
|
|
|
|
$msg .= "We will create a new password for you. You can then change\n";
|
|
|
|
|
$msg .= "your password at the Preferences screen.\n\n";
|
|
|
|
|
$msg .= "Your new password is: ".$passwd."\n\n";
|
2004-12-01 22:26:04 +00:00
|
|
|
|
|
|
|
|
if (mail($user->lookup_email($userid), '[AppDB] Lost Password', $msg))
|
|
|
|
|
{
|
|
|
|
|
addmsg("Your new password has been emailed to you.", "green");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
addmsg("Your password has changed, but we could not email it to you. Contact Support!", "red");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
addmsg("Internal Error, we could not update your password.", "red");
|
|
|
|
|
}
|
2004-03-15 16:22:00 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2004-12-19 17:54:09 +00:00
|
|
|
addmsg("Sorry, that username (". urlencode($_POST['ext_username']) .") does not exist.", "red");
|
2004-03-15 16:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
redirect(apidb_fullurl("account.php?cmd=login"));
|
|
|
|
|
}
|
|
|
|
|
|
2004-12-12 03:51:51 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* on login handler
|
|
|
|
|
*/
|
2004-03-15 16:22:00 +00:00
|
|
|
function cmd_do_login()
|
|
|
|
|
{
|
|
|
|
|
$user = new User();
|
2004-12-10 01:07:45 +00:00
|
|
|
$result = $user->login($_POST['ext_username'], $_POST['ext_password']);
|
2004-03-15 16:22:00 +00:00
|
|
|
|
|
|
|
|
if($result == null)
|
2004-12-12 03:51:51 +00:00
|
|
|
{
|
|
|
|
|
$_SESSION['current'] = $user;
|
|
|
|
|
addmsg("You are successfully logged in as '$user->username'.", "green");
|
|
|
|
|
redirect(apidb_fullurl("index.php"));
|
|
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
retry("login","Login failed ($result)");
|
|
|
|
|
$_SESSION['current'] = "";
|
|
|
|
|
}
|
2004-03-15 16:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
2004-12-12 03:51:51 +00:00
|
|
|
?>
|