From bba9cd515b8a4fe601c20a3a09e33a3712253111 Mon Sep 17 00:00:00 2001 From: John McLear Date: Sat, 13 Aug 2011 19:53:02 +0100 Subject: [PATCH] Added support for changing username from the URL ie ?userName=JohnMcLear -- doesnt urldecode etc. needs checking for vulnerabilities too --- static/js/pad2.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/static/js/pad2.js b/static/js/pad2.js index 5705218d..1fe56b12 100644 --- a/static/js/pad2.js +++ b/static/js/pad2.js @@ -18,6 +18,7 @@ var socket; var LineNumbersDisabled = false; +var globalUserName = false; $(document).ready(function() { @@ -97,10 +98,15 @@ function getParams() { if(showLineNumbers == "false") { - // pad.changeViewOption('showLineNumbers', false); LineNumbersDisabled = true; } } + + if(userName) + { + // If the username is set as a parameter we should set a global value that we can call once we have initiated the pad. + globalUserName = userName; + } } function getUrlVars() @@ -170,10 +176,20 @@ function handshake() pad.init(); initalized = true; + + // If the LineNumbersDisabled value is set to true then we need to hide the Line Numbers if (LineNumbersDisabled == true) { - pad.changeViewOption('showLineNumbers', false); $ + pad.changeViewOption('showLineNumbers', false); } + + // 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