Joomla Registration plugin skip if existing user

Aramis_1970 14 Apr, 2010
I'm using the registration plugin to register new users in a demo license request form.
I'd like to skip registration plugin if users is already registered.
How can i do this?
Now if the user is already registered i got joomla error and no form processing obvioulsy.
Is it possible in the form to ask if already registered to login and then skip regitration plugin?
Or as simple as ingoring "already regstered user" and process the form?
thank you!
GreyHead 14 Apr, 2010
Hi Aramis_1970,

There's no way at present to turn a Plugin 'off' (I do have some code in test versions that does that.)

There are a couple of possible solutions.

a) If the user is logged in then you can detect that in the Form HTML and redirect them to a second copy of the form without the Registration plugin.

b) You can add a message at the top of the form asking them to login if they are already subscribed.

c) You can add a server-side validation that checks for an existing username and rejects the form with a message to login if it's already in use.

d) More complex but you could do (c) with an Ajax check in the form itself.

Bob
Aramis_1970 14 Apr, 2010
Hi Bob.
Thank you for your quick reply!
I think i will go with solution a)
Do you have a sample code to detect if the user is logged in and redirect?

thank you!!

cheers
GreyHead 14 Apr, 2010
Hi Aramis_1970,

If you search here on 'getuser' you should find several examples.

Bob
Aramis_1970 14 Apr, 2010
Thank oyu.
I have in my form code / form html at the beginning:

<?
$user = JFactory::getUser();
JRequest::setVar('user_id', $user->id);
print_r("User ID ".$user_id);
?>
just to check if works.
if i not logged in this code works returning correct empy id, if i logged in it returns:
You can not re-register while you are already signed in
Powered By ChronoForms - ChronoEngine.com

without processing my code?!
where i have to put this check for redirect?

cheers
nml375 14 Apr, 2010
Hi all,
I'm afraid this approach will not work, as the 'onLoad' plugin-event is processed before any other tasks. Instead, you'll have to leave the registration-plugin disabled, and use your "on submit"-code to either manually run the plugin, or manually register the user.

To manually run the plugin, you'd need some code along these lines (untested):
Remember to alter the plugin parameters according to your form.
<?
$pluginObject = new stdClass;
//Set up our parameters for the plugin.
$paramstring = 'name=name
username=username
email=useremail
pass=password
vpass=verifypassword
emailuser=Yes
emailadmins=Yes
joomlastatus=1
showmessages=1
overrideJallowUserRegistration=1
autologin=1
onsubmit=before_email
debugging=0';

//Now invoke the plugin...
$pluginObject->params = $paramString;
$MyPlugins->runPlugin('before_email', array('ONSUBMIT', 'ONLOADONSUBMIT'), 'cf_joomla_registration', $pluginObject);

//Any errors?
if ($MyForm->showFormErrors($MyForm->formrow->name)) {
  $MyForm->showForm($MyForm->formrow->name, $posted);
  return;
}
?>

Note, the above does not test whether the user is logged in or not, so you'll need to add that check. Also, you might have to define $MyForm and/or $MyPlugins, don't remember if they're defined in the "on Submit - before email" context.

If you'd rather do the registration yourself, there are quite a few examples on how to do this (and the occasional how not to do it). Feel free to ask if you need further assistance with either approach.

/Fredrik
GreyHead 15 Apr, 2010
Hi Aramis_1970,

Sorry, Fredrik is right. I had completely forgotten that there was that OnLoad check in the plugin and was only thinking about the OnSubmit process.

You could though hack the plugin code - the OnLoad function is right at the end.
function onload( $option, $row, $params, $html_string )
{
  global $mainframe;

  $user = JFactory::getUser();
  $db   =& JFactory::getDBO();
  if ( ($user->id) && ($mainframe->isSite()) ) {
    $html_string = 'You can not re-register while you are already signed in';
    $mainframe->redirect('some other url'); // add this line
  }
  // return $html_string ; // comment this line out
  return; // add this line
}
?>
Not tested and might not work

Bob
This topic is locked and no more replies can be posted.