Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > BOOK: Professional XMPP Programming with JavaScript and jQuery
|
BOOK: Professional XMPP Programming with JavaScript and jQuery
This is the forum to discuss the Wrox book Professional XMPP Programming with JavaScript and jQuery by Jack Moffitt; ISBN: 978-0-470-54071-8
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional XMPP Programming with JavaScript and jQuery section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 3rd, 2014, 12:31 PM
Authorized User
 
Join Date: May 2013
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default In-band registration: How do I connect to the network to register new users?

Hello once again coders, anyone familiar with in-band registration? I just found out about it and decided it was the best way to hook up my app users with jabber ids, without having them go through the headache of obtaining one themselves. Since I'm new to it, this may sound as a silly question. In order to send stanzas to an XMPP server, you need to be connected through an XMPP account right? So I login with my jid to Jack's beautifully created peek console and send the following stanza to the server
Code:
$iq({type: "get", id: "reg1"}).c("query", {xmlns:"jabber:iq:register"})
which is supposed to get the register fields. The server sends back the following stanza

Code:
<iq id='reg1'
    type='result'
    to='my_jid@miqote.com/my_resource'>
<query xmlns='jabber:iq:register'>
<registered/>
<username>
my_jid
</username>
<password/>
</query>
</iq>
Note that I replaced my real jid with "my_jid"
So the puzzle is, how in the world am I supposed to register a new user if the server recognizes that my stanza is coming from an already registered user? Or is it possible to somehow send stanzas to the server without loging in with an already existing username?
 
Old April 3rd, 2014, 12:39 PM
Wrox Author
 
Join Date: Jan 2010
Posts: 178
Thanks: 0
Thanked 16 Times in 15 Posts
Default

This is not possible without the use of plugins. See the plugins at https://github.com/strophe/strophejs-plugins

The issue is that normally Strophe establishes an authenticated or anonymous session, and the legacy registration protocol must be done before a session is established.
 
Old April 3rd, 2014, 10:18 PM
Authorized User
 
Join Date: May 2013
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'll take a look at that Jack. Thanks for the lead.
 
Old April 4th, 2014, 01:21 AM
Authorized User
 
Join Date: May 2013
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by metajack View Post
This is not possible without the use of plugins. See the plugins at https://github.com/strophe/strophejs-plugins

The issue is that normally Strophe establishes an authenticated or anonymous session, and the legacy registration protocol must be done before a session is established.


I uploaded strophe.register.js from github to my server. Then I ran the register plugin. My final code looks like this(I'm including the html for clarity)


Quote:









<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">



<head>



<script type = "text/javascript" src="http://code.jquery.com/jquery-latest.js"> </script>


<!--include JQM -->

<meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1">

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0-rc.1/jquery.mobile-1.3.0-rc.1.min.css" />

<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>

<script src="http://code.jquery.com/mobile/1.3.0-rc.1/jquery.mobile-1.3.0-rc.1.min.js"></script>




<!--include strophe and associated libraries/plugins-->

<script src='path/strophe.js'></script>
<script src='path/strophe.register.js'></script>
<script src='path/scripts/flXHR.js'></script>



<script>

$(document).ready(function(){


$("#register_button").click(function(){



var user = $("#user").val();

var pass = $("#pass").val();



var callback = function (status) {

if (status === Strophe.Status.REGISTER) {

// fill out the fields

connection.register.fields.username = user;

connection.register.fields.password = pass;

// calling submit will continue the registration process

connection.register.submit();

} else if (status === Strophe.Status.REGISTERED) {

console.log("registered!");

// calling login will authenticate the registered JID.

//connection.authenticate();

} else if (status === Strophe.Status.CONFLICT) {

console.log("Contact already existed!");

} else if (status === Strophe.Status.NOTACCEPTABLE) {

console.log("Registration form not properly filled out.")

} else if (status === Strophe.Status.REGIFAIL) {

console.log("The Server does not support In-Band Registration")

} else if (status === Strophe.Status.CONNECTED) {

// do something after successful authentication

} else {

// Do other stuff

}

};




var connection = new Strophe.Connection("http://bosh.metajack.im:5280/xmpp-httpbind");

connection.register.connect("miqote.com", callback, wait, hold);


});//End click

});//End document ready

</script>





<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />







<title>

XMPP In Band Registration

</title>



</head>







<body>


<div data-role = "content" style = "border:1px dotted blue;position:relative;top:20%;left:20%;width:400p x;height:300px">

Username: <input id = "user" type = "text" maxlength = "15"/>

Password: <input id = "pass" type = "password" maxlength = "15"/>

Email: <input id = "email" type = "text" maxlength = "50"/>

<div id = "register_button" data-role = "button" style = ""> Register! </div>

</div>


</body>





</html>

When I fill in the username and password fields(only these two are allowed by server), and hit "register", i get this error

"Uncaught TypeError: Cannot call method 'bind' of undefined strophe.register.js:85"

What am I missing?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Register XMPP-Account using the Strophe.js-Register-Plugin ede32 BOOK: Professional XMPP Programming with JavaScript and jQuery 3 January 27th, 2013 01:55 PM
band-pass filter ondra .NET Framework 3.5 0 January 19th, 2010 12:26 PM
Duplicating Labels in the Detail band MountainProud Access 4 June 11th, 2008 02:10 PM
How do you get a users Network login ID lokilewis Pro VB.NET 2002/2003 2 November 28th, 2005 04:13 AM
Add/Register Users stacy Classic ASP Basics 3 January 22nd, 2004 09:45 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.