在joomla 1.5中为新用户分配gid

时间:2012-03-15 23:46:49

标签: php joomla1.5

我在注册用户下创建了几个新的子组,当我从后端创建一个新用户时,一切正常。尝试在前端创建帐户时,系统会向他们提供父组(注册用户)的gid。我想知道你是否可以把gid传给joomla。这是我正在使用的脚本不起作用。非常感谢!

           // Begin create user
            global $mainframe;
            JFactory::getLanguage()->load('com_user');
            $this->execPieceByName('ff_InitLib');
    $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.
    $usersConfig = &JComponentHelper::getParams( 'com_users' );
    if ($usersConfig->get('allowUserRegistration') == '0') {
        echo '<script>alert("Access forbidden");history.go(-1);</script>';
        return;
    } else {

        // Initialize new usertype setting
        $newUsertype = $usersConfig->get( 'new_usertype' );
        if (!$newUsertype) {
            $newUsertype = 'Free User';
        }

        // Bind the post array to the user object
        $post = array(
            'name' => ff_getSubmit('ownerName'), 
            'username' => ff_getSubmit('ownerEmail'), 
            'email' => ff_getSubmit('ownerEmail'), 
            'password' => ff_getSubmit('password'), 
            'password2' => ff_getSubmit('password'), 
            'task' => 'register_save',
            'id' => '0',
            'gid' => ff_getSubmit('101'),
            );

        if (!$user->bind( $post, 'usertype' )) {
            echo '<script>alert("'.addslashes($user-      >getError()).'");history.go(-1);</script>';
            return;
        } else {

            // Set some initial user values
            $user->set('id', 0);
            $user->set('usertype', 'Free User');
            $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
            $useractivation = $usersConfig->get( 'useractivation' );
            if ($useractivation == '1')
            {
                jimport('joomla.user.helper');
                $user->set('activation', JUtility::getHash( JUserHelper::genRandomPassword()) );
                $user->set('block', '1');
            }

            // If there was an error with registration, set the message and display form
            if ( !$user->save() )
            {
                echo '<script>alert("'.addslashes(JText::_( $user->getError())).'");history.go(-1);</script>';
                return;
            } else {

                $db     =& JFactory::getDBO();

                $name       = $user->get('name');
                $email      = $user->get('email');
                $username   = $user->get('username');

                JFactory::getDBO()->setQuery("Update #__facileforms_records Set user_id = '".$user->get('id')."', 

username =“.JFactory :: getDBO() - &gt; Quote($ username)。”,user_full_name =“.JFactory :: getDBO() - &gt; Quote($ name)。”其中id ='“。$ this-&gt; record_id。”'“);                     JFactory :: getDBO() - &GT;查询();                 }

        }

    }

1 个答案:

答案 0 :(得分:0)

[已解决]在joomla 1.5中为新用户分配gid

我明白了。如果其他人正在寻找这个问题的答案,只需替换这行代码:

$ user-&gt; set(&#39; gid&#39;,$ authorize-&gt; get_group_id(&#39;&#39;,$ newUsertype,&#39; ARO&#39;)); < / p>

$ user-&gt; set(&#39; gid&#39;,&#39;你的gid#);