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

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

parent 2e3330ea
...@@ -13,67 +13,24 @@ var displayNewAccountForm = function(bool) { ...@@ -13,67 +13,24 @@ var displayNewAccountForm = function(bool) {
$("table#new-account-table").css("display","table"); $("table#new-account-table").css("display","table");
} }
} }
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
* @param userName : name of the user
* @param location : server location
* @param applicant : (optional) information about the person/application needing this JIO object (allow limited access)
* @return JIO object
*/
(function initializeFromDav(userName, location, applicant) {
//get the user personal JIO file
$.ajax({
url: location+"/dav/"+userName+"/"+applicant.ID+"/"+"jio.json",//we could use userAdress instead...
type: "GET",
async: false,
dataType: "text",
headers: {Authorization: "Basic "+Base64.encode(userName+":"+applicant.password)},
fields: {withCredentials: "true"},
success: function(jioContent){
Storage.create(jioContent);
},
error: function(type) {alert("Error "+type.status+" : fail while trying to load jio.json");}
});
return JIO;
})(wallet.userName, wallet.storageLocation, {"ID":"www.ungproject.com", "password":wallet.applicationPassword});
} else { } else {
Storage.create('{"type":"local","userName":"'+wallet.userName+'"}'); Storage.create('{"type":"local","userName":"'+wallet.userName+'"}');
} }
} }
//unhosted functions
function getStorageLocation(provider) {
//TODO : uses webFinger
return "http://"+provider;
}
function getApplicationPasswordFromURL() {
return window.location.href.split("appPwd:")[1]
}
function setWallet(newWallet) {
localStorage.setItem("wallet",JSON.stringify(newWallet));
}
function getWallet() {
return JSON.parse(localStorage.getItem("wallet"))||null;
}
var Wallet = function() {
this.userName = $("input#name").attr("value");
this.provider = $("input#storage_location").attr("value");
this.storageLocation = getStorageLocation(this.provider);
}
/** /**
* try to log an user after having logged in their Dav account * 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() { function tryLog() {
var wallet = getWallet(); var wallet = getWallet();
...@@ -82,42 +39,92 @@ function tryLog() { ...@@ -82,42 +39,92 @@ function tryLog() {
wallet.applicationPassword = applicationPassword; wallet.applicationPassword = applicationPassword;
setWallet(wallet);//to delete for new registration each time setWallet(wallet);//to delete for new registration each time
initStorage(wallet); initStorage(wallet);
//go to ung when the storage is ready
waitBeforeSucceed(function() {return getCurrentStorage().getUser();},function(){window.location.href = "ung.html";}); waitBeforeSucceed(function() {return getCurrentStorage().getUser();},function(){window.location.href = "ung.html";});
} }
} }
/** /**
* Log an user with it's Name and storage provider * Log an user after they fill their Name and storage provider
*/ */
function logUser() { function logUser() {
var wallet = new Wallet(); var wallet = new Wallet();
setWallet(wallet); setWallet(wallet);
if(!wallet.userName) {return;} if(!wallet.userName) {return;}
if(wallet.provider) { if(wallet.provider) {
if(!wallet.storageLocation) {alert("unable to find your storage from your provider");return;} if(!wallet.storageLocation) {alert("unable to find your storage from your provider");return;}
if(!wallet.applicationPassword) {logIntoDav(wallet);return;} if(!wallet.applicationPassword) {logIntoDav(wallet);return;}
} }
initStorage(wallet); initStorage(wallet);
//go to ung when the storage is ready
waitBeforeSucceed(function() {return getCurrentStorage().getUser();},function(){window.location.href = "ung.html";}); 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
$.ajax({
url: location+"/dav/"+userName+"/"+applicant.ID+"/"+"jio.json",//we could use userAdress instead...
type: "GET",
async: false,
dataType: "text",
headers: {Authorization: "Basic "+Base64.encode(userName+":"+applicant.password)},
fields: {withCredentials: "true"},
success: function(jioContent){
Storage.create(jioContent);
},
error: function(type) {alert("Error "+type.status+" : fail while trying to load jio.json");}
});
return JIO;
}
function getStorageLocation(provider) {
//TODO : use webFinger
return "http://"+provider;
}
function getApplicationPasswordFromURL() {
return window.location.href.split("appPwd:")[1]
}
function setWallet(newWallet) {
localStorage.setItem("wallet",JSON.stringify(newWallet));
}
function getWallet() {
return JSON.parse(localStorage.getItem("wallet"))||null;
}
var Wallet = function() {
this.userName = $("input#name").attr("value");
this.provider = $("input#storage_location").attr("value");
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;
window.location.href = wallet.storageLocation+"#"+recall;
}
/**********************************************************************
* functions from UNG Docs 1.0 and not currently used
*/
/** /**
* create an account (to use only if UNG is also a storage provider) * create an account (to use only if UNG is also a storage provider)
*/ */
function createNewUser() { function createNewUser() {
var form = $("form#create-user")[0]; var form = $("form#create-user")[0];
/* check that the form is complete */ /* check that the form is complete */
for(var i = 0; i<form.length-1; i++) { for(var i = 0; i<form.length-1; i++) {
if(!form[i].value) {formError("please fill each field");} if(!form[i].value) {formError("please fill each field");}
...@@ -128,11 +135,11 @@ function createNewUser() { ...@@ -128,11 +135,11 @@ function createNewUser() {
form[5].value=""; form[5].value="";
} }
if(!testEMail()) {formError("please enter a valid email");} if(!testEMail()) {formError("please enter a valid email");}
/* create the new user */ /* create the new user */
//JIO //JIO
} }
/** /**
* Report an error when filling the form * Report an error when filling the form
*/ */
...@@ -140,7 +147,7 @@ function formError(message) { ...@@ -140,7 +147,7 @@ function formError(message) {
$("td#form-message").attr("value",message); $("td#form-message").attr("value",message);
$("td#form-message").css("display","table-cell"); $("td#form-message").css("display","table-cell");
} }
/** /**
* check if an email address is valid * check if an email address is valid
*/ */
...@@ -149,7 +156,7 @@ function testEMail(email) { ...@@ -149,7 +156,7 @@ function testEMail(email) {
var regEx = new RegExp(patern); var regEx = new RegExp(patern);
return regEx.test(email); return regEx.test(email);
} }
//TODO //TODO
function setFocus() { function setFocus() {
login = document.getElementById('name'); login = document.getElementById('name');
...@@ -158,4 +165,4 @@ function setFocus() { ...@@ -158,4 +165,4 @@ function setFocus() {
password.focus(); password.focus();
else else
login.focus(); login.focus();
} }
\ No newline at end of file
...@@ -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();
...@@ -622,4 +622,4 @@ editUserSettings = function() { ...@@ -622,4 +622,4 @@ editUserSettings = function() {
} }
} }
}); });
} }
\ No newline at end of file
...@@ -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