简体   繁体   中英

Assigning gid to new user in joomla 1.5

I've created several new child groups under registered users and when I create a new user from the backend, everything works fine. When trying to create an account on the frontend the system is giving them the gid of the parent group (registered users). I would like to know if you can pass the gid to joomla. Here's the script I'm using that's not working. Many thanks!

           // 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)." Where id = '".$this->record_id."'"); JFactory::getDBO()->query(); }

        }

    }

[SOLVED] Assigning gid to new user in joomla 1.5

I figured it out. If anyone else looking for an answer to this questions, just replace this line of code:

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

with

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM