From 39329dba3a80976d1de80112da36558b8253ab5c Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Tue, 17 Jul 2012 15:55:36 -0400 Subject: [PATCH] Almost fixed saved session management --- lib/app/index.js | 13 +++++++------ src/app/index.coffee | 26 +++++++++++--------------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/lib/app/index.js b/lib/app/index.js index 83f5556739..fb75b5412a 100644 --- a/lib/app/index.js +++ b/lib/app/index.js @@ -84,12 +84,13 @@ get('/:userId?', function(page, model, _arg) { var userId; userId = _arg.userId; return model.subscribe("users", function(err, users) { - var guid, newUser, task, user, _i, _len, _ref1; + var debuggingUsers, guid, newUser, task, user, _i, _len, _ref1; + debuggingUsers = parseInt(userId) < 40; + if ((userId != null) && (users.get(userId) || debuggingUsers)) { + model.set('_userId', userId); + } userId = model.get('_userId'); - debug(userId, 'model.get _userId'); - if (model.get("users." + userId)) { - debug(userId, 'model.get userId'); - } else { + if (!model.get("users." + userId)) { newUser = { stats: { money: 0, @@ -156,7 +157,7 @@ get('/:userId?', function(page, model, _arg) { ready(function(model) { var endOfDayTally, expModifier, hpModifier, poormanscron, setupSortable, step, tour, type, updateStats, _i, _j, _len, _len1, _ref1, _ref2; - model.set('_purl', window.location.origin + '/' + model.get('_user.id')); + model.set('_purl', window.location.origin + '/' + model.get('_userId')); $('[rel=popover]').popover(); model.on('set', '*', function() { return $('[rel=popover]').popover(); diff --git a/src/app/index.coffee b/src/app/index.coffee index 035dfeeff7..97e3a8bc38 100644 --- a/src/app/index.coffee +++ b/src/app/index.coffee @@ -48,24 +48,20 @@ debug = (obj, message) -> console.log obj, "[debug] #{message}" get '/:userId?', (page, model, {userId}) -> - # # Saved session - # # TODO: this doesn't check that the user at guid exists, and - # # will probably error since no user is created. Will only happen if - # # first access, but still. model.get(userId) and model.get("users.#{userId}") aren't - # # working for some reason - # debuggingUsers = (parseInt(userId) < 40) #these are users created before guid was in use, need to convert them to guid and get rid of this - # if userId? and (Guid.isGuid(userId) or debuggingUsers)# and model.get(userId)? - # model.set '_userId', userId - # return getRoom page, model, userId model.subscribe "users", (err, users) -> + + # Previously saved session (eg, http://localhost/{guid}) (temporary solution until authentication built) + debuggingUsers = (parseInt(userId) < 40) #these are users created before guid was in use, need to convert them to guid and get rid of this + if userId? and (users.get(userId) or debuggingUsers) + model.set '_userId', userId + + # Current browser session # The session middleware will assign a _userId automatically # Render page if a userId is already stored in session data - userId = model.get '_userId' - debug userId, 'model.get _userId' - if model.get "users.#{userId}" - debug userId, 'model.get userId' - else + userId = model.get '_userId' + + unless model.get "users.#{userId}" # Otherwise, select a new userId and initialize user newUser = { stats: { money: 0, exp: 0, lvl: 1, hp: 50 } @@ -108,7 +104,7 @@ get '/:userId?', (page, model, {userId}) -> ready (model) -> - model.set '_purl', window.location.origin + '/' + model.get('_user.id') + model.set '_purl', window.location.origin + '/' + model.get('_userId') $('[rel=popover]').popover() #TODO: this isn't very efficient, do model.on set for specific attrs for popover