Cleanup User class. Move user related functions into class as static member functions

This commit is contained in:
Chris Morgan
2006-06-29 15:54:29 +00:00
committed by WineHQ
parent df8baf54fe
commit 245a6b993e
16 changed files with 202 additions and 213 deletions

View File

@@ -152,8 +152,8 @@ function cmd_send_passwd()
$note = '(<b>Note</b>: accounts for <b>appdb</b>.winehq.org and <b>bugs</b>.winehq.org '
.'are separated, so You might need to <b>create second</b> account for appdb.)';
$userid = user_exists($aClean['ext_email']);
$passwd = generate_passwd();
$userid = User::exists($aClean['ext_email']);
$passwd = User::generate_passwd();
$user = new User($userid);
if ($userid)
{

View File

@@ -123,7 +123,7 @@ if (!$aClean['id'])
echo '<td>';
$imgSRC = '<img width="'.$oScreenshot->oThumbnailImage->width.'" height="'.$oScreenshot->oThumbnailImage->height.'" src="../appimage.php?queued=true&id='.$obj_row->id.'" />';
// generate random tag for popup window
$randName = generate_passwd(5);
$randName = User::generate_passwd(5);
// set image link based on user pref
$img = '<a href="javascript:openWin(\'../appimage.php?queued=true&id='.$obj_row->id.'\',\''.$randName.'\','.$oScreenshot->oScreenshotImage->width.','.($oScreenshot->oScreenshotImage->height+4).');">'.$imgSRC.'</a>';
if ($_SESSION['current']->isLoggedIn())

View File

@@ -15,37 +15,37 @@ echo "<table width='100%' border=1 cellpadding=3 cellspacing=0>\n\n";
/* Display the number of users */
echo "<tr class=color4>\n";
echo " <td>Users:</td>\n";
echo " <td>".get_number_of_users()."</td>\n";
echo " <td>".User::count()."</td>\n";
echo "</tr>\n\n";
/* Display the active users in the last 30 days */
echo "<tr class=color4>\n";
echo " <td>Users active within the last 30 days:</td>\n";
echo " <td>".get_active_users_within_days(30)."</td>\n";
echo " <td>".User::active_users_within_days(30)."</td>\n";
echo "</tr>\n\n";
/* Display the active users in the last 60 days */
echo "<tr class=color4>\n";
echo " <td>Users active within the last 60 days:</td>\n";
echo " <td>".get_active_users_within_days(60)."</td>\n";
echo " <td>".User::active_users_within_days(60)."</td>\n";
echo "</tr>\n\n";
/* Display the active users in the last 90 days */
echo "<tr class=color4>\n";
echo " <td>Users active within the last 90 days:</td>\n";
echo " <td>".get_active_users_within_days(90)."</td>\n";
echo " <td>".User::active_users_within_days(90)."</td>\n";
echo "</tr>\n\n";
/* Display the inactive users */
echo "<tr class=color4>\n";
echo " <td>Inactive users (not logged in since six months):</td>\n";
echo " <td>".(get_number_of_users()-get_active_users_within_days(183))."</td>\n";
echo " <td>".(User::count()-User::active_users_within_days(183))."</td>\n";
echo "</tr>\n\n";
/* Display the users who were warned and pending deletion */
echo "<tr class=color4>\n";
echo " <td>Inactive users pending deletion:</td>\n";
echo " <td>".get_inactive_users_pending_deletion()."</td>\n";
echo " <td>".User::get_inactive_users_pending_deletion()."</td>\n";
echo "</tr>\n\n";
/* Display the number of comments */

View File

@@ -114,7 +114,7 @@ function notifyAdminsOfCleanupStart()
{
$sSubject = "Cleanup script starting\r\n";
$sMsg = "Appdb cleanup cron script started.\r\n";
$sEmail = get_notify_email_address_list(null, null); /* get list admins */
$sEmail = User::get_notify_email_address_list(null, null); /* get list admins */
if($sEmail)
mail_appdb($sEmail, $sSubject, $sMsg);
}
@@ -124,7 +124,7 @@ function notifyAdminsOfCleanupStart()
/* events of the appdb */
function notifyAdminsOfCleanupExecution($usersWarned, $usersUnwarnedWithData, $usersDeleted, $usersWithData)
{
$warnedUsers = get_inactive_users_pending_deletion();
$warnedUsers = User::get_inactive_users_pending_deletion();
$sSubject = "Cleanup script summary\r\n";
$sMsg = "Appdb cleanup cron script executed.\r\n";
@@ -135,7 +135,7 @@ function notifyAdminsOfCleanupExecution($usersWarned, $usersUnwarnedWithData, $u
$sMsg .= "Warned users pending deletion:".$warnedUsers."\r\n";
$sMsg .= "Users deleted:".$usersDeleted."\r\n";
$sMsg .= "Users pending deletion but have appdb data:".$usersWithData."\r\n";
$sEmail = get_notify_email_address_list(null, null); /* get list admins */
$sEmail = User::get_notify_email_address_list(null, null); /* get list admins */
if($sEmail)
mail_appdb($sEmail, $sSubject, $sMsg);
}
@@ -163,7 +163,7 @@ function orphanVersionCheck()
$sSubject = "Versions orphaned in the database\r\n";
$sEmail = get_notify_email_address_list(null, null); /* get list admins */
$sEmail = User::get_notify_email_address_list(null, null); /* get list admins */
if($sEmail)
mail_appdb($sEmail, $sSubject, $sMsg);
}

View File

@@ -415,7 +415,7 @@ class Application {
addmsg("Application rejected.", "green");
break;
}
$sEmail = get_notify_email_address_list($this->iAppId);
$sEmail = User::get_notify_email_address_list($this->iAppId);
if($sEmail)
mail_appdb($sEmail, $sSubject ,$sMsg);
}

