1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/jappix_ynh.git synced 2024-09-03 19:26:19 +02:00
jappix_ynh/source/app/javascripts/httpauth.js

114 lines
3.2 KiB
JavaScript
Raw Normal View History

2014-03-12 14:52:47 +01:00
/*
Jappix - An open social platform
These are the http-auth JS scripts for Jappix
-------------------------------------------------
License: AGPL
Author: Valérian Saliou, Kload
*/
// Bundle
var HTTPAuth = (function () {
/**
* Alias of this
* @private
*/
var self = {};
2014-04-08 20:14:28 +02:00
/**
2014-03-12 14:52:47 +01:00
* Login to a HTTP session
* @public
* @param {string} lNick
* @param {string} lPass
* @param {string} lServer
* @param {number} lPriority
* @return {boolean}
*/
self.go = function(lNick, lPass, lServer, lPriority) {
try {
// We add the login wait div
Interface.showGeneralWait();
if(Common.hasWebSocket()) {
// WebSocket supported & configured
con = new JSJaCWebSocketConnection({
httpbase: HOST_WEBSOCKET
});
} else {
var httpbase = (HOST_BOSH_MAIN || HOST_BOSH);
// Check BOSH origin
BOSH_SAME_ORIGIN = Origin.isSame(httpbase);
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
// We create the new http-binding connection
con = new JSJaCHttpBindingConnection({
httpbase: httpbase
});
}
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
// And we handle everything that happen
2014-04-08 20:14:28 +02:00
Connection.setupCon(con);
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
// Generate a resource
var random_resource = DataStore.getDB(Connection.desktop_hash, 'session', 'resource');
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
if(!random_resource) {
random_resource = JAPPIX_RESOURCE + ' (' + (new Date()).getTime() + ')';
}
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
// Generate a priority
lPriority = lPriority ? lPriority : 10;
// Store the resource (for reconnection)
DataStore.setDB(Connection.desktop_hash, 'session', 'resource', random_resource);
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
// Generate a session XML to be stored
session_xml = '<session><stored>true</stored><domain>' + lServer.htmlEnc() + '</domain><username>' + lNick.htmlEnc() + '</username><resource>' + random_resource + '</resource><password>' + lPass.htmlEnc() + '</password><priority>' + (lPriority + '').htmlEnc() + '</priority></session>';
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
// Save the session parameters (for reconnect if network issue)
Connection.current_session = session_xml;
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
// We store the infos of the user into the data-base
DataStore.setDB(Connection.desktop_hash, 'priority', 1, 10);
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
// We connect !
2014-11-25 20:12:58 +01:00
con.connect({
'domain': $.trim(lServer),
'username': $.trim(lNick),
'resource': random_resource,
'pass': lPass,
'secure': true,
'xmllang': XML_LANG
});
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
// Change the page title
Interface.title('wait');
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
Console.info('Jappix is connecting...');
} catch(e) {
Console.error('HTTPAuth.go', e);
// Reset Jappix
Talk.destroy();
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
// Open an unknown error
Board.openThisError(2);
} finally {
return false;
}
};
/**
* Return class scope
*/
return self;
})();