Full-stack developer Emerson Rocha .::. CMS Joomla!, PHP, JavaScript/NodeJS, Infraestrutura

Código da Função

<?php
function CreateNewUser($name, $username, $email, $password, $registerDate = NULL, $usertype = 'Registered', $block = '0', $sendEmail = '1', $gid = '18') {
        global $db;

        $db = & JFactory::getDBO();
        jimport('joomla.user.helper');

        //Make the joomla password hash
        $salt = JUserHelper::genRandomPassword(32);
        $crypt = JUserHelper::getCryptedPassword($password, $salt);
        $joomlapassword = $crypt . ':' . $salt;

        //Table #__users
        //Informations about the user
        $user = new stdClass;
        $user->id = NULL;
        $user->name = $name;
        $user->username = $username;
        $user->email = $email;
        $user->password = $joomlapassword;
        $user->registerDate = registerDate;
        $user->usertype = $usertype;
        $user->block = $block;
        $user->sendEmail = $sendEmail;
        $user->gid = $gid;

        if (!$db->insertObject('#__users', $user, 'id')) {
            echo $db->stderr();
            return false;
        }


        //Table #__core_acl_aro
        //Discover what is the last value of value in #__core_acl_aro
        $query = "SELECT value FROM #__core_acl_aro ORDER BY id DESC LIMIT 1";
        $db->setQuery($query);
        $coreaclarolastvalue = $db->loadResult();

        $coreaclaro = new stdClass;
        $coreaclaro->id = NULL;
        $coreaclaro->section_value = 'users';
        $coreaclaro->value = $coreaclarolastvalue + 1;
        $coreaclaro->order_value = NULL;
        $coreaclaro->name = $name;
        $coreaclaro->hidden = NULL;

        if (!$db->insertObject('#__core_acl_aro', $coreaclaro, 'id')) {
            echo $db->stderr();
            return false;
        }

        //Table #__core_acl_groups_aro_map
        $coreaclmap = new stdClass;
        $coreaclmap->group_id = $gid;
        $coreaclmap->section_value = NULL;
        $coreaclmap->aro_id = $coreaclaro->id; // maybe just $user->id ?

        if (!$db->insertObject('#__core_acl_groups_aro_map', $coreaclmap)) {
            echo $db->stderr();
            return false;
        }

        $CreateNewUserInfo = array($user->id, $user->name, $user->username, $user->email);
        return $CreateNewUserInfo;
}

Exemplo de implementação 1


//This exemple will take data from one post, for example
$username = JRequest::getVar('username');
$name = JRequest::getvar('name');
$email = JRequest::getVar('email');
$password = JRequest::getVar('password');

//This code will call your funcion, then register with your data
$NewUserInfo = CreateNewUser($name, $username, $email, $password, $registerDate);


fititnt.org is not affiliated with or endorsed by the Joomla Project or Open Source Matters. The Joomla logo is used under a limited license granted by Open Source Matters the trademark holder in the United States and other countries
HTML5 Valid

Console de depuração do Joomla!

Sessão

Informação do perfil

Memória Utilizada

Consultas ao banco