I've poked around to see if anyone else had this problem and couldn't find much. I found people with similar problems - but not the same. Anyway here is the description of the problem and the fix I implemented:
I'm using the registration plug in. I have a scholarship application where on the first screen the user enters an email and a password (both twice to make sure they get it right). I'm using the email as the username. They then proceed with the application. Once they submit, the form is submitted perfectly and their registration is created. However if they then go and apply for another scholarship (there are two types) and the same thing is done the first screen validation fails because a user already exists with that username. The failure messsage was vague as well.
So I hacked the registration plug in code to ignore the registration process if the user is already registered. The details:
- modify regValidateEmail to not check for duplicates. Instead if the email is not blank and passes the other email validation in that function just return true.
- modify refValidateUsername the same way.
- I added a proc that given a username returns if that user is already registered:
function regUsernameExists($username)
{
// added by R.J. Edgar
$db =& JFactory::getDBO();
$db->setQuery("SELECT id FROM #__users WHERE `username` LIKE '".$db->getEscaped($username)."'");
return $db->loadResult() ? true : false;
}
added code to beginning of register16 function that returns if that user already exists. I put it after the lant->load statement, but I think it could have gone first:
if (plgSystemRSFPRegistration::regUsernameExists($vars['username'])) {
// user already registered.
return true;
}
Its not a perfect fix. If you are not using the email as the username you may want to add code that checks for the email already being in use. I'm not sure what you would do though if the username didn't exist but the email address did?
So far my testing shows this to do what I want.
I started down the path of if the user was registered of having the code update the password - then realized that would be a big security hole.
Is there an easier solution? I guess one solution would be to separate the user registration from the form process, but doesn't that defeat the whole idea for the registration plugin? Somehow I get the feeling that I'm missing something because this seems like it would be a common problem?