我在 html 中创建了一个简单的“创建帐户”表单,该表单与一些 java 交互以实现双重选择加入方法。我还希望此表单在 Joomla 中创建用户并在单击创建帐户按钮后登录。
双重选择工作正常,但 joomla 2.5 的新用户脚本不起作用,没有错误,但它只是没有注册用户。我尝试将在 stackoverflow 上找到的 php 脚本(见下文)放置到生成新用户,但它不起作用。
是否可以在一个表单上同时运行这两种类型的脚本?如果是这样,我哪里错了?谢谢!
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
//Check for request forgeries, we comment this out since tokens are not generated in the html page
//JRequest::checkToken() or jexit( 'Invalid Token' );
//Get required system objects
$user = clone(JFactory::getUser());
$pathway = & $mainframe->getPathway();
$config = & JFactory::getConfig();
$authorize = & JFactory::getACL();
$document = & JFactory::getDocument();
//If user registration is not allowed, show 403 not authorized(Not needed)
$usersConfig = &JComponentHelper::getParams( 'com_users' );
if ($usersConfig->get('allowUserRegistration') == '0')
{
JError::raiseError( 403, JText::_( 'Access Forbidden' ));
return;
}
//Initialize new usertype setting
$newUsertype = $usersConfig->get( 'new_usertype' );
if (!$newUsertype)
{
$newUsertype = 'Registered';
}
//Bind the post array to the user object
if (!$user->bind( JRequest::get('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' ));
$date =& JFactory::getDate();
$user->set('registerDate', $date->toMySQL());
//If user activation is turned on, we need to set the activation information(Not needed)
$useractivation = $usersConfig->get( 'useractivation' );
if ($useractivation == '1')
{
jimport('joomla.user.helper');
$user->set('activation', md5( JUserHelper::genRandomPassword()) );
$user->set('block', '1');
}
//Save the details of the user
$user->save();