From 48980f9e196d4b1bb2bf1ddba2918bda2f2e5b7a Mon Sep 17 00:00:00 2001 From: Peter 'Pita' Martischka Date: Mon, 15 Aug 2011 18:26:20 +0100 Subject: [PATCH] Show permission messages on the browser side --- node/handler/PadMessageHandler.js | 2 +- static/js/pad2.js | 49 ++++++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/node/handler/PadMessageHandler.js b/node/handler/PadMessageHandler.js index 846c1973..3b032314 100644 --- a/node/handler/PadMessageHandler.js +++ b/node/handler/PadMessageHandler.js @@ -602,7 +602,7 @@ function handleClientReady(client, message) //no access, send the client a message that tell him why else { - client.send({accessStatus: statusObject.accessStatus}) + client.json.send({accessStatus: statusObject.accessStatus}) } }); }, diff --git a/static/js/pad2.js b/static/js/pad2.js index a72f6729..5ebe6ae0 100644 --- a/static/js/pad2.js +++ b/static/js/pad2.js @@ -34,7 +34,7 @@ $(window).unload(function() pad.dispose(); }); -function createCookie(name, value, days) +function createCookie(name, value, days, path) { if (days) { @@ -43,7 +43,11 @@ function createCookie(name, value, days) var expires = "; expires=" + date.toGMTString(); } else var expires = ""; - document.cookie = name + "=" + value + expires + "; path=/"; + + if(!path) + path = "/"; + + document.cookie = name + "=" + value + expires + "; path=" + path; } function readCookie(name) @@ -133,6 +137,14 @@ function getUrlVars() return vars; } +function savePassword() +{ + //set the password cookie + createCookie("password",$("#passwordinput").val(),null,document.location.pathname); + //reload + document.location=document.location; +} + function handshake() { var loc = document.location; @@ -162,12 +174,14 @@ function handshake() } var sessionID = readCookie("sessionID"); + var password = readCookie("password"); var msg = { "component": "pad", "type": "CLIENT_READY", "padId": padId, "sessionID": sessionID, + "password": password, "token": token, "protocolVersion": 2 }; @@ -179,17 +193,41 @@ function handshake() socket.on('message', function(obj) { - //if we haven't recieved the clientVars yet, then this message should it be - if (!receivedClientVars) + //the access was not granted, give the user a message + if(!receivedClientVars && obj.accessStatus) { + if(obj.accessStatus == "deny") + { + $("#editorloadingbox").html("You have no permission to access this pad"); + } + else if(obj.accessStatus == "needPassword") + { + $("#editorloadingbox").html("You need a password to access this pad
" + + ""+ + ""); + } + else if(obj.accessStatus == "wrongPassword") + { + $("#editorloadingbox").html("You're password was wrong
" + + ""+ + ""); + } + } + + //if we haven't recieved the clientVars yet, then this message should it be + else if (!receivedClientVars) + { + //log the message if (window.console) console.log(obj); receivedClientVars = true; + //set some client vars clientVars = obj; clientVars.userAgent = "Anonymous"; clientVars.collab_client_vars.clientAgent = "Anonymous"; + //initalize the pad pad.init(); initalized = true; @@ -198,20 +236,17 @@ function handshake() { pad.changeViewOption('showLineNumbers', false); } - // If the Monospacefont value is set to true then change it to monospace. if (useMonospaceFontGlobal == true) { pad.changeViewOption('useMonospaceFont', true); } - // if the globalUserName value is set we need to tell the server and the client about the new authorname if (globalUserName !== false) { pad.notifyChangeName(globalUserName); // Notifies the server $('#myusernameedit').attr({"value":globalUserName}); // Updates the current users UI } - } //This handles every Message after the clientVars else