Project

General

Profile

How to register account by jaxmpp3

shir Hu
Added almost 4 years ago

Hello, everyone,

When I switch jaxmpp3 to register account, I found that the function changed in jaxmpp2 . for example, the function addListener(...) missed, RegistrationEven.java also missed .

Then I remove those missed ,and occur

 tigase.jaxmpp.core.client.exceptions.JaxmppException: Not connected!

I have no idea about register with jaxmpp3, Can you give me some example code?


Replies (1)

Added by Wojciech Kapcia TigaseTeam almost 4 years ago

First of all you need to register appropriate module:

jaxmpp.getModulesManager().register(new InBandRegistrationModule());

Then enable InBandRegistrationMode:

jaxmpp.getSessionObject().setProperty(InBandRegistrationModule.IN_BAND_REGISTRATION_MODE_KEY, Boolean.TRUE);

And then use new EventBus to handle registration form:

        jaxmpp.getEventBus().addHandler(
                InBandRegistrationModule.ReceivedRequestedFieldsHandler.ReceivedRequestedFieldsEvent.class,
                new InBandRegistrationModule.ReceivedRequestedFieldsHandler() {

                    @Override
                    public void onReceivedRequestedFields(SessionObject sessionObject, IQ responseStanza) {

                        try {
                            jaxmpp.getModule(InBandRegistrationModule.class).register(username, password, email,
                                    new AsyncCallback() {

                                @Override
                                public void onError(Stanza responseStanza, ErrorCondition error) throws JaxmppException {
                                    System.out.println("Account registration error: " + error);
                                }

                                @Override
                                public void onSuccess(Stanza responseStanza) throws JaxmppException {
                                    System.out.println("registrationSuccess");
                                }

                                @Override
                                public void onTimeout() throws JaxmppException {
                                    System.out.println("Account registration failed.");
                                }
                            });
                        } catch (JaxmppException e) {
                            System.out.println(e);
                        }

                    }

                });

Finally connect:

jaxmpp.login(false);

    (1-1/1)