Hi,
I'm in a kind of 'damned if you do, damned if you don't' situation here.
I'm working on web site with two login levels:
- 'Client' users, who manages their individual content.
- 'Staff' users, who manages the clients including registering new ones.
My problem is that if a 'Staff'-class user logs in to his/her account and tries to register a new 'Client'-class user and the Joomla Registration plugin is enabled, the I get the 'You can not re-register while you are already signed in' error message.
On the other hand, if the plugin is disabled, then the new 'Client' user can't log in since his/her account won't be activated.
Is there anyway around this situation?
Grateful for any pointers🙂
I'm in a kind of 'damned if you do, damned if you don't' situation here.
I'm working on web site with two login levels:
- 'Client' users, who manages their individual content.
- 'Staff' users, who manages the clients including registering new ones.
My problem is that if a 'Staff'-class user logs in to his/her account and tries to register a new 'Client'-class user and the Joomla Registration plugin is enabled, the I get the 'You can not re-register while you are already signed in' error message.
On the other hand, if the plugin is disabled, then the new 'Client' user can't log in since his/her account won't be activated.
Is there anyway around this situation?
Grateful for any pointers🙂
Hi JavaJunkie,
I think that you need two different - but similar - forms:
One is for new users to self-register and has the Joomla! Registration plug-in enabled.
The second is for admins to add users, this can't have the plug-in enabled but needs to have user creation code added by hand.
Bob
PS There may be a third version for users to edit their entries.
I think that you need two different - but similar - forms:
One is for new users to self-register and has the Joomla! Registration plug-in enabled.
The second is for admins to add users, this can't have the plug-in enabled but needs to have user creation code added by hand.
Bob
PS There may be a third version for users to edit their entries.
Hmmm, not quite what I had in mind.
The new users 'Clients' won't be allowed to self-register. It seems that I need to mimic the behaviour of the registration process, but just adding a new post to the jos_user obviously isn't enough. So what else do I need to do?
The new users 'Clients' won't be allowed to self-register. It seems that I need to mimic the behaviour of the registration process, but just adding a new post to the jos_user obviously isn't enough. So what else do I need to do?
Hi JavaJunkie,
If you are OK with PHP here is the code you need. This is taken from a from to allow staff to manage users (some client info removed):
Bob
If you are OK with PHP here is the code you need. This is taken from a from to allow staff to manage users (some client info removed):
// Get required system objects
$user = clone(JFactory::getUser());
$pathway =& $mainframe->getPathway();
$config =& JFactory::getConfig();
$authorize =& JFactory::getACL();
$newUsertype = 'Registered';
$post = JRequest::get('post');
$post['email'] = JRequest::getString('email', '', 'post');
if ( $post['email'] ) {
$post['username'] = $post['email'];
} else {
$f_name = JRequest::getWord('first_name', '', 'post');
$l_name = JRequest::getWord('last_name', '', 'post');
$post['username'] = strtolower($l_name.$f_name.rand(10, 99));
}
$f_name = JRequest::getString('first_name', '', 'post');
$l_name = JRequest::getString('last_name', '', 'post');
$post['name'] = $f_name.' '.$l_name;
$post['email'] = JRequest::getString('email', '', 'post');
$post['password'] = JRequest::getString('service_no', '', 'post');
jimport('joomla.user.helper');
$post['password'] = JUserHelper::genRandomPassword();
$post['password2'] = $post['password'];
//$messages[] = '$post: '.print_r($post, true);
if ( !$user->bind( $post, 'usertype' ) ) {
JError::raiseError( 500, $user->getError());
}
// Set some initial user values
$user->set('id', 0);
$user->set('usertype', '');
$user->set('gid', $authorize->get_group_id( '', $newUsertype, 'ARO' ));
// TODO: Should this be JDate?
$user->set('registerDate', date('Y-m-d H:i:s'));
if ( !$user->save() ) {
$messages[] = JText::_( $user->getError());
$messages[] = ('Sorry, the user registration failed.');
$MyForm =& CFChronoForm::getInstance('add_user');
$MyForm->showForm('add_user', $post);
$MyForm->stoprunning = true;
} else {
JRequest::setVar('user_id', $user->id);
JRequest::setVar('published', 1);
$subject = "### Subject text ###";
$message = "Dear %s,\n\n### Intro text ###
To login to the website please visit www.example.com and enter the following details:\n\nUsername: %s\nPassword: %s\n\n";
$message = sprintf ( $message, $post['first_name'], $post['username'], $post['password2']);
$message = html_entity_decode($message, ENT_QUOTES);
// Send email to user
$fromname = "### From Name ###";
$mailfrom = "### From Email ###";
$email = $post['email'];
JUtility::sendMail($mailfrom, $fromname, $email, $subject, $message);
}Bob
Thank you.
I'll give a go..:)
I'll give a go..:)
Hi GreyHead,
sorry about the belated response.
I took your code sample, tweaked it a bit (since my clients aren't required to own an email address) and put it in the 'On Submit code - before sending email:' field (I assume that where it was supposed to go):
Unfortunately, I still get the same result as earlier...
sorry about the belated response.
I took your code sample, tweaked it a bit (since my clients aren't required to own an email address) and put it in the 'On Submit code - before sending email:' field (I assume that where it was supposed to go):
<?php
// Get required system objects
$user = clone(JFactory::getUser());
$pathway =& $mainframe->getPathway();
$config =& JFactory::getConfig();
$authorize =& JFactory::getACL();
$newUsertype = 'Registered';
$post = JRequest::get('post');
$post['name'] = JRequest::getString('name', '', 'post');
$post['username'] = JRequest::getString('username', '', 'post');
$post['password'] = JRequest::getString('password', '', 'post');
if ( !$user->bind( $post, 'usertype' ) ) {
JError::raiseError( 500, $user->getError());
}
// Set some initial user values
$user->set('id', 0);
$user->set('usertype', '');
$user->set('gid', $authorize->get_group_id( '', $newUsertype, 'ARO' ));
// TODO: Should this be JDate?
$user->set('registerDate', date('Y-m-d H:i:s'));
if ( !$user->save() ) {
$messages[] = JText::_( $user->getError());
$messages[] = ('Sorry, the user registration failed.');
$MyForm =& CFChronoForm::getInstance('registerClient');
$MyForm->showForm('registerClient', $post);
$MyForm->stoprunning = true;
} else {
JRequest::setVar('user_id', $user->id);
JRequest::setVar('published', 1);
}
?>Unfortunately, I still get the same result as earlier...
Hi JavaJunkie,
I'm not sure what "the same result as before" is . . .
Please check that 'Send Emails' is set to Yes on the form General tab for the code in the On Submit Before code to be run.
The email field is required for a Joomla! Registration - not sure how you can get round that.
Bob
I'm not sure what "the same result as before" is . . .
Please check that 'Send Emails' is set to Yes on the form General tab for the code in the On Submit Before code to be run.
The email field is required for a Joomla! Registration - not sure how you can get round that.
Bob
This topic is locked and no more replies can be posted.
