Openfire Inband registraion using strophe js in converse JS

Here i have explaining, how we can implement the in band registration using Strophe js.

First we need to download following library files and include in the html .

1.jquery-2.1.4.js
2.strophe.min.js
3.strophe.muc.js
4.strophe.register.js

Here is the piece of code below and you can modify the necessary fields

<script type="text/javascript">
var BOSH_SERVICE = 'http://example.com/http-bind/'; // your openfire http-bind url
var server = 'example.com';
function register() {
	var $reg_name = 'Enter username';
	var $reg_pass = 'Enter password';
	var $fullname = 'Enter fullname';
	var $email = 'Enter email';
	var url = BOSH_SERVICE;
	connection = new Strophe.Connection(url);
	var registerCallback = function (status) {
		if (status === Strophe.Status.REGISTER) {
			console.log("registerCallback: REGISTER");
			connection.register.fields.username = $reg_name;
			connection.register.fields.password = $reg_pass;
			connection.register.fields.name = $fullname;
			connection.register.fields.email = $email;
			console.log(connection.register.fields);
			connection.register.submit();
		} else if (status === Strophe.Status.REGISTERED) {
			console.log("registerCallback: REGISTERED");
			connection.authenticate();
		} else if (status === Strophe.Status.CONNECTED) {
			console.log("registerCallback: CONNECTED");
		} else if (status === Strophe.Status.CONFLICT) {
			console.log("registerCallback: Contact already existed!");
		} else if (status === Strophe.Status.NOTACCEPTABLE) {
			console.log("registerCallback: Registration form not properly filled out.")
		} else if (status === Strophe.Status.REGIFAIL) {
			console.log("registerCallback: The Server does not support In-Band Registration")
		} else {
			// every other status a connection.connect would receive
		}
	};
	connection.register.connect(server, registerCallback);
}
$(document).ready(function() {
	register();
});
</script>

I hope this may help you. Thank you.

Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkedin
Share On Pinterest

Be the first to comment

Leave a Reply

Your email address will not be published.

*


*