Regarding Account Activation Notification email

1,171 views
Skip to first unread message

Mohamed Akram

unread,
Jul 15, 2012, 1:22:39 AM7/15/12
to joomla-de...@googlegroups.com
Hi, everyone,
     At present Joomla 2.5, when a user account is activated, if the admin notification are enabled, then an email should be fired to all the admin and which is working fine., But when I checked the query in the core , which select the users (for admin side notification) such as for admin approval etc..,  it just select all the users from #__Users table where sendemail = 1, bla bla, but for one of my project I override the method with the current query with INNER JOIN to user group table with the condition of where user type is admin , super admin or manager and sendemail is enabled, as my system has lots of registered level users with the email notification enabled for different purposes,

so without checking the condition whether he is a super users or admin, in the case its return all the users without irrespective of privilages who should get account approval emails, . What Iam coming to tell is, is this is correct as Iam not sure in the way it working currently. Please somebody let me know...

here is the query which i get from registration model from com_users component,   
[code]
// get all admin users
  95              $query = 'SELECT name, email, sendEmail, id' .
  96                          ' FROM #__users' .
  97                          ' WHERE sendEmail=1';
  98  
  99              $db->setQuery( $query );
 100              $rows = $db->loadObjectList();
 101  
 102              // Send mail to all users with users creating permissions and receiving system emails
 103              foreach( $rows as $row )
 104              {
 105                  $usercreator = JFactory::getUser($id = $row->id);
 106                  if ($usercreator->authorise('core.create', 'com_users'))
 107                  {
 108                      $return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $row->email, $emailSubject, $emailBody);
 109  
 110                      // Check for an error.
 111                      if ($return !== true) {
 112                          $this->setError(JText::_('COM_USERS_REGISTRATION_ACTIVATION_NOTIFY_SEND_MAIL_FAILED'));
 113                          return false;
 114                      }
 115                  }
 116              }

and Here is the query which I re-write form my project,
  95              $query = 'SELECT name, email, sendEmail, id' .
  96                          ' FROM #__users usr INNER JOIN #__usergroup urg ON usr.id = urg.userid' .
  97                          ' WHERE sendEmail=1 AND rest of condition to chek user types';





[\code]

Matt Thomas

unread,
Jul 15, 2012, 8:01:13 PM7/15/12
to joomla-de...@googlegroups.com
Hi,

Could you provide the complete code for what replaces line 95 -116 instead of "rest of condition to chek user types" and your reasoning for replacing it? That is, what issue did you solve by re-writing the query?

Also, you might find a fairly recent discussion at https://groups.google.com/d/topic/joomlabugsquad/3oHPSe248r0/discussion and tracker issues at http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=28646 interesting as they relate to the code in question.

Thanks for improving the code!

Best,

Matt Thomas
Founder betweenbrain
Phone: 203.632.9322
Twitter: @betweenbrain





--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To view this discussion on the web, visit https://groups.google.com/d/msg/joomla-dev-general/-/v6I0x8O1RycJ.
To post to this group, send an email to joomla-de...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-gene...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.

MOHAMED AKRAM

unread,
Jul 16, 2012, 1:38:00 AM7/16/12
to joomla-de...@googlegroups.com
Dear Matt Thomas,

As we know the Joomla 2.5 support three two king of new account activation, this can be configured in the com_users component perameters , when its set to self, the user can activate their account them self, and currently working fine, and no problem at all,

The problem arrise when its set to admin activation, first when a new user register to a site via the front end of a joomla 2.5 site, initially user has to validate thier email, during the validation , emails should be fired to all the admin or users who has privilage for core.edit.state on com_users component, this is normal follow, and code is show bellow which is copied from registration model

[code]
if (($userParams->get('useractivation') == 2) && !$user->getParam('activate', 0))
{
$uri = JURI::getInstance();

// Compile the admin notification mail values.
$data = $user->getProperties();
$data['activation'] = JApplication::getHash(JUserHelper::genRandomPassword());
$user->set('activation', $data['activation']);
$data['siteurl'] = JUri::base();
$base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
$data['activate'] = $base.JRoute::_('index.php?option=com_users&task=registration.activate&token='.$data['activation'], false);
$data['fromname'] = $config->get('fromname');
$data['mailfrom'] = $config->get('mailfrom');
$data['sitename'] = $config->get('sitename');
$user->setParam('activate', 1);
$emailSubject = JText::sprintf(
'COM_USERS_EMAIL_ACTIVATE_WITH_ADMIN_ACTIVATION_SUBJECT',
$data['name'],
$data['sitename']
);

$emailBody = JText::sprintf(
'COM_USERS_EMAIL_ACTIVATE_WITH_ADMIN_ACTIVATION_BODY',
$data['sitename'],
$data['name'],
$data['email'],
$data['username'],
$data['siteurl'].'index.php?option=com_users&task=registration.activate&token='.$data['activation']
);

// get all admin users

Here see the query which return the users to send approval notification , but query
condition is just check the who is enabled to receive system emails,

$query = 'SELECT name, email, sendEmail, id' .
' FROM #__users' .
' WHERE sendEmail=1';
$db->setQuery( $query );
$rows = $db->loadObjectList();

// Send mail to all superadministrators id

foreach( $rows as $row )
			{

$return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $row->email, $emailSubject, $emailBody);

				// Check for an error.
				if ($return !== true) {

$this->setError(JText::_('COM_USERS_REGISTRATION_ACTIVATION_NOTIFY_SEND_MAIL_FAILED'));
					return false;
}
}
}


 [/code]
Here see the query which return the users to send approval notification , but query 
condition is just check the who is enabled to receive system emails,

In the above code see line no 92,93  query this query is executed and email are fired , but according to my site there are normal registered level users who is enabled to recieve system email for a different purposes, my problem was , they also getting notifcations email,

how I rewrite query was,

// get all admin users
            $query = 'SELECT name, email, sendEmail' .
                        ' FROM #__users usr INNER JOIN #__user_usergroup_map usrgrp ON usr.id=usrgrp.user_id ' .
                        ' WHERE usrgrp.group_id=8 OR usrgrp.group_id=7 AND  sendEmail=1';

group id 8 (super user) , 7 (admin)....

and I restrict the approval emails only to admin or super admin who are allowed to recive system emails,  but this also not more sepcific, in the front end also we should check whether the user has core.edit.state permision on com_user component...,

In the back end this is not a probelm....


Regards,
 Mohamed Akram




Matt Thomas

unread,
Jul 17, 2012, 11:53:49 AM7/17/12
to joomla-de...@googlegroups.com
Hi Mohamed,

If I understand the problem correctly, this was resolved about a month ago. Please see https://github.com/joomla/joomla-cms/commit/48905fe31d32459abc52f9edbc3ad50f02613c3d. This change resolved the issue with all users set to receive system emails receiving new user activation emails.

Best,

Matt Thomas
Founder betweenbrain
Phone: 203.632.9322
Twitter: @betweenbrain




MOHAMED AKRAM

unread,
Jul 18, 2012, 7:12:26 AM7/18/12
to joomla-de...@googlegroups.com
Dear Matt,

 Its great that the problem has already fixed in joomla 2.5.6, I just checked it..., Thnx for ur helps..

Regards,
Mohamed Akram
Reply all
Reply to author
Forward
0 new messages