Make API object propagate authentication failures
Auto-logout when an API call gives a 403
});
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',
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) {
inResponse.type = type;
this.bubble('onClearStatus', inResponse);
});
+ req.error(this, function() {
+ if (req.xhrResponse.status == 403) {
+ this.authenticationFailed();
+ }
+ });
req.go();
},
loadFeed: function() {
entries: inResponse
});
});
+ req.error(this, function() {
+ if (req.xhrResponse.status == 403) {
+ this.authenticationFailed();
+ }
+ });
req.go();
},
getSubscriptionStatus: function(username) {
subscribed: inResponse.subscribed
});
});
+ req.error(this, function() {
+ if (req.xhrResponse.status == 403) {
+ this.authenticationFailed();
+ }
+ });
req.go();
},
subscription: function(username, v) {
subscribed: inResponse.status == "success" && subv
});
});
+ req.error(this, function() {
+ if (req.xhrResponse.status == 403) {
+ this.authenticationFailed();
+ }
+ });
req.go();
},
subscribe: function(username) {
});
}
});
+ req.error(this, function() {
+ if (req.xhrResponse.status == 403) {
+ this.authenticationFailed();
+ }
+ });
req.go();
}
});
onSetTitle: "setTitle",
onPostVisibility: "postVisibilityUpdate",
onReload: "sendReload",
- onShowChangePassword: "showChangePassword"
+ onShowChangePassword: "showChangePassword",
+ onAuthFailure: "authFailure"
},
components: [
{classes: "blerg-header", components: [
},
showChangePassword: function() {
this.$.passwdDialog.show();
+ },
+ authFailure: function(inSender, inEvent) {
+ this.logout();
}
});