Skip to content

Commit

Permalink
https://github.com/w3c/wai-axsdb-web/issues/62
Browse files Browse the repository at this point in the history
  • Loading branch information
evlach committed Aug 6, 2014
1 parent 1e0057b commit 5617fac
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 26 deletions.
8 changes: 6 additions & 2 deletions js/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
window.accessdb.config = window.accessdb.config || {};

// Config to override
window.accessdb.config.URL_API_ROOT = "http://www.w3.org/WAI/accessibility-support/api_dev/";
window.accessdb.config.URL_API_ROOT = "http://www.w3.org/WAI/accessibility-support/api/";
window.accessdb.config.loadingStart = function(holder){
var div = $('<div class="progress"><div>Loading…</div></div>');
$(holder).attr("aria-busy", true);
Expand Down Expand Up @@ -295,7 +295,11 @@
window.accessdb.config.loadingEnd(targetE);
}
if(jqXHR.status===200){
callback(null, {}, jqXHR.status);
callback(null, jqXHR.responseJSON, jqXHR.status);
return;
}
if(jqXHR.status===403){
callback(null, jqXHR.responseJSON, jqXHR.status);
return;
}
callback(jqXHR, null, null);
Expand Down
59 changes: 35 additions & 24 deletions js/testing-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,15 @@ window.accessdb.Models.testingSession = Backbone.Model.extend({
this.set("testUnitIdList", newList);
},
login: function (lData, callback, targetE) {
this.resetLocalSession();
//this.resetLocalSession();
var self = this;
this.load(function(error){
if(error){
console.warn("session invalid for login");
callback(false);
}
if (self.isValid()) {
lData.sessionId = self.get("sessionId");
// if (self.isValid()) {
lData.sessionId = accessdb.sessionId;
accessdb.API.TESTINGSESSION.login(lData, function (error, data, status) {
if (!error) {
if (data.userId !== null && status===200) {
Expand All @@ -206,7 +206,7 @@ window.accessdb.Models.testingSession = Backbone.Model.extend({
return;
}
}, targetE);
}
// }
})
},
logout: function (callback) {
Expand All @@ -222,37 +222,43 @@ window.accessdb.Models.testingSession = Backbone.Model.extend({

resetLocalSession: function () {
Utils.eraseCookie('accessdb-session-id');
/*
Utils.eraseCookie('accessdb-session-userId');
Utils.eraseCookie('accessdb-session-userRoles');
sessionStorage.removeItem("accessdb-session");
console.log("session reset in local storage");
*/
},
loadLocalSession: function () {
this.set("sessionId", Utils.readCookie("accessdb-session-id") || accessdb.sessionId);
/*
if(Utils.readCookie("accessdb-session-userId"))
this.set("userId", Utils.readCookie("accessdb-session-userId"));
if(Utils.readCookie("accessdb-session-userRoles"))
this.set("userRoles", Utils.readCookie("accessdb-session-userRoles"));
if (Utils.supports_html5_storage() && sessionStorage["accessdb-session"]) {
this.set(JSON.parse(sessionStorage["accessdb-session"]));
}
else {
this.set("sessionId", Utils.readCookie("accessdb-session-id") || accessdb.sessionId);
if(Utils.readCookie("accessdb-session-userId"))
this.set("userId", Utils.readCookie("accessdb-session-userId"));
if(Utils.readCookie("accessdb-session-userRoles"))
this.set("userRoles", Utils.readCookie("accessdb-session-userRoles"));
}
*/
console.log("session loaded from local storage");
},
saveLocalSession: function () {
if (this.get("sessionId"))
Utils.createCookie("accessdb-session-id", this.get("sessionId"), 10);
/*
if (this.get("userId"))
Utils.createCookie("accessdb-session-userId", this.get("userId"), 10);
if (this.get("userRoles"))
Utils.createCookie("accessdb-session-userRoles", this.get("userRoles"), 10);
if (Utils.supports_html5_storage()) {
sessionStorage.setItem("accessdb-session", JSON.stringify(this));
}
else {
console.error("Node html5 storage supported by your browser");
console.error("No html5 storage supported by your browser");
}
*/
console.log("session saved in local storage");
},
isSessionAuthenticated: function () {
Expand All @@ -263,21 +269,26 @@ window.accessdb.Models.testingSession = Backbone.Model.extend({
},
load: function (callback) {
var self = this;
this.loadLocalSession();
accessdb.sessionId = Utils.readCookie("accessdb-session-id") || accessdb.sessionId;
accessdb.API.TESTINGSESSION.getSession(function(error, data, status){
if(error)
if(error){
callback(error);
if(status===201){ // new session created server side
accessdb.session.set("sessionId", data.sessionId);
console.log("New session created: " + self.get("sessionId"));
return;
}
if(status===403){ // not auth
// accessdb.session.set("sessionId", data.sessionId);
//self.saveLocalSession();
console.log("unauth session: " + accessdb.sessionId);
}
else if(status===200){ // existing session
accessdb.session.set("sessionId", data.sessionId);
if (self.isSessionAuthenticated()) {
$(".login-info").html("Log out " + self.get("userId"));
$(".login-info").parent().attr("href","#/log-out.html");
$(".userid").html(self.get("userId"));
}
else if(status>=200){ // auth session
accessdb.session.attributes = data;
if(self.get("userId")!=null){
//accessdb.session.set("sessionId", data.sessionId);
$(".login-info").html("Log out " + self.get("userId"));
$(".login-info").parent().attr("href","#/log-out.html");
$(".userid").html(self.get("userId"));
}

}
else{
console.warn("unknown state");
Expand Down

0 comments on commit 5617fac

Please sign in to comment.