Preventing to visit the login page if the user is logged in

Change-Id: I7e3fe159300e4a29b3b9f5203b3bc6438a40148c
diff --git a/src/app/core/login/login.ts b/src/app/core/login/login.ts
index c091e43..ac0da82 100644
--- a/src/app/core/login/login.ts
+++ b/src/app/core/login/login.ts
@@ -13,6 +13,11 @@
     private $state: angular.ui.IStateService,
     private ModelSetup: IXosModelSetupService
   ) {
+
+    if (this.authService.isAuthenticated()) {
+      this.$state.go('xos.dashboard');
+    }
+
     this.img = this.getImg(StyleConfig.background);
 
     this.loginStyle = {
diff --git a/src/app/core/services/runtime-states.ts b/src/app/core/services/runtime-states.ts
index bc99a8e..652b554 100644
--- a/src/app/core/services/runtime-states.ts
+++ b/src/app/core/services/runtime-states.ts
@@ -7,7 +7,10 @@
   this.$get = function($state: ng.ui.IStateService) {
     return {
       addState: function(name: string, state: IXosState) {
-        $stateProvider.state(name, state);
+        // prevent to add multiple time the same state
+        if (!$state.get(name)) {
+          $stateProvider.state(name, state);
+        }
       }
     };
   };
diff --git a/src/app/datasources/rest/auth.rest.ts b/src/app/datasources/rest/auth.rest.ts
index f963799..edf7705 100644
--- a/src/app/datasources/rest/auth.rest.ts
+++ b/src/app/datasources/rest/auth.rest.ts
@@ -23,6 +23,7 @@
   logout(): Promise<any>;
   getUser(): any; // NOTE how to define return user || false ???
   isAuthenticated(): boolean;
+  clearUser(): void;
 }
 export class AuthService {
 
@@ -56,9 +57,7 @@
       xossessionid: this.$cookies.get('xossessionid')
     })
       .then(() => {
-        this.$cookies.remove('xoscsrftoken');
-        this.$cookies.remove('xossessionid');
-        this.$cookies.remove('xosuser');
+        this.clearUser();
         d.resolve();
       })
       .catch(e => {
@@ -67,6 +66,12 @@
     return d.promise;
   }
 
+  public clearUser(): void {
+    this.$cookies.remove('xoscsrftoken');
+    this.$cookies.remove('xossessionid');
+    this.$cookies.remove('xosuser');
+  }
+
   public getUser(): IXosUser {
     const user = this.$cookies.get('xosuser');
     if (angular.isDefined(user)) {