title: AngularJS 'Cannot read property 'then' of undefined'
body: <p>I've this problem, when I click on login button, the chrome console log this:</p>
  
  <blockquote>
    <p>angular.min.js:117 TypeError: Cannot read property 'then' of undefined
        at m.$scope.logIn (loginModuleController.js:11)</p>
  </blockquote>
  
  <p>Service:</p>
  
  <pre><code>angular.module('loginModule')
  .factory('loginService', function($http){
    return{
      login: function(username, password){
        var session;
        $http.post('../server/php/auth/auth.php', {
          username: username,
          password: password
        })
        .then(function(res){
          session = res;
        });
        return session;
      },
      isLogged: function(){
        return $http.get('../angCMS/server/php/auth.php?is_logged=true');
      },
      logOut: function(){
        return $http.get('../angCMS/server/php/auth.php?logout=true');
      }
    };
  });
  </code></pre>
  
  <p>controller:</p>
  
  <pre><code>angular.module('loginModule')
  .controller('LoginCtrl', ['$scope', 'loginService', function($scope, loginService){
  
    $scope.auth = false;
  
    $scope.username;
    $scope.password;
    $scope.logIn = function(){
      loginService.login($scope.username, $scope.password).then(function(response){
  
      }, function(res){
  
      });
    };
  
    $scope.isLogged = function(){
      loginService.isLogged()
      .then(function(response){
        if(response){
          $scope.auth = true;
        }
      });
    };
  
    $scope.logOut = function(){
      loginService.logOut()
      .then(function(response){
        if(response){
          $scope.auth = false;
        }
      });
    };
  
  }]);
  </code></pre>
  
  <p>and this is the html template:</p>
  
  <pre><code>&lt;div class="container" ng-if="auth==false"&gt;
    &lt;div class="col-md-4 col-md-offset-4"&gt;
      &lt;div class="row"&gt;
        &lt;br/&gt;&lt;h2 align="center"&gt;Login&lt;/h2&gt;
      &lt;/div&gt;
      &lt;div class="well"&gt;
          &lt;form class="form-horizontal"&gt;
          &lt;fieldset&gt;
            &lt;div class="form-group"&gt;
                  &lt;input type="text" class="form-control" placeholder="Username" ng-model="username" required&gt;
            &lt;/div&gt;
            &lt;div class="form-group"&gt;
                  &lt;input type="password"  class="form-control" placeholder="Password" ng-model="password" required&gt;
            &lt;/div&gt;
            &lt;div class="form-group"&gt;
                  &lt;button class="btn btn-md btn-primary btn-block" type="submit" ng-click="logIn()"&gt;Sign in&lt;/button&gt;
            &lt;/div&gt;
          &lt;/fieldset&gt;
        &lt;/div&gt;
      &lt;/form&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>PHP login method:</p>
  
  <pre><code>public function login($user, $pass){
  
          $user = htmlspecialchars(trim($user));
          $pass = md5(htmlspecialchars(trim($pass)));
  
          $res = $this-&gt;DB-&gt;prepare("SELECT * FROM `admin` WHERE username = :user");
          if(!$res-&gt;execute(Array(":user"=&gt;$user)))
              die(mysql_error());
  
          $row = $res-&gt;fetch(PDO::FETCH_ASSOC);
  
          if(!$row['password'] == $pass)
              die("Errore: password errata!");
  
          $_SESSION['logged'] = $row;
          array_push($session, $_SESSION['logged'], true);
  
          return $session;
      }
  </code></pre>