From d2a785acfbcae2e493ba5c2b4d6cff27ec6d5fc8 Mon Sep 17 00:00:00 2001 From: james Date: Tue, 16 Feb 2010 17:58:14 +0000 Subject: [PATCH] if a user exists for the current fair year and is deleted when they try to register, simply undelete them --- user_new.php | 74 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 28 deletions(-) diff --git a/user_new.php b/user_new.php index 6a6c7d23..c5ccec21 100644 --- a/user_new.php +++ b/user_new.php @@ -115,42 +115,60 @@ } /* See if this email already exists */ - $q = mysql_query("SELECT id,types FROM users WHERE email='$sql_email' OR username='$sql_email'"); + $q = mysql_query("SELECT id,types,MAX(year) AS year,deleted FROM users WHERE (email='$sql_email' OR username='$sql_email' )"); + //select *, max(year) from users where username=sql_email + //if deleted and year = current yera - just undelete + //if deleted and year != current yera - proceed normally and recreate the user + if(mysql_num_rows($q) > 0) { /* It already exists, make sure they're not already in this role */ $r = mysql_fetch_object($q); $types = split(',', $r->types); - if(in_array($type, $types)) { - message_push(error(i18n("That email address has an existing {$user_what[$type]} registration"))); - message_push(notice(i18n("Use the 'recover password' option on the %1 {$user_what[$type]} login page %2 if you have forgotten your password", - array("", "")))); - break; /* Don't want to create an account */ - } else { - /* If they're already logged in, we can go ahead and - * add this role. We've passed all the required checks - * for creating a new user of this role. - * The user has already been warned about being logged - * out. */ - if(isset($_SESSION['users_id'])) { - /* user_create does last minute checks, like - * ensuring a student doesn't try to also - * register as a judge */ - $u = user_load($_SESSION['users_id']); - $u = user_create($type, $u['username'], $u); - $_SESSION['users_type'] = $type; - message_push(notice(i18n("Login to finish adding the new role to your account"))); - header("location: user_login.php?action=logout&redirect=roleattached"); - exit; - } - /* forward the user to the login page for whatever role - * they already have (it doesn't matter), and - * setup a login role_add redirect */ - message_push(notice(i18n("Your email address already exists. Please login to your existing account below and you will be redirected to the multi-role creation page to complete your registration request."))); - header("location: user_login.php?type={$types[0]}&redirect=roleadd&redirectdata=$type"); + if($r->year==$config['FAIRYEAR'] && $r->deleted=='yes') { + mysql_query("UPDATE users SET deleted='no' WHERE id='$r->id'"); + message_push(happy(i18n("Your account has been undeleted"))); + message_push(notice(i18n("Use the 'recover password' option on the %1 {$user_what[$type]} login page %2 if you have forgotten your password", + array("", "")))); + header("Location: user_login.php?type=$type"); exit; } + else if($r->deleted=='no') { + if(in_array($type, $types)) { + message_push(error(i18n("That email address has an existing {$user_what[$type]} registration"))); + message_push(notice(i18n("Use the 'recover password' option on the %1 {$user_what[$type]} login page %2 if you have forgotten your password", + array("", "")))); + break; /* Don't want to create an account */ + } else { + /* If they're already logged in, we can go ahead and + * add this role. We've passed all the required checks + * for creating a new user of this role. + * The user has already been warned about being logged + * out. */ + if(isset($_SESSION['users_id'])) { + /* user_create does last minute checks, like + * ensuring a student doesn't try to also + * register as a judge */ + $u = user_load($_SESSION['users_id']); + $u = user_create($type, $u['username'], $u); + $_SESSION['users_type'] = $type; + message_push(notice(i18n("Login to finish adding the new role to your account"))); + + header("location: user_login.php?action=logout&redirect=roleattached"); + exit; + } + /* forward the user to the login page for whatever role + * they already have (it doesn't matter), and + * setup a login role_add redirect */ + message_push(notice(i18n("Your email address already exists. Please login to your existing account below and you will be redirected to the multi-role creation page to complete your registration request."))); + header("location: user_login.php?type={$types[0]}&redirect=roleadd&redirectdata=$type"); + exit; + } + } + else { + //deletes = yes but year!=fairyear, so go ahead and let it create the new account + } } /* Strict validate the email */