From c75b3d2f31e7af90bc612fed8f0c2fa2e8f7347c Mon Sep 17 00:00:00 2001 From: Daniel Howard Date: Fri, 12 Sep 2014 14:31:46 -0700 Subject: [PATCH] Store sessionid in store instead of in cookies. --- client/js/cookies.js | 48 -------------------------------------------- client/js/im.js | 9 +++++++-- 2 files changed, 7 insertions(+), 50 deletions(-) delete mode 100644 client/js/cookies.js diff --git a/client/js/cookies.js b/client/js/cookies.js deleted file mode 100644 index 20f613d..0000000 --- a/client/js/cookies.js +++ /dev/null @@ -1,48 +0,0 @@ -// Cookies API -var cookies = { - // === {{{AjaxIM.}}}**{{{cookies.set(name, value, days)}}}** === - // - // Sets a cookie, stringifying the JSON value upon storing it. - // - // ==== Parameters ==== - // * {{{name}}} is the cookie name.\\ - // * {{{value}}} is the cookie data that you would like to store.\\ - // * {{{days}}} is the number of days that the cookie will be stored for. - set: function(name, value, days) { - if (days) { - var date = new Date(); - date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); - var expires = "; expires=" + date.toGMTString(); - } else var expires = ""; - document.cookie = name + "=" + JSON.stringify(value) + expires + "; path=/"; - }, - - // === {{{AjaxIM.}}}**{{{cookies.get(name)}}}** === - // - // Gets a cookie, decoding the JSON value before returning the data. - // - // ==== Parameters ==== - // * {{{name}}} is the cookie name that you would like to retrieve. - get: function(name) { - var nameEQ = name + "="; - var ca = document.cookie.split(';'); - for(var i = 0; i < ca.length; i++) { - var c = ca[i]; - while (c.charAt(0) == ' ') c = c.substring(1, c.length); - if (c.indexOf(nameEQ) == 0) { - var cval = decodeURIComponent(c.substring(nameEQ.length, c.length)); - try { return JSON.parse(cval); } catch (e) { return cval; } - } - } - return null; - }, - - // === {{{AjaxIM.}}}**{{{cookies.erase(name)}}}** === - // - // Deletes a cookie. - // - // {{{name}}} is the existing cookie that you would like to delete. - erase: function(name) { - this.set(name, '', -1); - } -}; diff --git a/client/js/im.js b/client/js/im.js index cfe8d93..d5d1767 100644 --- a/client/js/im.js +++ b/client/js/im.js @@ -54,6 +54,10 @@ AjaxIM = function(options, actions) { signoff: this.settings.pollServer + '/app/signoff' }, actions); + if (!store.get('sessionid')) { + store.set('sessionid', uid(40)); + } + // If Socket.IO is available, create a socket self.socket = null; $.getScript(this.settings.pollServer+'/socket.io/socket.io.js', function(){ @@ -62,7 +66,7 @@ AjaxIM = function(options, actions) { event = $.extend(true, {}, event); self.dispatchEvent(event); }); - var event = {type: 'hello', from: this.username, sessionID: cookies.get('sessionid')}; + var event = {type: 'hello', from: store.get('user'), sessionID: store.get('sessionid')}; self.sendEvent(event); }); @@ -1502,7 +1506,7 @@ AjaxIM.request = function(url, type, data, successFunc, failureFunc, noopurl) { var jsonp = (url.substring(0, 1) !== '/'); var success = false; - data['sessionid'] = cookies.get('sessionid'); + data['sessionid'] = store.get('sessionid'); $.ajax({ url: url, data: data, @@ -1532,6 +1536,7 @@ AjaxIM.request = function(url, type, data, successFunc, failureFunc, noopurl) { var noopfn = function() { var noopdone = false; var event = {type: 'noop'}; + event['sessionid'] = store.get('sessionid'); $.ajax({ url: noopurl, data: event,