nBill Community nBill Home Page
21/May/2012, 10:30:14 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Click Here for the nBill home page, or take a tour.  
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Walkthrough: Allow registrations through nBill and keep email validation!  (Read 7186 times)
paulm
Jr. Member
**
Offline Offline

Posts: 22


View Profile
« on: 27/October/2009, 02:31:20 PM »

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:
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:
<?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:
if ($allowUserRegistration == '0' || $userActivation == '0') {
JError::raiseError( 403, JText::_( 'Access Forbidden' ));
return;
}

to ...

Code:
/*
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.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!