View File

@@ -245,7 +245,7 @@ class Bug {
addmsg("Bug Link deleted.", "green");
}
$sEmail = get_notify_email_address_list(null, $this->iVersionId);
$sEmail = User::get_notify_email_address_list(null, $this->iVersionId);
if($sEmail)
{
mail_appdb($sEmail, $sSubject ,$sMsg);

View File

@@ -61,7 +61,7 @@ class Comment {
if($hResult)
{
$this->comment(mysql_insert_id());
$sEmail = get_notify_email_address_list($this->iAppId, $this->iVersionId);
$sEmail = User::get_notify_email_address_list($this->iAppId, $this->iVersionId);
$sEmail .= $this->oOwner->sEmail." ";
// fetches e-mails from parent comments, all parents are notified that a
@@ -161,7 +161,7 @@ class Comment {
/* fixup the child comments so the parentId points to a valid parent comment */
$hResult = query_parameters("UPDATE appComments set parentId = '?' WHERE parentId = '?'",
$this->iParentId, $this->iCommentId);
$sEmail = get_notify_email_address_list($this->iAppId, $this->iVersionId);
$sEmail = User::get_notify_email_address_list($this->iAppId, $this->iVersionId);
$sEmail .= $this->oOwner->sEmail;
if($sEmail)
{

View File

@@ -356,7 +356,7 @@ class distribution{
addmsg("Distribution rejected.", "green");
break;
}
$sEmail = get_notify_email_address_list(null, null);
$sEmail = User::get_notify_email_address_list(null, null);
if($sEmail)
mail_appdb($sEmail, $sSubject ,$sMsg);
}

View File

@@ -126,7 +126,7 @@ class Monitor {
}
break;
}
$sEmail = get_notify_email_address_list(null, $this->iVersionId);
$sEmail = User::get_notify_email_address_list(null, $this->iVersionId);
if($sEmail)
mail_appdb($sEmail, $sSubject ,$sMsg);
}

View File

@@ -153,7 +153,7 @@ class Note {
addmsg("Note deleted.", "green");
break;
}
$sEmail = get_notify_email_address_list(null, $this->iVersionId);
$sEmail = User::get_notify_email_address_list(null, $this->iVersionId);
if($sEmail)
mail_appdb($sEmail, $sSubject ,$sMsg);
}

View File

@@ -288,7 +288,7 @@ class Screenshot {
addmsg("Screenshot deleted.", "green");
}
$sEmail = get_notify_email_address_list(null, $this->iVersionId);
$sEmail = User::get_notify_email_address_list(null, $this->iVersionId);
if($sEmail)
mail_appdb($sEmail, $sSubject ,$sMsg);
}
@@ -404,7 +404,7 @@ function get_thumbnail($id)
$oScreenshot = new Screenshot($id);
// generate random tag for popup window
$randName = generate_passwd(5);
$randName = User::generate_passwd(5);
// set img tag
$imgSRC = '<img src="'.apidb_fullurl("appimage.php").
'?thumbnail=true&id='.$id.'" alt="'.$oScreenshot->sDescription.

