Author Topic: Walkthrough: Allow registrations through nBill and keep email validation!  (Read 8980 times)

Offline paulm

  • Full Member
  • ***
  • Posts: 22
    • View Profile
In the absence of a more appropriate section, I thought I'd post this here.

Copy the following in to /administrator/language/en-GB/en-GB.ini & /language/en-GB/en-GB.ini.  You need both just in case you ever create a user from the admin panel.

Code:
Code: [Select]
USERNAME_REMINDER_EMAIL_TITLE=Your %s username
RESEND_ACTIVATION_EMAIL_TEXT=Hello,<br /><br />An activation link has been requested for your %s account.<br /><br />To activate to your account, click on the link below.<br /><br />%s<br /><br />Thank you.

Then, create a new file called a.php in /administrator/components/com_netinvoice/events/user_created/

Code:
Code: [Select]
<?php

// GET ALL THE FILES WE NEED
jimport('joomla.user.helper');
jimport('joomla.application.component.model');
jimport('joomla.mail.helper');

// CONNECT TO THE DATABASE AND BLOCK THE NEW USER
$db =& JFactory::getDBO();
$query "UPDATE #__users SET block = '1' WHERE id = '$params[id]';";
$db->setQuery($query);
$db->query();

// GENERATE A NEW ACTIVATION KEY & REMOVE THE LAST VISIT DATE
$activation JUtility::getHash(JUserHelper::genRandomPassword());
$query "UPDATE #__users SET activation = '$activation', lastvisitDate = '0000-00-00 00:00:00' WHERE id = '$params[id]';";
$db->setQuery($query);
$db->query();

// SEND THE USER AN EMAIL WITH THE ACTIVATION LINK
$config = &JFactory::getConfig();
$uri = &JFactory::getURI();
$url $uri->toString( array('scheme''host''port')).JRoute::_('index.php?option=com_user&view=login'false);
$from $config->getValue('mailfrom');
$fromname $config->getValue('fromname');
$subject JText::sprintf('USERNAME_REMINDER_EMAIL_TITLE'$config->getValue('sitename'));
$link $uri->toString( array('scheme''host''port')).JRoute::_('/index.php?option=com_user&task=activate&activation='.$activationfalse);
$link '<a href="'.$link.'">'.$link.'</a>';
$body JText::sprintf('RESEND_ACTIVATION_EMAIL_TEXT'$config->getValue('sitename'),$link);
if (!JUtility::sendMail($from$fromname$params[email], $subject$body1))
{
return false;
}
?>


As far as I'm aware, there's no validation required here (checking if account exists etc) as this file is only called when a user has been created.

This script blocks the user upon registration (via front or back end), removes the "last visit date" from the database (required by the "activate" function in /components/com_user/controller.php), generates a new activation token and sends another (it's NOT part of the welcome) email to the user.

If you disable Joomla registration, you will also need to edit the "activate" function in the /components/com_user/controller.php file.

Change
Code: [Select]
if ($allowUserRegistration == '0' || $userActivation == '0') {
JError::raiseError( 403, JText::_( 'Access Forbidden' ));
return;
}

to ...

Code: [Select]
/*
if ($allowUserRegistration == '0' || $userActivation == '0') {
JError::raiseError( 403, JText::_( 'Access Forbidden' ));
return;
}
*/

This will ignore the joomla config and attempt to process the request regardless of the state of the "Allow registration" variable.