mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
Almost fixed saved session management
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user