registering and unregistering a user

253 views
Skip to first unread message

ceallach

unread,
Dec 10, 2010, 11:06:58 AM12/10/10
to jabber-net
I'm currently in the process of registering and unregister/remove
users programmatically from my openfire XMPP server using jabber-net.
Users get created of deleted from a superuser "admin" account.

For registering a list users synchronously i have the following code:
=================================================
public void RegisterUsers(List<User> users)
{
if (client.IsAuthenticated)
{
IQ regForm = RequestRegistrationForm();

foreach (User user in users)
{
// populate form with user information
IQ form = PopulateRegistrationForm(regForm, user);
form.To = Server;
form.Type = IQType.set;
form.ID = Element.NextID();
form.From = user.Username + "@" + Server + "/" +
Resource;

// send a synchronous IQ call
// TODO: keeps throwing timeout error waiting for
IQ response. try to fix it
IQ response = client.Tracker.IQ(form,
(int)client.KeepAlive);
}
}
=================================================

The accounts get created and everything is fine. Sometimes I do get a
timeout error waiting for IQ response. Any idea why this might
happen?, Since the user accounts still get created when this error is
thrown

for removing the users i have to following code:
=================================================
public void UnRegisterUsers(List<User> users)
{
if (client.IsAuthenticated)
{
RegisterIQ iq = new RegisterIQ(client.Document);
iq.To = Server;
iq.Type = IQType.set;

Register r = iq.Query as Register;
r.Remove = true;

foreach (User user in users)
{
iq.ID = Element.NextID();
iq.From = user.Username + "@" + Server + "/" +
Resource;

client.Tracker.IQ(iq, (int)client.KeepAlive);
}
}
}
=================================================

The stanza for cancelling the accounts of the user follows the
protocol from:
http://xmpp.org/extensions/xep-0077.html#usecases-cancel

and produces the following stanza:

<iq id="JN_7" type="set" to="localxmpp" from="useraccount@localxmpp/
resource"><query xmlns="jabber:iq:register"><remove /></query></iq>

which, as far is I can see, is correct.

The problem I'm encountering is that instead of the "useraccount"
getting removed, my "admin" account get's deleted. And I receive the
following response.

<iq type="result" id="JN_7" from="localxmpp"
to="conclusionadmin@localxmpp/conclusion"/>

Thank you,

Michael Wegman

unread,
Dec 13, 2010, 12:34:24 PM12/13/10
to jabbe...@googlegroups.com
XEP 77 is used to register and unregister oneself, not another user.
This is why the unregister doesn't do what you want it to do. When the
XMPP server gets the IQ packet, it will replace the 'from' attribute
with the current user account (your admin account) and remove that
user.

Michael Wegman

> --
> You received this message because you are subscribed to the Google Groups "jabber-net" group.
> To post to this group, send email to jabbe...@googlegroups.com.
> To unsubscribe from this group, send email to jabber-net+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/jabber-net?hl=en.
>
>

Joe Hildebrand

unread,
Dec 14, 2010, 3:29:04 AM12/14/10
to jabbe...@googlegroups.com
Michael is right. If you want to delete accounts for other users, have
admin privileges, and your server supports it, you might try XEP-133,
section 4.2 (http://goo.gl/PabPj).

Alternately, if you have that user's password, you can log in as them ,
then send the remove as you are now.

Reply all
Reply to author
Forward
0 new messages