angular.module('starter.controllers')

.controller('loginCtrl', function($scope, $ionicModal, $state, $ionicHistory, Profile, $http) {
  /*Dealings of the Ionic to clear navigation history*/
  $ionicHistory.clearHistory();

  /*Function to login with the Facebook and set the user on the services*/
  $scope.fbLogin = function () {
    var ref = new Firebase("https://partiuapp.firebaseio.com");
    ref.authWithOAuthPopup("facebook", function(error, authData) {
        if (error) {
            console.log("Login Failed!", error);
        } else {
            console.log("Authenticated successfully with payload:", authData);
            var data = authData.facebook;
            if(data.cachedUserProfile.gender == 'male') {
                data.cachedUserProfile.gender = 'Masculino';
            }
            else if(data.cachedUserProfile.gender == 'female') {
                data.cachedUserProfile.gender = 'Feminino';
            }

            Profile.setUser(data.displayName, data.email, data.accessToken, data.cachedUserProfile.gender, data.profileImageURL, data.id, data.cachedUserProfile.link);

            var requestData = {
              "user": {
                "name": data.displayName,
                "email": data.email,
                "facebook_id": data.id,
                "photo_url": data.profileImageURL
              }
            }

            $http.post('http://localhost:3000/api/users', requestData).success(function(data) {
            });

            $http.get('http://localhost:3000/api/get_user_id', {params:{"facebook_id": data.id}}).success(function(idData) {
              Profile.updateBackendId(idData);

            });
            $state.go('menu.home');
        }
    }, {
        remember: "default",
        scope: "email, public_profile, user_friends, user_about_me, publish_actions"
    });
  };
})

@@ -1352,32 +1352,33 @@
  %7D%0A            %7D
+;
 %0A%0A            $h
@@ -1385,11 +1385,10 @@
 ttp.
-pos
+ge
 t('h
@@ -1416,54 +1416,156 @@
 api/
-users', requestData).success(function(
+get_user_id', %7Bparams:%7B%22facebook_id%22: data.id%7D%7D)%0A              .then(function(response) %7B%0A                Profile.updateBackendId(response.
 data)
- %7B%0A
+;%0A  
     
@@ -1573,20 +1573,40 @@
        %7D
-);%0A%0A
+, function(error) %7B%0A    
         
@@ -1607,34 +1607,35 @@
           $http.
-ge
+pos
 t('http://localh
@@ -1651,57 +1651,48 @@
 api/
-get_user_id', %7Bparams:%7B%22facebook_id%22: data.id%7D%7D).
+users', requestData).%0A                  
 succ
@@ -1708,18 +1708,21 @@
 ion(
-idData) %7B%0A
+user) %7B%0A     
     
@@ -1723,32 +1723,33 @@
                 
+ 
 Profile.updateBa
@@ -1760,18 +1760,42 @@
 dId(
-idData);%0A%0A
+user.id);%0A                  %7D);%0A  
     
@@ -1798,32 +1798,33 @@
             %7D);%0A
+%0A
             $sta

Fix bug: user_id was not setted in the register