Commit 4525e4b7 authored by Sebastien Robin's avatar Sebastien Robin

bug fixes done by Francois (sorry, I do not have details)

parent 2e3330ea
...@@ -14,22 +14,60 @@ var displayNewAccountForm = function(bool) { ...@@ -14,22 +14,60 @@ var displayNewAccountForm = function(bool) {
} }
} }
function logIntoDav(wallet) {
var recall = window.location;
window.location.href = wallet.storageLocation+"#"+recall;
}
/**
* create a new storage
*/
function initStorage(wallet) { function initStorage(wallet) {
if(!wallet.provider) {//local storage if(wallet.provider) {//DAV storage
/** // load JIO file from a DAV and create the JIO object
* load JIO file from a DAV and create and return the JIO object initializeFromDav(wallet.userName, wallet.storageLocation, {"ID":"www.ungproject.com", "password":wallet.applicationPassword});
* This function will be replaced. The aim is to load JIO in more various ways, and use JIO.initialize after } else {
* @param userName : name of the user Storage.create('{"type":"local","userName":"'+wallet.userName+'"}');
* @param location : server location }
* @param applicant : (optional) information about the person/application needing this JIO object (allow limited access) }
* @return JIO object
/**
* try to log an user just after having logged in their Dav account
* if the user is logged, it means that getApplicationPasswordFromURL has a result
*/
function tryLog() {
var wallet = getWallet();
var applicationPassword = getApplicationPasswordFromURL();
if(applicationPassword) {
wallet.applicationPassword = applicationPassword;
setWallet(wallet);//to delete for new registration each time
initStorage(wallet);
//go to ung when the storage is ready
waitBeforeSucceed(function() {return getCurrentStorage().getUser();},function(){window.location.href = "ung.html";});
}
}
/**
* Log an user after they fill their Name and storage provider
*/ */
(function initializeFromDav(userName, location, applicant) { function logUser() {
var wallet = new Wallet();
setWallet(wallet);
if(!wallet.userName) {return;}
if(wallet.provider) {
if(!wallet.storageLocation) {alert("unable to find your storage from your provider");return;}
if(!wallet.applicationPassword) {logIntoDav(wallet);return;}
}
initStorage(wallet);
//go to ung when the storage is ready
waitBeforeSucceed(function() {return getCurrentStorage().getUser();},function(){window.location.href = "ung.html";});
}
/***************************************************************************
********************** Unhosted functions *****************************
* these function are only required to respect the unhosted architecture */
// load JIO file from a DAV and create the JIO object
function initializeFromDav(userName, location, applicant) {
//get the user personal JIO file //get the user personal JIO file
$.ajax({ $.ajax({
url: location+"/dav/"+userName+"/"+applicant.ID+"/"+"jio.json",//we could use userAdress instead... url: location+"/dav/"+userName+"/"+applicant.ID+"/"+"jio.json",//we could use userAdress instead...
...@@ -44,16 +82,9 @@ function initStorage(wallet) { ...@@ -44,16 +82,9 @@ function initStorage(wallet) {
error: function(type) {alert("Error "+type.status+" : fail while trying to load jio.json");} error: function(type) {alert("Error "+type.status+" : fail while trying to load jio.json");}
}); });
return JIO; return JIO;
})(wallet.userName, wallet.storageLocation, {"ID":"www.ungproject.com", "password":wallet.applicationPassword});
} else {
Storage.create('{"type":"local","userName":"'+wallet.userName+'"}');
}
} }
//unhosted functions
function getStorageLocation(provider) { function getStorageLocation(provider) {
//TODO : uses webFinger //TODO : use webFinger
return "http://"+provider; return "http://"+provider;
} }
function getApplicationPasswordFromURL() { function getApplicationPasswordFromURL() {
...@@ -70,36 +101,10 @@ var Wallet = function() { ...@@ -70,36 +101,10 @@ var Wallet = function() {
this.provider = $("input#storage_location").attr("value"); this.provider = $("input#storage_location").attr("value");
this.storageLocation = getStorageLocation(this.provider); this.storageLocation = getStorageLocation(this.provider);
} }
//redirects the application to the storage of the user to log the application in and get the password for the application
function logIntoDav(wallet) {
/** var recall = window.location;
* try to log an user after having logged in their Dav account window.location.href = wallet.storageLocation+"#"+recall;
*/
function tryLog() {
var wallet = getWallet();
var applicationPassword = getApplicationPasswordFromURL();
if(applicationPassword) {
wallet.applicationPassword = applicationPassword;
setWallet(wallet);//to delete for new registration each time
initStorage(wallet);
waitBeforeSucceed(function() {return getCurrentStorage().getUser();},function(){window.location.href = "ung.html";});
}
}
/**
* Log an user with it's Name and storage provider
*/
function logUser() {
var wallet = new Wallet();
setWallet(wallet);
if(!wallet.userName) {return;}
if(wallet.provider) {
if(!wallet.storageLocation) {alert("unable to find your storage from your provider");return;}
if(!wallet.applicationPassword) {logIntoDav(wallet);return;}
}
initStorage(wallet);
waitBeforeSucceed(function() {return getCurrentStorage().getUser();},function(){window.location.href = "ung.html";});
} }
...@@ -109,7 +114,9 @@ function logUser() { ...@@ -109,7 +114,9 @@ function logUser() {
/**********************************************************************
* functions from UNG Docs 1.0 and not currently used
*/
/** /**
......
...@@ -287,7 +287,7 @@ Storage.load({ ...@@ -287,7 +287,7 @@ Storage.load({
success: function(list) { success: function(list) {
delete list[getCurrentUser().getName()+".profile"];//remove the profile file delete list[getCurrentUser().getName()+".profile"];//remove the profile file
getCurrentStorage().documentList = list; getCurrentStorage().documentList = list;
fireEvent(Storage.LIST_READY); Storage.fireEvent(Storage.LIST_READY);
} }
} }
JIO.getDocumentList(option); JIO.getDocumentList(option);
...@@ -303,7 +303,7 @@ Storage.load({ ...@@ -303,7 +303,7 @@ Storage.load({
setUser: function(user) { setUser: function(user) {
this.user = user; this.user = user;
this.userName = user.getName(); this.userName = user.getName();
fireEvent(Storage.USER_READY); Storage.fireEvent(Storage.USER_READY);
this.updateDocumentList(); this.updateDocumentList();
getCurrentStorage().save(); getCurrentStorage().save();
......
...@@ -6,7 +6,9 @@ ...@@ -6,7 +6,9 @@
* Class UngObject * Class UngObject
* provides useful general methods * provides useful general methods
*/ */
UngObject = function() {} UngObject = function() {
this.listenerList = [];
}
/* return true if this object implements the interface */ /* return true if this object implements the interface */
UngObject.prototype.implement = function(myInterface) UngObject.prototype.implement = function(myInterface)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment