From 22a46874eed7d143012430fa1e8b7c30cabff9b5 Mon Sep 17 00:00:00 2001 From: james Date: Wed, 23 Feb 2011 17:50:06 +0000 Subject: [PATCH] Misc login/invite fixes --- user.inc.php | 17 ++++++++++++----- user_invite.php | 20 +++++++++++++++----- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/user.inc.php b/user.inc.php index 433bf669..cfa57137 100644 --- a/user.inc.php +++ b/user.inc.php @@ -1613,14 +1613,16 @@ function user_invite($username, $password, $email, $roles_id){ if($returnval == null){ // good so far, let's see if the account already exists - $q = mysql_query("SELECT id FROM accounts WHERE username = '" . mysql_real_escape_string($username) . "'"); + $q = mysql_query("SELECT id FROM accounts WHERE username='".mysql_real_escape_string($username)."' OR email='" . mysql_real_escape_string($username)."'"); $row = mysql_fetch_assoc($q); if(is_array($row)){ // This username is already in use. Let's see if this is a user that // the current one can modify $newUser = user_load(null, $row['id']); if(!is_array($newUser)){ - $returnval = 'Unable to load user'; + //this just means the user has no roles yet, that could be fine, if its a new user... + $newUser = user_create($row['id'], $conference['id']); + // $returnval = 'Unable to load user'; }else{ // check for role-specific limitations on who can edit who // we need to query the data manually, as the user_load function only @@ -1634,11 +1636,13 @@ function user_invite($username, $password, $email, $roles_id){ } } } - }else{ + } + else { // ok, this is a new user name, so we'll need to create everything $newAccount = account_create($username, $password); if(is_array($newAccount)){ - // if we're inviting someone, then their email address __MUST__ be their username, otherwise, how the *(@&#*(@#& can we send them the invite?! + // if we're inviting someone that doesnt already exist, then their email address __MUST__ + //be their username, otherwise, how the *(@&#*(@#& can we send them the invite?! account_set_email($newAccount['id'],$username); // created the account successfully, now do the user @@ -1660,7 +1664,10 @@ function user_invite($username, $password, $email, $roles_id){ if($returnval == null){ // if we've gotten this far, then either the user was created successfully, or they've // been loaded and our permission to modify them has been confirmed; we can add the role. - $result = user_add_role($newUser, $roletype); +// print_r($newUser); + + $result = account_add_role($newUser['accounts_id'], $roles_id, $conference['id']);//, $password); + if($result == 'ok'){ $returnval = user_load($newUser['id']); }else{ diff --git a/user_invite.php b/user_invite.php index 8adb98b0..8ed062d1 100644 --- a/user_invite.php +++ b/user_invite.php @@ -118,13 +118,13 @@ update_status(""); $("#button").attr('disabled',false); $("#button").val(''); - $("#action").val("invite"); + $("#action").val("invitenew"); break; case "norole": - update_status(""); + update_status("Choose the \"Invite existing account role\" button below add the selected role on this user\'s account and send them email notice of the change.')?>"); $("#button").attr('disabled',false); - $("#button").val(''); - $("#action").val("invite"); + $("#button").val(''); + $("#action").val("inviteexisting"); break; case "exist": update_status(""); @@ -161,7 +161,17 @@ } */ -if($_POST['action']=="invite" && $_POST['email'] && $type != '') { +if($_POST['action']=="invitenew" && $_POST['email'] && $type != '') { + $newUser=user_invite($_POST['email'], null, $_POST['email'], $type); + if(is_array($newUser)) { + echo happy(i18n("%1 successfully invited to be a %2",array($_POST['email'],$type))); + } + else { + echo error($newUser); + } + } + else if($_POST['action']=="inviteexisting" && $_POST['email'] && $type != '') { + $newUser=user_invite($_POST['email'], null, $_POST['email'], $type); if(is_array($newUser)) { echo happy(i18n("%1 successfully invited to be a %2",array($_POST['email'],$type)));