【问题标题】:Assigning gid to new user in joomla 1.5在 joomla 1.5 中为新用户分配 gid
【发布时间】:2012-03-15 23:46:49
【问题描述】:

我在注册用户下创建了几个新的子组,当我从后端创建新用户时,一切正常。当尝试在前端创建帐户时,系统会为他们提供父组(注册用户)的 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()->Quote($username).", user_full_name = ".JFactory::getDBO()->Quote($name)."其中 id = '".$this->record_id."'"); JFactory::getDBO()->query(); }

        }

    }

【问题讨论】:

    标签: php joomla1.5


    【解决方案1】:

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

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

    $user->set('gid', $authorize->get_group_id('', $newUsertype, 'ARO'));

    $user->set('gid', '你的gid#);

    【讨论】:

      猜你喜欢
      • 2011-08-12
      • 2011-01-04
      • 1970-01-01
      • 2010-11-08
      • 1970-01-01
      • 1970-01-01
      • 2012-10-16
      • 2013-12-22
      • 1970-01-01
      相关资源
      最近更新 更多