0
votes

I wanted to send "nick" field from client to register new username with ejabberd in band registration. but Server is sending only username, password and instructions fields back to client to fill. I have checked below mod_register to modify these fields but none provide is available.

https://docs.ejabberd.im/admin/configuration/#mod-register

2018-05-29 23:01:08.426 [debug] <0.4613.3>@xmpp_socket:send:218 (tls|<0.4613.3>) Send XML on stream = <<"
<iq xml:lang='en' from='xmpp.test.in' type='result' id='mCbQBXKp-Sd4'>
    <query xmlns='jabber:iq:register'>
        <username/>
        <password/>
        <instructions>Choose a username and password to register with this server</instructions>
    </query>
</iq>">>

Can any help me how to get nick included in registration itself?

1

1 Answers

0
votes

If you are using Smack client for Android you can send additional attributes in createAccount method like:

public void signup(String user, String password, String nickname) throws SmackInvocationException {
    connect();

    Map<String, String> attributes = new HashMap<String, String>();
    attributes.put("name", nickname);
    try {
        AccountManager.getInstance(con).createAccount(user, password, attributes);
    } catch (Exception e) {
        throw new SmackInvocationException(e);
    }
}

Another approach is to use Vcard with VcardManager and set nickname in smack like (after login or signup):

    private Context context;
    private XMPPConnection con;

    public SmackVCardHelper(Context context, XMPPConnection con) {
        this.context = context;
        this.con = con;
    }

    public void save(String nickname) throws SmackInvocationException {
        VCard vCard = VCardManager.getInstanceFor(connection).loadVCard();

        try {
            vCard.setNickName(nickname);
            vCard.saveVCard(vcard);
        } catch (Exception e) {
            throw new SmackInvocationException(e);
        }
    }