Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Avatar
jogissa #1
Member since Feb 2008 · 6 posts
Group memberships: Members
Show profile · Link to this post
Subject: Web Service for registering a new Account
Hi all,

First of all, sorry for write about a topic already is on the forum, but I have read other posts and I do not conclude anything :-S

I am doing a Web service just for register a new account into my ejabberd server. This service only has to register a new Account, there is no need to login after, and it returns a string message. My code is:

    [WebMethod(EnableSession = true)]   
    [System.Web.Script.Services.ScriptMethod(UseHttpGet = true)]
    public string Register(String user, String password)
    {
        user = user + "@localdomain";
        XmppClientConnection xmpp;
        xmpp = new XmppClientConnection();

        //xmpp.AutoPresence = true;
        //xmpp.AutoResolveConnectServer = true;
        xmpp.Port = 5222;
        xmpp.UseSSL = false;
        xmpp.OnReadXml += new XmlHandler(xmpp_OnReadXml);
        xmpp.OnWriteXml += new XmlHandler(xmpp_OnWriteXml);

        xmpp.Server = "localdomain";
       
        xmpp.RegisterAccount = true;
        agsXMPP.protocol.iq.register.Register reg = new agsXMPP.protocol.iq.register.Register(user, password);

        try
        {
            xmpp.Open();
        }
        catch (Exception ex)
        {
            return "Error Open " + ex.Message;
        }
        System.Threading.Thread.Sleep(1500);
        try
        {
            xmpp.Send(reg);
        }
        catch (Exception ex)
        {
            return "Error Send " + ex.Message;
        }
        System.Threading.Thread.Sleep(15000);
        xmpp.Close();
        return "Registered!" + textDebug;
    }

    private void xmpp_OnReadXml(object sender, string xml)
        {
            textDebug += "RECV XML: " + xml + System.Environment.NewLine;
        }

    private void xmpp_OnWriteXml(object sender, string xml)
        {
            textDebug += "SEND XML: " + xml + System.Environment.NewLine;
        }


Note that I give a lot of time System sleep, but the result is the same if it is 15000 than 1000. It is:

Registered!SEND XML: RECV XML: RECV XML: DIGEST-MD5PLAIN SEND XML: RECV XML: SEND XML: RECV XML: RECV XML: DIGEST-MD5PLAIN SEND XML: RECV XML: Choose a username and password to register with this server SEND XML: RECV XML: SEND XML: johan@localdomainjohanpass SEND XML:

But it does not really register nothing. Could someone tell me why?. I am using ejabberd 2.0 and it has register module activated.

Thanks in advance.
Avatar
Alex #2
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
  • Please post your complete Xml log.
  • you don't have to send the Register Element on your own when using xmpp.RegisterAccount = true;
  • Why are you registering accounts with agsXMPP when you can write the username and password directly to the ejabberd sql database?

Alex
Avatar
jogissa #3
Member since Feb 2008 · 6 posts
Group memberships: Members
Show profile · Link to this post
RESOLVED!! Many thanks Alex


Please post your complete Xml log.
Sorry!! I was using a bad control for viewing results. Here comes the correct log:

SEND XML: <stream:stream to='localdomain' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xml:lang='en'>
RECV XML: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" from="localdomain" version="1.0" xml:lang="en" id="3478271330" >
RECV XML: <stream:features xmlns:stream="http://etherx.jabber.org/streams"><starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls" /><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>DIGEST-MD5</mechanism><mechanism>PLAIN</mechanism></mechanisms><register xmlns="http://jabber.org/features/iq-register" /></stream:features>
SEND XML: <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls" />
RECV XML: <proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls" />
SEND XML: <stream:stream to='localdomain' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xml:lang='en'>
RECV XML: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" from="localdomain" version="1.0" xml:lang="en" id="4266837750" >
RECV XML: <stream:features xmlns:stream="http://etherx.jabber.org/streams"><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>DIGEST-MD5</mechanism><mechanism>PLAIN</mechanism></mechanisms><register xmlns="http://jabber.org/features/iq-register" /></stream:features>
SEND XML: <iq id="agsXMPP_1" type="get" to="localdomain"><query xmlns="jabber:iq:register" /></iq>
RECV XML: <iq xmlns="jabber:client" from="localdomain" type="result" id="agsXMPP_1"><query xmlns="jabber:iq:register"><instructions>Choose a username and password to register with this server</instructions><username /><password /></query></iq>
SEND XML: <iq type="set" id="agsXMPP_2" to="localdomain"><query xmlns="jabber:iq:register"><username /><password /></query></iq>
RECV XML: <iq xmlns="jabber:client" from="localdomain" type="error" id="agsXMPP_2"><query xmlns="jabber:iq:register"><username /><password /></query><error code="400" type="modify"><bad-request xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" /></error></iq>
SEND XML: </stream:stream>


Ok, as I see here, I am not passing user and password... but if I do not send the Register Element by my own (next quote), how do I do it?..... (after a few minutes thinking), ok, by xmpp.username and xmpp.password... :-D


you don't have to send the Register Element on your own when using xmpp.RegisterAccount = true;
Ok, thanks for the note!

Why are you registering accounts with agsXMPP when you can write the username and password directly to the ejabberd sql database?
It's true, but I want user can register by its own, not with my admin privileges (If I have understood your point)
This post was edited 2 times, last on 2008-04-22, 07:54 by jogissa.
Avatar
Alex #4
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by jogissa:
RESOLVED!! Many thanks Alex

You got it working?

Quote by jogissa:
Why are you registering accounts with agsXMPP when you can write the username and password directly to the ejabberd sql database?
It's true, but I want user can register by its own, not with my admin privileges (If I have understood your point)

The XMPP server has a database. I meant to connect to this database with admin or some other predefined privileges and add the new user directly which is normally only one record in one table.

Alex
Avatar
jogissa #5
Member since Feb 2008 · 6 posts
Group memberships: Members
Show profile · Link to this post
You got it working?

Yes, it works know. Thanks to your answers. The option of inserting a new row in table is also a good point, but I think I will use what I have.

About xmpp server database... if admin can insert a new contact, it is possible than he/she can read also that table and get all contacts, isn't he/she?. And another question, that table only has user and password fields? or also status? (I don't think so). If you could post an example of how can I access to that table it would be perfect.

Thanks.
Avatar
Jabberer #6
Member since Feb 2006 · 249 posts
Group memberships: Members
Show profile · Link to this post
Quote by jogissa:
About xmpp server database... if admin can insert a new contact, it is possible than he/she can read also that table and get all contacts, isn't he/she?. And another question, that table only has user and password fields? or also status? (I don't think so). If you could post an example of how can I access to that table it would be perfect.
This depends on the server software you are using.
You should check the documentation of your server or contact your server vendor.
Software Developer
AG-Software
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Forum: agsXMPP RSS