X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=www%2Fjssrc%2Fblerg%2FAPI.js;h=64b1108b0de9b2910b2d0139bae6e925dec010d0;hb=HEAD;hp=19b6734833c2af86127f8018ec8704d9f07a0aed;hpb=79fccce2b8adf36b7d08e810761bc49f07a4e271;p=blerg.git diff --git a/www/jssrc/blerg/API.js b/www/jssrc/blerg/API.js index 19b6734..64b1108 100644 --- a/www/jssrc/blerg/API.js +++ b/www/jssrc/blerg/API.js @@ -76,21 +76,29 @@ enyo.kind({ }); req.go(); }, + expireClientAuthentication: function() { + blerg.API.loggedIn = false; + blerg.API.username = ''; + enyo.setCookie('auth', '', {"Max-Age": 0}); + }, logout: function() { var req = new enyo.Ajax({ url: baseURL + '/logout', method: 'POST' }); - var logout_func = function(inSender, inResponse) { - blerg.API.loggedIn = false; - blerg.API.username = ''; - enyo.setCookie('auth', '', {"Max-Age": 0}); + var logout_func = function() { + this.expireClientAuthentication(); this.bubble('onLogoutSuccessful'); - }; + }.bind(this); req.response(this, logout_func); req.error(this, logout_func); req.go(); }, + authenticationFailed: function() { + enyo.log("Authentication failed -- logging out"); + this.expireClientAuthentication(); + this.bubble('onAuthFailure'); + }, changePassword: function(oldpassword, newpassword) { var req = new enyo.Ajax({ url: baseURL + '/passwd', @@ -186,6 +194,11 @@ enyo.kind({ req.response(this, function(inSender, inResponse) { this.bubble('onStatus', inResponse); }); + req.error(this, function() { + if (req.xhrResponse.status == 403) { + this.authenticationFailed(); + } + }); req.go(); }, clearStatus: function(type) { @@ -206,6 +219,11 @@ enyo.kind({ inResponse.type = type; this.bubble('onClearStatus', inResponse); }); + req.error(this, function() { + if (req.xhrResponse.status == 403) { + this.authenticationFailed(); + } + }); req.go(); }, loadFeed: function() { @@ -221,6 +239,11 @@ enyo.kind({ entries: inResponse }); }); + req.error(this, function() { + if (req.xhrResponse.status == 403) { + this.authenticationFailed(); + } + }); req.go(); }, getSubscriptionStatus: function(username) { @@ -233,6 +256,11 @@ enyo.kind({ subscribed: inResponse.subscribed }); }); + req.error(this, function() { + if (req.xhrResponse.status == 403) { + this.authenticationFailed(); + } + }); req.go(); }, subscription: function(username, v) { @@ -250,6 +278,11 @@ enyo.kind({ subscribed: inResponse.status == "success" && subv }); }); + req.error(this, function() { + if (req.xhrResponse.status == 403) { + this.authenticationFailed(); + } + }); req.go(); }, subscribe: function(username) { @@ -279,6 +312,11 @@ enyo.kind({ }); } }); + req.error(this, function() { + if (req.xhrResponse.status == 403) { + this.authenticationFailed(); + } + }); req.go(); } });