Skip to content

Commit

Permalink
Merge branch 'refactor' of https://github.com/vlead/vlabs-landing-pages
Browse files Browse the repository at this point in the history
… into develop
  • Loading branch information
ksripathi committed Jan 3, 2018
2 parents 335cc78 + 8ee5f39 commit f616d55
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 137 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ lint_output
literate-tools
src/sitemap.org
elisp

*.html
*.tex
config.org
2 changes: 1 addition & 1 deletion scripts/labspec.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"configure": [],
"pre_build": [],
"build": [
"cd ../;make build"
"cd ../;cp src/runtime/config.org.sample src/runtime/config.org;make build"
],
"post_build": [
"rm /var/www/html/index.html",
Expand Down
2 changes: 1 addition & 1 deletion src/demos/2017-11-29-demonstration-script.org
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 6 additions & 10 deletions src/deployment/setup-dev-environment.org
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -72,9 +72,10 @@
#+BEGIN_EXAMPLE
git clone https://github.com/vlead/vlabs-landing-pages.git
#+END_EXAMPLE
10. Checkout to =refactor= branch and build the sources
10. Checkout to =develop= branch and build the sources
#+BEGIN_EXAMPLE
git checkout refactor
cd vlabs-landing-pages
git checkout develop
make
#+END_EXAMPLE
11. Remove the default =index.html= from =/var/www/html/=
Expand All @@ -86,8 +87,7 @@
#+BEGIN_EXAMPLE
cd /var/www/html/
#+END_EXAMPLE
14. Configure =document.domain= value to =vlabs.ac.in= and
post message url to =http://pages.vlabs.ac.in= in
14. Configure =document.domain= value to =vlabs.ac.in= in
=disciplines.html=, =institutes.html= and =labs.html=
files
#+BEGIN_EXAMPLE
Expand All @@ -96,9 +96,6 @@
document.domain="vlabs.ac.in"
--------
-------
msg = window.parent.postMessage("all-disciplines", "http://pages.vlabs.ac.in");
------
------

#+END_EXAMPLE
15. Configure the following variables in
Expand All @@ -110,7 +107,7 @@

3. lds_url = "http://alpha-lds.vlabs.ac.in"

16. Restart the =apache= servier
16. Restart the =apache2= server
#+BEGIN_EXAMPLE
service apache2 restart
#+END_EXAMPLE
Expand All @@ -125,7 +122,6 @@
---------
---------
192.168.33.20 alpha.vlabs.ac.in
192.168.33.21 alpha-lds.vlabs.ac.in
192.168.33.22 alpha-openedx.vlabs.ac.in
#+END_EXAMPLE
2. Access vlabs-landig-page on base machine's browser
Expand Down
File renamed without changes.
210 changes: 109 additions & 101 deletions src/runtime/authentication.org
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
=vlabs-landing-pages=
* Authentication
** Set Login url to content iframe
By default on page loads =contentIframe= is set to load
all the disciplines. This is to be replaced with login
url of the OpenEdx when user clicks on =Login= button
from the header division
When =Login= button is clicked, the content iframe is set
to the login page of Open edX.

When =Logout= button is clicked, the content iframe is
loaded with all disciplines, toggles the button to
=login= and makes a call to Open edX to the =/logout=
#+NAME: set-login-url-to-content-iframe
#+BEGIN_SRC javascript
var setLoginUrlInContentIframe = function(event) {
Expand All @@ -25,8 +27,11 @@ var setLoginUrlInContentIframe = function(event) {
if(event == "login"){
iframe.src = hosted_base + "/login";
}
else{
else {
document.cookie = "session-status='logged-out'";
iframe.src = hosted_base + "/logout";
toggleBtns();
loadAllDisciplines();
}
};

Expand All @@ -50,15 +55,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
Expand All @@ -71,126 +76,116 @@ 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')" );
var register_elem = document.getElementById("register");
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')" );
var register_elem = document.getElementById("register");
register_elem.style.display = "block";
}
else{
console.log("");
}
}

#+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) {
var post_msg = evt.data.toLocaleLowerCase();
if (post_msg.indexOf("my courses") != -1){
document.cookie = "session_status='logged in'";
if (window.lab_url == ""){
loadAllDisciplines();
function processPostMessage(evt) {
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{
var iframe = document.getElementById("contentIframe");
iframe.src = window.lab_url;
else if(post_msg.indexOf("all-institutes") !=-1 ) {
toggleBackButtonFlag(loadAllInstitutes);
}
}
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 if(post_msg.indexOf("all-labs") !=-1 ){
toggleBackButtonFlag(loadAllDisciplines);
}
else
{
window.bk_btn_flag = false;
console.log("==========false case=======");
console.log(window.bk_btn_flag);
};

var post_msg = evt.data.toLocaleLowerCase();

if (post_msg.indexOf("my courses") != -1) {
document.cookie = "session-status='logged-in'";
if (window.lab_url == "") {
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();
}
}
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
{
window.bk_btn_flag = false;
console.log("==========false case=======");
console.log(window.bk_btn_flag);
loadAllDisciplines();
else {
var iframe = document.getElementById("contentIframe");
iframe.src = window.lab_url;
}
} else {
handlePostForBackBtn(post_msg);
}
validateCookie();
}

toggleBtns();
};

#+END_SRC
** Configure post message script inside openedx server
Expand Down Expand Up @@ -219,10 +214,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
Expand All @@ -234,6 +242,6 @@ location @proxy_to_lms_app {
<<set-register-url-to-content-iframe>>
<<set-login-url-to-content-iframe>>
<<validate-authentication>>
<<validate-cookie>>
<<validate-post-message>>
<<toggle-log-btns>>
<<process-post-message>>
#+END_SRC
File renamed without changes.
Loading

0 comments on commit f616d55

Please sign in to comment.