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)
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();
});
}
};
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();
});
}
};