- replaced tons of tabs with spaces

- replaced <? with <?php for compatibility sake (see TODO and CODING_STANDARD to know more)
- improved overall code lisibility
This commit is contained in:
Jonathan Ernst
2004-12-12 03:51:51 +00:00
committed by WineHQ
parent 7270e4cabc
commit d3d9e853d9
73 changed files with 1156 additions and 1219 deletions

View File

@@ -1,131 +1,140 @@
<?
/*
* Account Login / Logout Handler for AppDB
*
*/
<?php
/********************************************/
/* Account Login / Logout Handler for AppDB */
/********************************************/
include("path.php");
include(BASE."include/"."incl.php");
//set http header to not cache
// set http header to not cache
header("Pragma: no-cache");
header("Cache-control: no-cache");
//check command and process
// check command and process
if(isset($_POST['cmd']))
do_account($_POST['cmd']);
do_account($_POST['cmd']);
else
do_account($_GET['cmd']);
do_account($_GET['cmd']);
//process according to $cmd from URL
/**
* process according to $cmd from URL
*/
function do_account($cmd = null)
{
if (! $cmd) return 0;
switch($cmd)
{
case "new":
apidb_header("New Account");
include(BASE."include/"."form_new.php");
apidb_footer();
exit;
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 "do_new":
cmd_do_new();
exit;
case "login":
apidb_header("Login");
include(BASE."include/"."form_login.php");
apidb_footer();
exit;
case "login":
apidb_header("Login");
include(BASE."include/"."form_login.php");
apidb_footer();
exit;
case "do_login":
cmd_do_login();
exit;
case "do_login":
cmd_do_login();
exit;
case "send_passwd":
cmd_send_passwd();
exit;
case "send_passwd":
cmd_send_passwd();
exit;
case "logout":
apidb_session_destroy();
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;
case "logout":
apidb_session_destroy();
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;
}
//retry
/**
* retry
*/
function retry($cmd, $msg)
{
addmsg($msg, "red");
do_account($cmd);
}
//create new account
/**
* create new account
*/
function cmd_do_new()
{
if(ereg("^.+@.+\\..+$", $_POST['ext_username']))
{
$_POST['ext_username'] = "";
retry("new", "Invalid Username, must not contain special characters");
return;
}
{
$_POST['ext_username'] = "";
retry("new", "Invalid Username, must not contain special characters");
return;
}
if(strlen($_POST['ext_username']) < 3)
{
$_POST['ext_username'] = "";
retry("new", "Username must be at least 3 characters");
return;
}
{
$_POST['ext_username'] = "";
retry("new", "Username must be at least 3 characters");
return;
}
if(strlen($_POST['ext_password']) < 5)
{
retry("new", "Password must be at least 5 characters");
return;
}
{
retry("new", "Password must be at least 5 characters");
return;
}
if($_POST['ext_password'] != $_POST['ext_password2'])
{
retry("new", "Passwords don't match");
return;
}
{
retry("new", "Passwords don't match");
return;
}
if(!isset($_POST['ext_realname']))
{
retry("new", "You don't have a Real name?");
return;
}
{
retry("new", "You don't have a Real name?");
return;
}
if(!ereg("^.+@.+\\..+$", $_POST['ext_email']))
{
$_POST['ext_email'] = "";
retry("new", "Invalid email address");
return;
}
{
$_POST['ext_email'] = "";
retry("new", "Invalid email address");
return;
}
$user = new User();
if($user->exists($_POST['ext_username']))
{
$_POST['ext_username'] = "";
retry("new", "That username is already in use");
return;
}
{
$_POST['ext_username'] = "";
retry("new", "That username is already in use");
return;
}
$result = $user->create($_POST['ext_username'], $_POST['ext_password'], $_POST['ext_realname'], $_POST['ext_email']);
if($result == null)
{
$user->login($_POST['ext_username'], $_POST['ext_password']);
addmsg("Account created! (".$_POST['ext_username'].")", "green");
redirect(apidb_fullurl());
}
{
$user->login($_POST['ext_username'], $_POST['ext_password']);
addmsg("Account created! (".$_POST['ext_username'].")", "green");
redirect(apidb_fullurl());
}
else
retry("new", "Failed to create account: $result");
}
//email lost password
/**
* email lost password
*/
function cmd_send_passwd()
{
$user = new User();
@@ -134,7 +143,7 @@ function cmd_send_passwd()
$passwd = generate_passwd();
if ($userid)
{
{
if ($user->update($userid, $passwd))
{
$msg = "Application DB Lost Password\n";
@@ -166,23 +175,25 @@ function cmd_send_passwd()
redirect(apidb_fullurl("account.php?cmd=login"));
}
//on login handler
/**
* on login handler
*/
function cmd_do_login()
{
$user = new User();
$result = $user->login($_POST['ext_username'], $_POST['ext_password']);
if($result == null)
{
$_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'] = "";
}
{
$_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'] = "";
}
}
?>
?>