How can I create a new Joomla user account from within a script?

后端 未结 12 794
感动是毒
感动是毒 2020-12-01 03:41

We\'re creating an XML API for Joomla that allows partner sites to create new accounts for their users on our website.

We\'ve created a standalone PHP script that

12条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 04:44

    Update: oh I ddin't see you wanted 1.5 but you could do similar but wth the 1.5 API instead.

    This is part of something I was usng for anther purpose but you would need to use the default group instead until an issue with using JUserHelper from the command line is fixed or make it a web application.

    input->get('username', null,'STRING');
            $name = $this->input->get('name');
            $email = $this->input->get('email', '', 'EMAIL');
            $groups = $this->input->get('groups', null, 'STRING');
    
            // Short args
            if (!$username)
            {
                $username = $this->input->get('u', null, 'STRING');
            }
            if (!$name)
            {
                $name = $this->input->get('n');
            }
            if (!$email)
            {
                $email = $this->input->get('e', null, 'EMAIL');
            }
            if (!$groups)
            {
                $groups = $this->input->get('g', null, 'STRING');
            }
    
            $user = new JUser();
    
            $array = array();
            $array['username'] = $username;
            $array['name'] = $name;
            $array['email'] = $email;
    
            $user->bind($array);
            $user->save();
    
            $grouparray = explode(',', $groups);
            JUserHelper::setUserGroups($user->id, $grouparray);
            foreach ($grouparray as $groupId)
            {
                JUserHelper::addUserToGroup($user->id, $groupId);
            }
    
            $this->out('User Created');
    
            $this->out();
        }
    
    }
    
    if (!defined('JSHELL'))
    {
        JApplicationCli::getInstance('Adduser')->execute();
    }
    

提交回复
热议问题