Improvements to login stuff.
authorCameron Ball <c.ball1729@gmail.com>
Wed, 22 Oct 2014 15:51:37 +0000 (23:51 +0800)
committerCameron Ball <c.ball1729@gmail.com>
Wed, 22 Oct 2014 15:51:37 +0000 (23:51 +0800)
app/components/hello/hello-service.js
app/components/menu/menu-directive.js
app/components/user/user-service.js
app/components/userMenu/userMenu-directive.js

index 8e1e93f..f5f4ce0 100644 (file)
@@ -26,22 +26,32 @@ factory("HelloService", ['$http', function($http)
     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: "http://rock.divinelegy.meeples/user/auth",
-                method: "GET",
-                params: {token: facebookObj.access_token}
-            }).
-            success(function (data)
-            {
-                hello.setAccessToken(data.token, data.expires);
-            });
-        });
+        hello('facebook').login( {scope: "hometown"} );
     };
     
+    hello.on('auth.login', function()
+    {
+        var facebookObj = hello.utils.store('facebook');
+
+        // send to 
+        $http({
+            url: "http://rock.divinelegy.dev/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);
+        });
+    });
+        
     hello.getFacebookId = function()
     {
         return hello('facebook').api('/me').then(function(r)
index a7739e4..1daee1d 100644 (file)
@@ -8,21 +8,21 @@ directive('menu', ['HelloService', 'UserService', function(HelloService, UserSer
     return {
         templateUrl: 'components/menu/menu.html',
         link: function(scope, element){
-            HelloService.on('auth.login', function()
+            HelloService.on('auth.login.userReady', function()
             {
                 UserService.getCurrentUser().then(function(user)
                 {
                     scope.welcomeMessage = 'Welcome, ' + user.displayName;
                     scope.loggedIn = true;
+                    scope.$$phase || scope.$apply();
                 });
-                UserService.getCurrentUser();
             });
             
             HelloService.on('auth.logout', function()
             {
                 scope.welcomeMessage = '';
                 scope.loggedIn = false;
-                scope.$apply();
+                scope.$$phase || scope.$apply();
             });
         }
     };
index cd03318..3a4fbc7 100644 (file)
@@ -19,7 +19,7 @@ factory("UserService", ['$http', '$q', 'HelloService', function($http, $q, Hello
         }
 
         $http({
-            url: "http://rock.divinelegy.meeples/user/" + facebookId,
+            url: "http://rock.divinelegy.dev/user/" + facebookId,
             method: "GET"
         }).
         success(function (data)
index 3ea12ca..68d61e8 100644 (file)
@@ -10,12 +10,13 @@ directive('userMenu', ['HelloService', function(HelloService)
             HelloService.on('auth.login', function()
             {
                 scope.showMenu = true;
+                scope.$$phase || scope.$apply();
             });
             
             HelloService.on('auth.logout', function()
             {
                 scope.showMenu = false;
-                scope.$apply();
+                scope.$$phase || scope.$apply();
             });
         }
     };