Remove /unsubscribe from htaccess config
[blerg.git] / www / jssrc / blerg / API.js
index 19b6734..64b1108 100644 (file)
@@ -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();
     }
 });