make logout page modal to confirm logout and give options
authorAlex Heneveld <alex.heneveld@cloudsoftcorp.com>
Mon, 28 Jan 2019 02:02:57 +0000 (02:02 +0000)
committerAlex Heneveld <alex.heneveld@cloudsoftcorp.com>
Mon, 28 Jan 2019 02:02:57 +0000 (02:02 +0000)
ui-modules/logout/app/views/main/main.controller.js
ui-modules/logout/app/views/main/main.template.html

index 357bb89..4740c74 100644 (file)
@@ -40,7 +40,7 @@ export function mainStateConfig($stateProvider) {
 }
 
 export function mainStateController($scope, $http) {
-    $scope.state = { status: "checking", message: "Preparing to log out" };
+    $scope.state = { status: "confirm" };
     $scope.$emit(HIDE_INTERSTITIAL_SPINNER_EVENT);
 
     function clearLocalCache() {
@@ -64,22 +64,13 @@ export function mainStateController($scope, $http) {
         }
         clearLocalCache();
     }
-        
-    function getUserThen(f) {
-        $http.get('v1/server/user').then(response => {
-            console.log("User check response", response);
-            $scope.state = { status: "logging-out", user: response.data };
-            f(response.data);
-            clearLocalCache();
-            
-        }, error => {
-            handleError("processing logged-on user check", error);
-        });
-    }
     
-    function postLogout(user) {
-        console.log("posting to "+'v1/logout/'+user);
-        $http.post('v1/logout'+(user ? '/'+user : '')).then(response => {
+    this.logout = (keepCreds) => {
+        $scope.state = { status: "logging-out" };
+        $http({ url: 'v1/logout'+(keepCreds ? '' : '?unauthorize=logging-out-from-webapp'), 
+                method: 'POST',
+                transformResponse: x => x})
+        .then(response => {
             console.log("Logout response", response);
             $scope.state = { status: "just-logged-out" };
             clearLocalCache();
@@ -89,9 +80,10 @@ export function mainStateController($scope, $http) {
         });
     }
     
-    $scope.logout = () => getUserThen(postLogout);
-    $scope.logout();
-    
+    this.retry = () => {
+        $scope.state = { status: "confirm" };
+    }
+        
     return;
     
     let userRequest = new XMLHttpRequest();
index fc12f8f..f10611c 100644 (file)
 <div class="container-fluid">
     <div class="row">
         <div class="col-md-12 text-center" ng-switch="state.status">
-            <div ng-switch-when="checking">
-                <h2>Logout in progress.../h2>
-                <p><a class="btn btn-lg btn-primary" ng-click="retry()">Retry</a></p>
+            <div ng-switch-when="confirm">
+                <h2>Are you sure you wish to log out?</h2>
+                <p>
+                    <a class="btn btn-lg btn-primary" ng-click="vm.logout()">Yes</a>
+                    <a class="btn btn-lg btn-outline" ng-click="vm.logout(false)">Yes, but keep credentials in browser</a>
+                    <a class="btn btn-lg btn-outline" href="/">No, return to <%= getBrandedText('product.name') %></a>
+                </p>
             </div>
+            
             <div ng-switch-when="logging-out">
-                <h2>Logout of {{ state.user }} in progress...</h2>
-                <p><a class="btn btn-lg btn-primary" ng-click="retry()">Retry</a></p>
+                <h2>Logging out...</h2>
+                <p><a class="btn btn-lg btn-primary" ng-click="vm.retry()">Retry</a></p>
             </div>
+            
             <div ng-switch-when="just-logged-out">
                 <h2>Logout successful</h2>
                 <p>Thank you for using <%= getBrandedText('product.name') %>, see you soon</p>
                 <p><a class="btn btn-lg btn-primary" href="/">Log back in</a></p>
-                <p><a class="btn btn-lg btn-outline" ng-click="checkUnauthorized()">Clear local cached auth</a></p>
             </div>
             <div ng-switch-when="already-logged-out">
                 <h2>Already logged out</h2>
                 <p>Thank you for using <%= getBrandedText('product.name') %>, see you soon</p>
                 <p><a class="btn btn-lg btn-primary" href="/">Log back in</a></p>
-                <p><a class="btn btn-lg btn-outline" ng-click="checkUnauthorized()">Clear local cached auth</a></p>
             </div>
+            
             <div ng-switch-default>
                 <h2>Log out failed<span ng-if="state.message">: {{ state.message }}</span</h2>
                 <p>
-                <p><a class="btn btn-lg btn-primary" ng-click="retry()">Try logging out again</a></p>
-                <p><a class="btn btn-lg btn-outline" href="/">Return to app (login if needed)</a></p>
+                <p><a class="btn btn-lg btn-primary" ng-click="vm.retry()">Try logging out again</a></p>
+                <p><a class="btn btn-lg btn-outline" href="/">Return to <%= getBrandedText('product.name') %> (login if needed)</a></p>
             </div>
         </div>
     </div>