View File

@@ -330,7 +330,7 @@ class testData{
addmsg("testing data rejected.", "green");
break;
}
$sEmail = get_notify_email_address_list(null, $this->iVersionId);
$sEmail = User::get_notify_email_address_list(null, $this->iVersionId);
if($sEmail)
mail_appdb($sEmail, $sSubject ,$sMsg);
}

View File

@@ -233,7 +233,7 @@ class Url {
addmsg("Url deleted.", "green");
}
$sEmail = get_notify_email_address_list(null, $this->iVersionId);
$sEmail = User::get_notify_email_address_list(null, $this->iVersionId);
if($sEmail)
mail_appdb($sEmail, $sSubject ,$sMsg);
}

View File

@@ -87,7 +87,7 @@ class User {
*/
function create($sEmail, $sPassword, $sRealname, $sWineRelease)
{
if(user_exists($sEmail))
if(User::exists($sEmail))
{
return USER_CREATE_EXISTS;
} else
@@ -120,7 +120,7 @@ class User {
if($this->sEmail && ($this->sEmail != $oUser->sEmail))
{
/* make sure this email isn't already in use */
if(user_exists($this->sEmail))
if(User::exists($this->sEmail))
{
addMsg("An account with this e-mail exists already.","red");
return USER_UPDATE_FAILED_EMAIL_EXISTS;
@@ -725,8 +725,181 @@ class User {
}
/**
* Creates a new random password.
*/
function generate_passwd($pass_len = 10)
{
$nps = "";
mt_srand ((double) microtime() * 1000000);
while (strlen($nps)<$pass_len)
{
$c = chr(mt_rand (0,255));
if (eregi("^[a-z0-9]$", $c)) $nps = $nps.$c;
}
return ($nps);
}
/**
* Check if a user exists.
* returns the userid if the user exists
*/
function exists($sEmail)
{
$hResult = query_parameters("SELECT userid FROM user_list WHERE email = '?'",
$sEmail);
if(!$hResult || mysql_num_rows($hResult) != 1)
{
return 0;
} else
{
$oRow = mysql_fetch_object($hResult);
return $oRow->userid;
}
}
/**
* Get the number of users in the database
*/
function count()
{
$hResult = query_parameters("SELECT count(*) as num_users FROM user_list;");
$oRow = mysql_fetch_object($hResult);
return $oRow->num_users;
}
/**
* Get the number of active users within $days of the current day
*/
function active_users_within_days($days)
{
$hResult = query_parameters("SELECT count(*) as num_users FROM user_list WHERE stamp >= DATE_SUB(CURDATE(), interval '?' day);",
$days);
$oRow = mysql_fetch_object($hResult);
return $oRow->num_users;
}
/**
* Get the count of users who have been warned for inactivity and are
* pending deletion after the X month grace period
*/
function get_inactive_users_pending_deletion()
{
/* retrieve the number of users that have been warned and are pending deletion */
$hResult = query_parameters("select count(*) as count from user_list where inactivity_warned = 'true'");
$oRow = mysql_fetch_object($hResult);
return $oRow->count;
}
/**
* Get the email address of people to notify for this appId and versionId.
*/
function get_notify_email_address_list($iAppId = null, $iVersionId = null)
{
$aUserId = array();
$c = 0;
$retval = "";
/*
* Retrieve version maintainers.
*/
/*
* If versionId was supplied we fetch supermaintainers of application and maintainer of version.
*/
if($iVersionId)
{
$hResult = query_parameters("SELECT appMaintainers.userId
FROM appMaintainers, appVersion
WHERE appVersion.appId = appMaintainers.appId
AND appVersion.versionId = '?'",
$iVersionId);
}
/*
* If versionId was not supplied we fetch supermaintainers of application and maintainer of all versions.
*/
elseif($iAppId)
{
$hResult = query_parameters("SELECT userId
FROM appMaintainers
WHERE appId = '?'",
$iAppId);
}
if($hResult)
{
if(mysql_num_rows($hResult) > 0)
{
while($oRow = mysql_fetch_object($hResult))
{
$aUserId[$c] = array($oRow->userId);
$c++;
}
}
}
/*
* Retrieve version Monitors.
*/
/*
* If versionId was supplied we fetch superMonitors of application and Monitors of version.
*/
if($iVersionId)
{
$hResult = query_parameters("SELECT appMonitors.userId
FROM appMonitors, appVersion
WHERE appVersion.appId = appMonitors.appId
AND appVersion.versionId = '?'",
$iVersionId);
}
/*
* If versionId was not supplied we fetch superMonitors of application and Monitors of all versions.
*/
elseif($iAppId)
{
$hResult = query_parameters("SELECT userId
FROM appMonitors
WHERE appId = '?'",
$iAppId);
}
if($hResult)
{
if(mysql_num_rows($hResult) > 0)
{
while($oRow = mysql_fetch_object($hResult))
{
$aUserId[$c] = array($oRow->userId);
$c++;
}
}
}
/*
* Retrieve administrators.
*/
$hResult = query_parameters("SELECT * FROM user_privs WHERE priv = 'admin'");
if(mysql_num_rows($hResult) > 0)
{
while($oRow = mysql_fetch_object($hResult))
{
$i = array_search($oRow->userid, $aUserId);
if ($aUserId[$i] != array($oRow->userid))
{
$aUserId[$c] = array($oRow->userid);
$c++;
}
}
}
if ($c > 0)
{
while(list($index, list($userIdValue)) = each($aUserId))
{
$oUser = new User($userIdValue);
if ($oUser->wantsEmail())
$retval .= $oUser->sEmail." ";
}
}
return $retval;
}
/************************/
@@ -1019,188 +1192,4 @@ class User {
}
}
/*
* User functions that are not part of the class
*/
/**
* Creates a new random password.
*/
function generate_passwd($pass_len = 10)
{
$nps = "";
mt_srand ((double) microtime() * 1000000);
while (strlen($nps)<$pass_len)
{
$c = chr(mt_rand (0,255));
if (eregi("^[a-z0-9]$", $c)) $nps = $nps.$c;
}
return ($nps);
}
/**
* Get the email address of people to notify for this appId and versionId.
*/
function get_notify_email_address_list($iAppId = null, $iVersionId = null)
{
$aUserId = array();
$c = 0;
$retval = "";
/*
* Retrieve version maintainers.
*/
/*
* If versionId was supplied we fetch supermaintainers of application and maintainer of version.
*/
if($iVersionId)
{
$hResult = query_parameters("SELECT appMaintainers.userId
FROM appMaintainers, appVersion
WHERE appVersion.appId = appMaintainers.appId
AND appVersion.versionId = '?'",
$iVersionId);
}
/*
* If versionId was not supplied we fetch supermaintainers of application and maintainer of all versions.
*/
elseif($iAppId)
{
$hResult = query_parameters("SELECT userId
FROM appMaintainers
WHERE appId = '?'",
$iAppId);
}
if($hResult)
{
if(mysql_num_rows($hResult) > 0)
{
while($oRow = mysql_fetch_object($hResult))
{
$aUserId[$c] = array($oRow->userId);
$c++;
}
}
}
/*
* Retrieve version Monitors.
*/
/*
* If versionId was supplied we fetch superMonitors of application and Monitors of version.
*/
if($iVersionId)
{
$hResult = query_parameters("SELECT appMonitors.userId
FROM appMonitors, appVersion
WHERE appVersion.appId = appMonitors.appId
AND appVersion.versionId = '?'",
$iVersionId);
}
/*
* If versionId was not supplied we fetch superMonitors of application and Monitors of all versions.
*/
elseif($iAppId)
{
$hResult = query_parameters("SELECT userId
FROM appMonitors
WHERE appId = '?'",
$iAppId);
}
if($hResult)
{
if(mysql_num_rows($hResult) > 0)
{
while($oRow = mysql_fetch_object($hResult))
{
$aUserId[$c] = array($oRow->userId);
$c++;
}
}
}
/*
* Retrieve administrators.
*/
$hResult = query_parameters("SELECT * FROM user_privs WHERE priv = 'admin'");
if(mysql_num_rows($hResult) > 0)
{
while($oRow = mysql_fetch_object($hResult))
{
$i = array_search($oRow->userid, $aUserId);
if ($aUserId[$i] != array($oRow->userid))
{
$aUserId[$c] = array($oRow->userid);
$c++;
}
}
}
if ($c > 0)
{
while(list($index, list($userIdValue)) = each($aUserId))
{
$oUser = new User($userIdValue);
if ($oUser->wantsEmail())
$retval .= $oUser->sEmail." ";
}
}
return $retval;
}
/**
* Get the number of users in the database
*/
function get_number_of_users()
{
$hResult = query_parameters("SELECT count(*) as num_users FROM user_list;");
$oRow = mysql_fetch_object($hResult);
return $oRow->num_users;
}
/**
* Get the number of active users within $days of the current day
*/
function get_active_users_within_days($days)
{
$hResult = query_parameters("SELECT count(*) as num_users FROM user_list WHERE stamp >= DATE_SUB(CURDATE(), interval '?' day);",
$days);
$oRow = mysql_fetch_object($hResult);
return $oRow->num_users;
}
/**
* Get the count of users who have been warned for inactivity and are
* pending deletion after the X month grace period
*/
function get_inactive_users_pending_deletion()
{
/* retrieve the number of users that have been warned and are pending deletion */
$hResult = query_parameters("select count(*) as count from user_list where inactivity_warned = 'true'");
$oRow = mysql_fetch_object($hResult);
return $oRow->count;
}
/**
* Check if a user exists.
* returns the userid if the user exists
*/
function user_exists($sEmail)
{
$hResult = query_parameters("SELECT userid FROM user_list WHERE email = '?'",
$sEmail);
if(!$hResult || mysql_num_rows($hResult) != 1)
{
return 0;
} else
{
$oRow = mysql_fetch_object($hResult);
return $oRow->userid;
}
}
?>

View File

@@ -649,8 +649,8 @@ function process_app_version_changes($isVersion)
}
if ($bAppChanged)
{
$sEmail = get_notify_email_address_list($_REQUEST['appId']);
$oApp = new Application($_REQUEST['appId']);
$sEmail = User::get_notify_email_address_list($_REQUEST['appId']);
$oApp = new Application($_REQUEST['appId']);
if($sEmail)
{
if($isVersion)

View File

@@ -514,7 +514,7 @@ class Version {
addmsg("Version rejected.", "green");
break;
}
$sEmail = get_notify_email_address_list(null, $this->iVersionId);
$sEmail = User::get_notify_email_address_list(null, $this->iVersionId);
if($sEmail)
mail_appdb($sEmail, $sSubject ,$sMsg);
}