From 68ccec6b9c1ef35713bfa6a9a00ace3dca408b78 Mon Sep 17 00:00:00 2001 From: ibuler Date: Tue, 2 Jan 2018 17:02:03 +0800 Subject: [PATCH] =?UTF-8?q?[UPdate]=20=E4=BF=AE=E6=94=B9cookie=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/ops/models.py | 1 + apps/static/js/jumpserver.js | 13 ++++++++++++- apps/templates/_user_profile.html | 8 ++++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/apps/ops/models.py b/apps/ops/models.py index 3f83e8ffd..accdfe78f 100644 --- a/apps/ops/models.py +++ b/apps/ops/models.py @@ -235,6 +235,7 @@ class AdHoc(models.Model): return result.results_raw, result.results_summary except AnsibleError as e: logger.error("Failed run adhoc {}, {}".format(self.task.name, e)) + pass @become.setter def become(self, item): diff --git a/apps/static/js/jumpserver.js b/apps/static/js/jumpserver.js index 5812e0191..d8db987ad 100644 --- a/apps/static/js/jumpserver.js +++ b/apps/static/js/jumpserver.js @@ -357,5 +357,16 @@ String.prototype.format = function(args) { function setCookie(key, value) { var expires = new Date(); expires.setTime(expires.getTime() + (24 * 60 * 60 * 1000)); - document.cookie = key + '=' + value + ';expires=' + expires.toUTCString(); + document.cookie = key + '=' + value + ';expires=' + expires.toUTCString() + ';path=/'; + console.log("Cookie: " + document.cookie) +} + + +function delCookie(key) { + var expires = new Date(); + expires.setTime(expires.getTime() - 1); + var val = getCookie(key); + if (val !== null) { + document.cookie = key + '=' + val + ";expires" + expires.toUTCString() + ';path=/'; + } } diff --git a/apps/templates/_user_profile.html b/apps/templates/_user_profile.html index a8572dfc9..c2f341871 100644 --- a/apps/templates/_user_profile.html +++ b/apps/templates/_user_profile.html @@ -37,15 +37,19 @@ $(document).ready(function () { }) .on('click', '#switch_admin', function () { + var cookieName = "IN_ADMIN_PAGE"; setTimeout(function () { - setCookie("IN_ADMIN_PAGE", "Yes"); + delCookie(cookieName); + setCookie(cookieName, "Yes"); window.location = "/" }, 100) }) .on('click', '#switch_user', function () { + var cookieName = "IN_ADMIN_PAGE"; setTimeout(function () { console.log("Set to No"); - setCookie("IN_ADMIN_PAGE", "No"); + delCookie(cookieName); + setCookie(cookieName, "No"); window.location = "/" }, 100); })