Bläddra i källkod

[notebook] Added global redirect handler for ajax calls after a logout

Enrico Berti 10 år sedan
förälder
incheckning
44d3c7d

+ 7 - 0
desktop/core/src/desktop/templates/common_header.mako

@@ -206,6 +206,13 @@ from django.utils.translation import ugettext as _
         $.ajaxSetup({ cache: false });
       }
 
+      // global catch for ajax calls after the user has logged out
+      $( document ).ajaxSuccess(function( event, xhr, settings, data) {
+        if (data === '/* login required */'){
+          location.href='/accounts/login/?next=' + encodeURIComponent(window.location.pathname + window.location.search)
+        }
+      });
+
       // prevents framebusting and clickjacking
       if (self == top){
         $("body").css({

+ 13 - 1
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -1927,6 +1927,16 @@ ${ require.config() }
       ko.applyBindings(viewModel);
       viewModel.init();
 
+      // global catch for ajax calls after the user has logged out
+      var isLoginRequired = false;
+      $(document).ajaxSuccess(function (event, xhr, settings, data) {
+        if (data === '/* login required */' && !isLoginRequired) {
+          isLoginRequired = true;
+          window.location.href = '/accounts/login/?next=' + encodeURIComponent(window.location.pathname + window.location.search);
+        }
+      });
+
+
       if (location.getParameter("github_status") != "") {
         if (location.getParameter("github_status") == "0") {
           $.jHueNotify.info("${ _('User successfully authenticated to GitHub.') }");
@@ -1977,7 +1987,9 @@ ${ require.config() }
 
       // Close the notebook snippets when leaving the page
       window.onbeforeunload = function (e) {
-        viewModel.selectedNotebook().close();
+        if (!isLoginRequired){
+          viewModel.selectedNotebook().close();
+        }
       };
 
       $(".preview-sample").css("right", (10 + $.scrollbarWidth()) + "px");