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
*/
function retry($cmd, $msg)
{
addmsg($msg, "red");
do_account($cmd);
}
/**
* create new account
*/
function cmd_do_new()
{
$aClean = array(); //array of filtered user input
$aClean['ext_email'] = makeSafe($_POST['ext_email']);
$aClean['ext_password'] = makeSafe($_POST['ext_password']);
$aClean['ext_password2'] = makeSafe($_POST['ext_password2']);
$aClean['CVSrelease'] = makeSafe($_POST['CVSrelease']);
$aClean['ext_realname']= makeSafe($_POST['ext_realname']);
if(!ereg("^.+@.+\\..+$", $aClean['ext_email']))
{
$aClean['ext_email'] = "";
retry("new", "Invalid email address");
return;
}
if(strlen($aClean['ext_password']) < 5)
{
retry("new", "Password must be at least 5 characters");
return;
}
if($aClean['ext_password'] != $aClean['ext_password2'])
{
retry("new", "Passwords don't match");
return;
}
if(empty($aClean['ext_realname']))
{
retry("new", "You don't have a Real name?");
return;
}
$user = new User();
$result = $user->create($aClean['ext_email'], $aClean['ext_password'], $aClean['ext_realname'], $aClean['CVSrelease'] );
if($result == true)
{
/* if we can log the user in, log them in automatically */
if($user->login($aClean['ext_email'], $aClean['ext_password']))
$_SESSION['current'] = $user;
addmsg("Account created! (".$aClean['ext_email'].")", "green");
redirect(apidb_fullurl());
}
else
{
retry("new", "Failed to create account");
}
}
/**
* email lost password
*/
function cmd_send_passwd()
{
$aClean = array(); //array of filtered user input
$aClean['ext_email'] = makeSafe($_POST['ext_email']);
$note = '(Note: accounts for appdb.winehq.org and bugs.winehq.org '
.'are separated, so You might need to create second account for appdb.)';
$userid = user_exists($aClean['ext_email']);
$passwd = generate_passwd();
$user = new User($userid);
if ($userid)
{
if ($user->update(null, $passwd))
{
$sSubject = "Application DB Lost Password";
$sMsg = "We have received a request that you lost your password.\r\n";
$sMsg .= "We will create a new password for you. You can then change\r\n";
$sMsg .= "your password at the Preferences screen.\r\n";
$sMsg .= "Your new password is: ".$passwd."\r\n";
if (mail_appdb($user->sEmail, $sSubject ,$sMsg))
{
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 (".APPDB_OWNER_EMAIL.") !", "red");
}
}
else
{
addmsg("Internal Error, we could not update your password.", "red");
}
}
else
{
addmsg("Sorry, that user (".$aClean['ext_email'].") does not exist.
"
.$note, "red");
}
redirect(apidb_fullurl("account.php?cmd=login"));
}
/**
* on login handler
*/
function cmd_do_login()
{
$aClean = array(); //array of filtered user input
$aClean['ext_email'] = makeSafe($_POST['ext_email']);
$aClean['ext_password'] = makeSafe($_POST['ext_password']);
$user = new User();
$result = $user->login($aClean['ext_email'], $aClean['ext_password']);
if($result == true)
{
$_SESSION['current'] = $user;
addmsg("You are successfully logged in as '$user->sRealname'.", "green");
redirect(apidb_fullurl("index.php"));
} else
{
retry("login","Login failed ".$note);
$_SESSION['current'] = "";
}
}
?>