Gracefully handle login failures.
authorCameron Ball <cameron@getapproved.com.au>
Tue, 30 Dec 2014 02:46:26 +0000 (10:46 +0800)
committerCameron Ball <cameron@getapproved.com.au>
Tue, 30 Dec 2014 02:46:26 +0000 (10:46 +0800)
app/components/hello/hello-service.js
app/components/user/user-service.js
app/pages/profile/profile.js

index 5fd5f39..e903c97 100644 (file)
@@ -46,31 +46,10 @@ factory("HelloService", ['rockEndpoint', '$http', '$location', '$q', function(ro
     hello.facebookLogin = function()
     {
         // get the short term token
-        hello('facebook').login( {scope: "hometown"} ).then(function() {
-            var facebookObj = hello.utils.store('facebook');
-
-            // send to 
-            $http({
-                url: rockEndpoint + "user/auth",
-                method: "GET",
-                params: {token: facebookObj.access_token}
-            }).
-            success(function (data)
-            {
-                /*
-                 * It is no good to use auth.login because that comes back almost
-                 * instantly due to facebook. We rely on rock.de for things like
-                 * the user name, so we need to wait for it to be ready, which happens
-                 * here.
-                 */
-                hello.emit('auth.login.userReady');
-                hello.setAccessToken(data.token, data.expires);
-            })
-            .error(function(data)
-            {
-                hello.emit('auth.login.fail');
-            });
-        },
+        //originally I put the auth.login callback in the .then bit, but that was
+        //no good since it only got called after pressing the login button, but not
+        //when the page was refreshed. I still need the fail thing here tho.
+        hello('facebook').login( {scope: "hometown"} ).then(function() {},
         function()
         {
             hello.emit('auth.login.fail');
@@ -79,7 +58,29 @@ factory("HelloService", ['rockEndpoint', '$http', '$location', '$q', function(ro
     
     hello.on('auth.login', function()
     {
+        var facebookObj = hello.utils.store('facebook');
 
+        // send to 
+        $http({
+            url: rockEndpoint + "user/auth",
+            method: "GET",
+            params: {token: facebookObj.access_token}
+        }).
+        success(function (data)
+        {
+            /*
+             * It is no good to use auth.login because that comes back almost
+             * instantly due to facebook. We rely on rock.de for things like
+             * the user name, so we need to wait for it to be ready, which happens
+             * here.
+             */
+            hello.emit('auth.login.userReady');
+            hello.setAccessToken(data.token, data.expires);
+        })
+        .error(function(data)
+        {
+            hello.emit('auth.login.fail');
+        });
     });
         
     hello.getFacebookId = function()
index 1c1d57c..a5cffa4 100644 (file)
@@ -79,7 +79,8 @@ factory("UserService", ['$rootScope', 'rockEndpoint', '$http', '$q', 'HelloServi
         }).
         error(function(data, status)
         {
-            $rootScope.$broadcast('message.error', 'Uh oh, something went really wrong. Try refreshing the page.'); 
+            deferred.reject();
+            //$rootScope.$broadcast('message.error', 'Uh oh, something went really wrong. Try refreshing the page.'); 
         });
 
         return deferred.promise;
index 0581430..ce94d0a 100644 (file)
@@ -15,9 +15,14 @@ angular.module("DivinElegy.pages.profile", ['DivinElegy.components.user'])
     $scope.ok = function()
     {
         var test = {displayName:"tits mcgee"};
-        UserService.updateCurrentUser(test).then(function(result)
+        UserService.updateCurrentUser(test).
+        then(function(result)
         {
             console.log(result);
+        }).
+        fail(function()
+        {
+            console.log('uh oh the spagghetti');
         });
     };