title: display connected user after login
body: <p>would you please help me to update my controller to change the username when the user is logged in is changed.
  the problem that I'm facing is that even after updating the user, the field username is always empty.
  Would you please help me to fix that?
  here is my controller</p>
  
  <pre><code>controller(
              "HomeController",
              function HomeController($scope, sessionService, accountService) {
                  var loggedUSer = {};
                  loggedUSer = accountService.getuser();
                  if (angular.isDefined(loggedUSer))
                      $scope.username = loggedUSer.username;
                  $scope.isLoggedIn = sessionService.isLoggedIn;
                  $scope.logout = sessionService.logout;
              })
  </code></pre>
  
  <p>and the username is displayed here after calling the controller</p>
  
  <pre><code>&lt;b&gt;{{username}}&lt;/b&gt;
  </code></pre>
  
  <p>When I load my web page the username field is empty and is always displayed empty even if the username is populated after user login. Ineed to change that to display the connected user.</p>
  
  <p>below is the factory used to retrieve the user and login :</p>
  
  <pre><code>factory(
              'sessionService',
              function($http) {
                  var session = {};
                  session.login = function(data) {
                      return $http
                              .post(
                                      "/myapp/login",
                                      "username=" + data.username
                                              + "&amp;password=" + data.password,
                                      {
                                          headers : {
                                              'Content-Type' : 'application/x-www-form-urlencoded'
                                          }
                                      })
                              .then(
                                      session.LoggIn = function(data) {
                                          alert("login successful");
                                          localStorage.setItem("session", {});
                                          console
                                                  .log(
                                                          "localStorage after login: ",
                                                          localStorage);
                                          console.log(
                                                  "session after login: ",
                                                  session);
                                          console.log("data after login: ",
                                                  data);
                                      }, function(data) {
                                          alert("error logging in");
                                      });
                  };
                  session.logout = function() {
                      localStorage.removeItem("session");
                  };
                  session.isLoggedIn = function() {
                      return localStorage.getItem("session") !== null;
                  };
                  return session;
              })
  </code></pre>
  
  <p>and </p>
  
  <pre><code>factory(
              'accountService',
              function($resource, sessionService) {
                  var service = {};
                  service.register = function(account, profile, success,
                          failure) {
                      if (profile.id == 1) {
                          var Account = $resource("/myapp/rest/account");
                          Account.save({}, account, success, failure);
                      } else {
                          var Account = $resource("/myapp/rest/account/teacher");
                          Account.save({}, account, success, failure);
                      }
                  };
                  service.userExists = function(account, success, failure) {
                      var Account = $resource("/myapp/rest/account");
                      var data = Account.get({
                          username : account.username,
                          password : account.password
                      }, function() {
                          console.log("user details : ", data);
                          var accounts = data.username;
                          if (accounts &amp;&amp; accounts.length !== 0) {
                              console
                                      .log("profile id :",
                                              data.userProfile.id);
                              service.data = data;                            
                              success(account);
                          } else {
                              failure();
                          }
                      }, failure);
                  };
                  service.getuser = function() {
                      if (service.data){
                          console.log (service.data);
                          return service.data;
                      }
                      else {
                          sessionService.logout();
                      }
                  };
                  return service;
              }).controller(
              "LoginController",
              function($scope, sessionService, accountService, $state) {
                  $scope.login = function() {
                      accountService.userExists($scope.account, function(
                              account) {
                          sessionService.login($scope.account).then(
                                  function() {
                                      $state.go("home");
                                  });
                      }, function() {
                          alert("Error logging in user");
                      });
                  };
              })
  </code></pre>