Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to register a openfire or ejabberd with jaxl? #48

Open
suny0508 opened this issue Jun 11, 2014 · 0 comments
Open

how to register a openfire or ejabberd with jaxl? #48

suny0508 opened this issue Jun 11, 2014 · 0 comments

Comments

@suny0508
Copy link

hi:
i m a very new for xmpp and openfire on windows server.
I want to konw how to register a openfire or ejabberd with jaxl。
the examples are not work ,
anyone help me ,please .

my codes like this:

class xmpp {

public function register_user($username, $password) {
    require_once './jaxl/jaxl.php';

    $this->client = new JAXL(array(
        'jid' => 'reg',
        'host' => '127.0.0.1',
        'port' => '5222',
        'log_level' => JAXL_DEBUG
    ));
    $this->username = $username;
    $this->password = $password;

    $this->client->require_xep(array(
        '0077'  // InBand Registration  
    ));
    $thisClassObject = & $this;

    $this->client->add_cb('on_stream_features', function($stanza) use(&$thisClassObject) {
        $thisClassObject->client->xeps['0077']->get_form('localhost');
        return array($thisClassObject, 'wait_for_register_form');
    });

    $this->client->start();

    return;
}

public function wait_for_register_response($event, $args) {

    if ($event == 'end_stream') {
        return;
    } else if ($event == 'stanza_cb') {
        $stanza = $args[0];
        echo '<pre>';
        print_r($stanza);
        if ($stanza->name == 'iq') {
            if ($stanza->attrs['type'] == 'result') {
                echo "registration successful" . PHP_EOL . "shutting down..." . PHP_EOL;
                $client->send_end_stream();
                return 'logged_out';
            } else if ($stanza->attrs['type'] == 'error') {
                $error = $stanza->exists('error');
                echo "registration failed with error code: " . $error->attrs['code'] . " and type: " . $error->attrs['type'] . PHP_EOL;
                echo "error text: " . $error->exists('text')->text . PHP_EOL;
                echo "shutting down..." . PHP_EOL;
                $client->send_end_stream();
                return "logged_out";
            }
        }
    }
}

public function wait_for_register_form($event, $args) {

    $stanza = $args[0];
    $query = $stanza->exists('query', NS_INBAND_REGISTER);
    if ($query) {
        $form = array();
        $instructions = $query->exists('instructions');
        if ($instructions) {
            echo $instructions->text . PHP_EOL;
        }

        $this->client->xeps['0077']->set_form($stanza->attrs['from'], array('username' => $this->username, 'password' => $this->password));
        return array($this, "wait_for_register_response");
    } else {
        $client->send_end_stream();
        return "logged_out";
    }
}

}

$xmppObj = new xmpp();
var_dump($xmppObj->register_user('user', 'password') );

but it does not register success,and got a message:
registration failed with error code: 400 and type: modify

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants