From 624555c28d47a70de8828966b9b34ec05fe54d57 Mon Sep 17 00:00:00 2001 From: Thirumal Ravula Date: Fri, 29 Dec 2017 13:58:46 +0530 Subject: [PATCH 1/8] refactord authentication --- .gitignore | 3 +- src/demos/2017-11-29-demonstration-script.org | 2 +- .../image-licensing.org | 0 src/runtime/authentication.org | 168 ++++++++---------- 4 files changed, 82 insertions(+), 91 deletions(-) rename image-licensing.org => src/image-licensing.org (100%) diff --git a/.gitignore b/.gitignore index f6fad06..57d2059 100644 --- a/.gitignore +++ b/.gitignore @@ -28,4 +28,5 @@ lint_output literate-tools src/sitemap.org elisp - +*.html +*.tex \ No newline at end of file diff --git a/src/demos/2017-11-29-demonstration-script.org b/src/demos/2017-11-29-demonstration-script.org index 73bd784..c9f6704 100644 --- a/src/demos/2017-11-29-demonstration-script.org +++ b/src/demos/2017-11-29-demonstration-script.org @@ -38,7 +38,7 @@ in. ** Disciplines - 1. Click [[http://header.vlabs.ac.in][here]] (http://header.vlabs.ac.in) to load the beta version of Virtual Labs + 1. Click [[http://beta.vlabs.ac.in][here]] ([[http://beta.vlabs.ac.in]]) to load the beta version of Virtual Labs portal. 2. The first page lists all the disciplines. 3. Click on =Aerospace Engineering= to list the labs in diff --git a/image-licensing.org b/src/image-licensing.org similarity index 100% rename from image-licensing.org rename to src/image-licensing.org diff --git a/src/runtime/authentication.org b/src/runtime/authentication.org index 269b0f3..70218be 100644 --- a/src/runtime/authentication.org +++ b/src/runtime/authentication.org @@ -27,6 +27,7 @@ var setLoginUrlInContentIframe = function(event) { } else{ iframe.src = hosted_base + "/logout"; + loadAllDisciplines(); } }; @@ -50,15 +51,15 @@ var setRegisterUrlInContentIframe = function() { event from =openedx= web-site #+NAME: post-message-event-listner #+BEGIN_SRC javascript -window.loggedin_handler = false; +window.loggedInState = false; window.bk_btn_flag = false; window.all_inst_flag = false; window.lab_url = ""; if (window.addEventListener) { - window.addEventListener("message", validatePostMessage, false); + window.addEventListener("message", processPostMessage, false); } else { - window.attachEvent("onmessage", validatePostMessage); + window.attachEvent("onmessage", processPostMessage); } #+END_SRC @@ -71,32 +72,32 @@ else { #+BEGIN_SRC javascript var validateAuthentication = function(url) { var lab_url = url.id; - var loggedinHandler = parent.window.loggedin_handler; var iframe = parent.document.getElementById("contentIframe"); - if(loggedinHandler == false){ + if(parent.window.loggedInState == false) { parent.window.lab_url = lab_url; iframe.src = hosted_base + "/login"; - } - else{ + } else { iframe.src = lab_url; } }; #+END_SRC -** Validate the cookie - This function validates the browser cookie and toggles - the login/logout buttons accordingly based on cookie - value. - - If the =session_status= of the cookie is set to - =loggedin= then =Logout= button will appear and it - hides the =Registration= button. - - If the cookie is set to =session_status=loggedout= then - =Login= and =Registration= button will be appeared -#+NAME: validate-cookie +** Toggle Login/Logout buttion + This function toggles the login/logout buttons + accordingly based on cookie value. This is required to + recreate the existing state when user accesses the + landing pages from another tab or when a post message + arrives on a successful login. + + A cookie maintains the status of the session as a key + value pair where key is =session_status= and value is + either =logged-in= or =logged-out=. + +#+NAME: toggle-log-btns #+BEGIN_SRC javascript -function validateCookie(){ - if(document.cookie.includes("logged in")){ - window.loggedin_handler=true; +function toggleBtns(){ + if(document.cookie.includes("logged-in")){ + window.loggedInState = true; var loginDiv = document.getElementById("login"); loginDiv.innerHTML = "Logout"; loginDiv.setAttribute( "onClick", "setLoginUrlInContentIframe('logout')" ); @@ -104,8 +105,8 @@ function validateCookie(){ register_elem.style.display = "none"; } - else if(document.cookie.includes("logged out")){ - window.loggedin_handler = false; + else if(document.cookie.includes("logged-out")){ + window.loggedInState = false; document.getElementById("login").innerHTML = "Login"; document.getElementById("login").setAttribute( "onClick", "setLoginUrlInContentIframe('login')" ); } @@ -115,82 +116,71 @@ function validateCookie(){ } #+END_SRC -** Validate post message - This function evaluates the post message which is being - sent from =openedx= website and sets the browser cookie - to either =session_status=logged in= or - =session_status=logged out= based on post message data. - - If post message contains sub string =MY COURSES= then - cookie sets to =session_status=logged in= - - If post message contains sub string =Welcome to the - Open= then cookie sets to =session_status=logged out= -#+NAME: validate-post-message +** Check Post message + + Post messages are sent in two scenarios: + 1. When the route =/dashboard= is accessed from Open + edX. This route is invoked on a successful login and + 2. When back button is pressed + + This function processess the post message. + + Case 1 : When the post message is from Open edX, + =session-status= of the browser cookie is set to + =logged-in= and the buttons are toggled. + + Case 2 : When the message is due to pressing of a back + button, the approprite page is loaded based the previous + state. + +#+NAME: process-post-message #+BEGIN_SRC javascript -function validatePostMessage(evt) { +function processPostMessage(evt) { + var post_msg = evt.data.toLocaleLowerCase(); - if (post_msg.indexOf("my courses") != -1){ - document.cookie = "session_status='logged in'"; - if (window.lab_url == ""){ + + if (post_msg.indexOf("my courses") != -1) { + document.cookie = "session-status='logged-in'"; + if (window.lab_url == "") { loadAllDisciplines(); } - else{ + else { var iframe = document.getElementById("contentIframe"); iframe.src = window.lab_url; } + } else { + handlePostForBackBtn(post_msg); } - else if (post_msg.indexOf("welcome to the open")!= -1){ - document.cookie = "session_status='logged out'"; - loadAllDisciplines(); - var loginDiv = document.getElementById("login"); - loginDiv.innerHTML = "Login"; - loginDiv.setAttribute( "onClick", "setLoginUrlInContentIframe('login')" ); - var register_elem = document.getElementById("register"); - register_elem.style.display = "block"; - } - else if(post_msg.indexOf("all-disciplines")!=-1 ){ - if(window.bk_btn_flag == false){ - window.bk_btn_flag = true; - console.log("==========true case======="); - console.log(window.bk_btn_flag); - } - else - { - window.bk_btn_flag = false; - console.log("==========false case======="); - console.log(window.bk_btn_flag); - loadAllDisciplines(); - } - } - else if(post_msg.indexOf("all-institutes")!=-1 ){ - if(window.bk_btn_flag == false){ - window.bk_btn_flag = true; - console.log("==========true case======="); - console.log(window.bk_btn_flag); - } - else - { - window.bk_btn_flag = false; - console.log("==========false case======="); - console.log(window.bk_btn_flag); - loadAllInstitutes(); + + toggleBtns(); + + var handlePostForBackBtn = function(postMsg) { + var toggleBackButtonFlag = function(loadF) { + if(window.bk_btn_flag == false){ + window.bk_btn_flag = true; + console.log("==========true case======="); + console.log(window.bk_btn_flag); + } + else + { + window.bk_btn_flag = false; + console.log("==========false case======="); + console.log(window.bk_btn_flag); + loadF(); + } + }; + + if(post_msg.indexOf("all-disciplines") !=-1 ) { + toggleBackButtonFlag(loadAllDisciplines); } - } - else if(post_msg.indexOf("all-labs")!=-1 ){ - if(window.bk_btn_flag == false){ - window.bk_btn_flag = true; - console.log("==========true case======="); - console.log(window.bk_btn_flag); + else if(post_msg.indexOf("all-institutes") !=-1 ) { + toggleBackButtonFlag(loadAllInstitutes); } - else - { - window.bk_btn_flag = false; - console.log("==========false case======="); - console.log(window.bk_btn_flag); - loadAllDisciplines(); + else if(post_msg.indexOf("all-labs") !=-1 ){ + toggleBackButtonFlag(loadAllDisciplines); } - } - validateCookie(); -} + }; +}; #+END_SRC ** Configure post message script inside openedx server @@ -234,6 +224,6 @@ location @proxy_to_lms_app { <> <> <> -<> -<> +<> +<> #+END_SRC From f959161237cc061180d523b2939ec141e90e475f Mon Sep 17 00:00:00 2001 From: ksripathi Date: Mon, 1 Jan 2018 11:21:44 +0530 Subject: [PATCH 2/8] tangled out toggle log btns --- src/runtime/authentication.org | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/runtime/authentication.org b/src/runtime/authentication.org index 70218be..1d7c7b9 100644 --- a/src/runtime/authentication.org +++ b/src/runtime/authentication.org @@ -209,10 +209,23 @@ server name where all post messages will be sent. Configure the =nginx= server file in =/etc/nginx/sites-enabled/lms= to sent post messages script #+BEGIN_EXAMPLE -location @proxy_to_lms_app { - add_after_body /server/message.html; - -------------- - ------------- + +-------- +-------- + location @append_and_proxy_to_lms_app { + add_after_body /server/message.html; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Port $server_port; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header Host $http_host; + + proxy_redirect off; + proxy_pass http://lms-backend; + } + location /dashboard { + try_files $uri @append_and_proxy_to_lms_app; + } +-------------- #+END_EXAMPLE * Tangle @@ -224,6 +237,6 @@ location @proxy_to_lms_app { <> <> <> -<> +<> <> #+END_SRC From 9ab7139701842f9e952e816309e0144378f4b280 Mon Sep 17 00:00:00 2001 From: Thirumal Ravula Date: Tue, 2 Jan 2018 10:42:54 +0530 Subject: [PATCH 3/8] right template included --- src/deployment/setup-dev-environment.org | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/deployment/setup-dev-environment.org b/src/deployment/setup-dev-environment.org index b459bad..35c23a4 100644 --- a/src/deployment/setup-dev-environment.org +++ b/src/deployment/setup-dev-environment.org @@ -1,7 +1,7 @@ #+TITLE: Setup Vlabs Landing Pages in Dev Environment #+AUTHOR: VLEAD #+DATE: [2017-12-21 Mon] -#+SETUPFILE: ./org-templates/level-0.org +#+SETUPFILE: ../org-templates/level-1.org #+TAGS: boilerplate(b) #+EXCLUDE_TAGS: boilerplate #+OPTIONS: ^:nil From aff1d25576e97d032f6f0b21db810893ec2b5258 Mon Sep 17 00:00:00 2001 From: ksripathi Date: Tue, 2 Jan 2018 10:54:19 +0530 Subject: [PATCH 4/8] added function togglebtn() to onpageshow for landing pages --- src/runtime/html.org | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/html.org b/src/runtime/html.org index 15f0e69..f447c3f 100644 --- a/src/runtime/html.org +++ b/src/runtime/html.org @@ -45,7 +45,7 @@ Virtual Labs - +