I'm not sure if this is intended, but my assumption was that provisioning would take care of creating the account.

Comments

fizk’s picture

You could use this code. I wrote it for creating random chat bots.

xmppframework/contrib/xmpp_api/vendor/XMPPHP/XMPP.php

       /**
        * Register a new random user.
        *
        * @param $entity
        *       Entity we want information about
        */
        public function registerRandomUser() {
                $id = 'reg_' . $this->getID();
                $xml = "<iq type='set' id='$id'>
                            <query xmlns='jabber:iq:register'>
                                <username>" . 'chatbot_' . $this->genRandomString(10) . "</username>
                                <password>" . $this->genRandomString(15) . "</password>
                                <email></email>
                                <name></name>
                            </query>
                        </iq>";

                $this->addIdHandler($id, 'register_random_user_handler');
                $this->send($xml);
        }

        /**
        * Handler for random user registration
        *
        * @param XML Object $xml
        */
        protected function register_random_user_handler($xml) {
                switch ($xml->attrs['type']) {
                        case 'error':
                                $this->event('random_user_registered', 'error');
                                break;
                        case 'result':
                                $query = $xml->sub('query');
                                foreach ($query->subs as $key => $value) {
                                    switch ($value->name) {
                                        case 'username':
                                            $username = $value->data;
                                            break;

                                        case 'password':
                                            $password = $value->data;
                                            break;
                                    }
                                }

                                $this->event('random_user_registered', array('jid' => $username . '@example.com', 'password' => $password));
                                break;
                        default:
                                $this->event('random_user_registered', 'default');
                }
        }

xmppframework/contrib/xmpp_api/xmpp_api.internal.inc

function xmpp_api_create_account($uid, $jid, $conn = NULL) {
  if ($conn = _xmpp_api_server_connection($conn)) {

      $conn->registerRandomUser();
      $payload = $conn->processUntil('random_user_registered', XMPP_API_PROCESS_TIMEOUT);
      $credentials = $payload[0][1];

      if (!is_array($credentials)) {
          watchdog('xmpp_api', 'Could not create chatbot for node: %node, jid: %jid ', array('%node' => $nid, '%jid' => $jid), WATCHDOG_ERROR);
          watchdog('xmpp_api', print_r($payload,true)); 
          return FALSE;
      }

    // store $credentials['jid'] and $credentials['password']

    return $credentials;
  } else { 
      return FALSE;
  }
}

darren.ferguson’s picture

Yeah i did not make it try and create the account since we utilized ldap and hence the account was created via ldap automaitcally.

This is something i can probably address in the framework at some point.

fizk’s picture

I've written code to do this with xmpp_api. Will send here soon.

aaron’s picture

very interested in this; not using ldap.

IckZ’s picture

Hi, is this feature temporaly integrated? I dont want wo run xmpp with ldap and really miss this feature. Anybody tested the code above?

fizk’s picture

Please see #756972: Various fixes and improvements to XMPPFramework for a big bug fix patch + slight improvements.

fizk’s picture

Status: Active » Closed (duplicate)