diff --git a/html/inc/common_defs.inc b/html/inc/common_defs.inc
index 6bc085d6e5..4701df30ad 100644
--- a/html/inc/common_defs.inc
+++ b/html/inc/common_defs.inc
@@ -89,6 +89,7 @@ define('ERR_DB_NOT_UNIQUE', -137);
define('ERR_DB_CANT_CONNECT', -138);
define('ERR_PROJECT_DOWN', -183);
define('ERR_BAD_USER_NAME', -188);
+define('ERR_NO_OPTION', -191);
define('ERR_BAD_EMAIL_ADDR', -205);
define('ERR_BAD_PASSWD', -206);
define('ERR_ACCT_CREATION_DISABLED', -208);
diff --git a/html/inc/delete_account.inc b/html/inc/delete_account.inc
index 07e56028e4..beb6a30c92 100644
--- a/html/inc/delete_account.inc
+++ b/html/inc/delete_account.inc
@@ -29,59 +29,63 @@ require_once("../project/project.inc");
// Constants for different methods of deleting accounts
// These correspond to the value used in the config.xml
// field of
+//
define("DELETE_ACCOUNT_METHOD_OBFUSCATE", 1);
define("DELETE_ACCOUNT_METHOD_WIPE", 2);
define("DELETE_ACCOUNT_METHOD_PROJECT_DEFINED", 3);
-// Constant for how long to sleep after invalidating authenticator before proceeding with rest of delete
-// This is done on the chance that there is an active scheduler request in progress
+// Constant for how long to sleep after invalidating authenticator
+// before proceeding with rest of delete
+// This is done on the chance that there is an active scheduler request
+// in progress
+//
if (!defined("DELETE_DELAY")) define("DELETE_DELAY", 2);
-
-function check_delete_account_token($userid, $token) {
- if( !is_valid_token($userid, $token, TOKEN_TYPE_DELETE_ACCOUNT) ) {
+function is_delete_account_token_valid($userid, $token) {
+ if (!is_valid_token($userid, $token, TOKEN_TYPE_DELETE_ACCOUNT) ) {
sleep(LOGIN_FAIL_SLEEP_SEC);
return false;
}
return true;
}
-/*
-* This function saves the minimal information from the user and their hosts
-* so that db_dump can provide the information necessary to export the deleted_user
-* and deleted_host files. These records are deleted after 60 days by the
-* daily ops task "delete_expired_users_and_hosts.php"
-*/
+// Save the minimal information from the user and their hosts
+// so that db_dump can provide the information necessary
+// to export the deleted_user and deleted_host files.
+// These records are deleted after 60 days by the
+// daily ops task "delete_expired_users_and_hosts.php"
+//
function insert_deleted_records($user) {
BoincUserDeleted::insert_user($user);
BoincHostDeleted::insert_hosts_for_user($user);
}
-/*
-* This method selects which delete method to utilize. Projects can implement their own method
-* and make that a third mechanism if they have a need to
-*/
+// This method selects which delete method to utilize.
+// Projects can implement their own method
+// and make that a third mechanism if they have a need to
+//
function delete_account($user) {
$config = get_config();
$enable_delete_account = parse_config($config, "");
- if ( $enable_delete_account == DELETE_ACCOUNT_METHOD_OBFUSCATE ) {
+ if ($enable_delete_account == DELETE_ACCOUNT_METHOD_OBFUSCATE) {
return obfuscate_account($user);
- } else if ( $enable_delete_account == DELETE_ACCOUNT_METHOD_WIPE ) {
+ } else if ($enable_delete_account == DELETE_ACCOUNT_METHOD_WIPE) {
return wipe_account($user);
- } else if ( $enable_delete_account == DELETE_ACCOUNT_METHOD_PROJECT_DEFINED ) {
+ } else if ($enable_delete_account == DELETE_ACCOUNT_METHOD_PROJECT_DEFINED) {
return project_delete_account($user);
}
- return false;
+ return ERR_NO_OPTION;
}
-// This method invalidates the authenticator and then sleeps for
-// DELETE_DELAY seconds in order to let any active scheduler requests complete.
+// invalidate the authenticator and then sleep for DELETE_DELAY seconds
+// in order to let any active scheduler requests complete.
+//
function invalidate_authenticator($user) {
$x = "deleted_".time()."_".random_string();
$retval = $user->update("authenticator='$x'");
- if (!$retval) return false;
+ if (!$retval) return ERR_DB_NOT_FOUND;
sleep(DELETE_DELAY);
- return true;
+ return 0;
}
// "obfuscate" an account: leave user record (for DB consistency) but:
@@ -96,31 +100,30 @@ function invalidate_authenticator($user) {
//
function obfuscate_account($user) {
$retval = invalidate_authenticator($user);
- if (!$retval) return false;
+ if ($retval) return $retval;
insert_deleted_records($user);
$x = "deleted_".time()."_".random_string();
$retval = $user->update("email_addr='$x', authenticator='$x', name='deleted', country='', postal_code='', has_profile=0");
- if (!$retval) return false;
+ if (!$retval) return ERR_DB_NOT_FOUND;
user_quit_team($user);
forum_delete_user($user);
pm_delete_user($user);
anonymize_hosts($user);
delete_profile($user);
delete_friends($user);
- return true;
+ return 0;
}
// return true if the result is in progress
+//
function is_in_progress($res) {
- if ($res->server_state == RESULT_SERVER_STATE_IN_PROGRESS) {
- return true;
- }
- return false;
+ return ($res->server_state == RESULT_SERVER_STATE_IN_PROGRESS);
}
// returns true if the result finished successfully but is either
// pending validation or inconclusive
+//
function is_over_but_not_validated($res) {
if ($res->server_state == RESULT_SERVER_STATE_OVER && $res->outcome == RESULT_OUTCOME_SUCCESS &&
($res->validate_state == VALIDATE_STATE_INIT || $res->validate_state == VALIDATE_STATE_INCONCLUSIVE) ) {
@@ -138,11 +141,12 @@ function transition_workunit($res) {
// It will cancel all in progress or returned, but not yet validated
// results for a user. For other results, it will set the userid and
// hostid fields to 0
+//
function cancel_results_for_user($user) {
$ress = BoincResult::enum("userid = $user->id");
$cancel_clause="server_state=".RESULT_SERVER_STATE_OVER.", outcome=".RESULT_OUTCOME_CLIENT_DETACHED.", validate_state=".VALIDATE_STATE_INVALID;
$set_id_clause="hostid=0, userid=0";
- foreach($ress as $res) {
+ foreach ($ress as $res) {
if (is_in_progress($res) || is_over_but_not_validated($res)) {
$res->update($cancel_clause.", ".$set_id_clause);
transition_workunit($res);
@@ -153,23 +157,28 @@ function cancel_results_for_user($user) {
}
// This method deletes all rows from the database associated with the user
+//
function wipe_account($user) {
$retval = invalidate_authenticator($user);
- if (!$retval) return false;
+ if ($retval) return $retval;
//insert records into tables for db_dump to announce deletion of user
+ //
insert_deleted_records($user);
// delete remote submit user
+ //
delete_remote_submit_user($user); // from submit_util.inc
// remove user's team records
+ //
user_erase_team_owner($user); // from team.inc
user_quit_team($user); // from team.inc
user_erase_team_delta($user); // from team.inc
// Items that do not have logic elsewhere
// and do not have objects in boinc_db.inc
+ //
$db = BoincDb::get();
if (!$db) die("no DB connection");
$db->do_query("delete from credited_job where userid = $user->id");
@@ -181,8 +190,8 @@ function wipe_account($user) {
$db->do_query("delete from msg_to_host where hostid in (select id from host where userid = $user->id )");
$db->do_query("delete from sent_email where userid = $user->id");
-
//It is much faster to update results with single query
+ //
cancel_results_for_user($user);
BoincHostAppVersion::delete_for_user($user->id);
@@ -190,5 +199,5 @@ function wipe_account($user) {
// final action
delete_user($user); //from user_util.inc
- return true;
+ return 0;
}
diff --git a/html/ops/delete_user.php b/html/ops/delete_user.php
index 5c6ad6a3f7..71a6be1347 100755
--- a/html/ops/delete_user.php
+++ b/html/ops/delete_user.php
@@ -26,10 +26,6 @@ require_once("../inc/delete_account.inc");
require_once("../inc/boinc_db.inc");
die("Delete this line first\n");
-$config = get_config();
-if (!parse_bool($config, "enable_delete_account")) {
- die(tra("This feature is disabled. Please enable it in the config.xml."));
-}
$id = (int) $argv[1];
@@ -38,9 +34,9 @@ if (!$user) die("no such user\n");
$retval = delete_account($user);
if ($retval) {
- echo tra("User deleted");
+ echo "Failed to delete user: $retval\n";
} else {
- echo tra("Failed to delete user");
+ echo "User deleted\n";
}
?>
diff --git a/html/user/delete_account_confirm.php b/html/user/delete_account_confirm.php
index ba9dda83f3..04c28e7b71 100644
--- a/html/user/delete_account_confirm.php
+++ b/html/user/delete_account_confirm.php
@@ -31,11 +31,11 @@ if (!parse_bool($config, "enable_delete_account")) {
}
function delete_account_confirm_form() {
- //Make sure the token is still valid
+ // Make sure the token is still valid
+ //
$userid = get_int("id");
$token = get_str("token");
- $retval = check_delete_account_token($userid, $token);
- if (!$retval) {
+ if (!is_delete_account_token_valid($userid, $token)) {
error_page(
tra("The token you used has expired or is otherwise not valid. Please request a new one here")
);
@@ -59,22 +59,23 @@ function delete_account_confirm_form() {
}
function delete_account_confirm_action() {
- //Make sure the token is still valid
+ // Make sure the token is still valid
+ //
$userid = post_int("id");
$token = post_str("token");
- $retval = check_delete_account_token($userid, $token);
- if (!$retval) {
+ if (!is_delete_account_token_valid($userid, $token)) {
error_page(
tra("The token you used has expired or is otherwise not valid. Please request a new one here")
);
}
- //Verify password
+ // Verify password
+ //
$user = BoincUser::lookup_id($userid);
$passwd = post_str("passwd");
check_passwd_ui($user, $passwd);
- if (!delete_account($user)) {
+ if (delete_account($user)) {
error_page(
tra("Failed to delete your account. Please contact the project administrator.")
);
@@ -93,4 +94,4 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
delete_account_confirm_form();
}
-?>
\ No newline at end of file
+?>