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;
|
var userId;
|
||||||
userId = _arg.userId;
|
userId = _arg.userId;
|
||||||
return model.subscribe("users", function(err, users) {
|
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');
|
userId = model.get('_userId');
|
||||||
debug(userId, 'model.get _userId');
|
if (!model.get("users." + userId)) {
|
||||||
if (model.get("users." + userId)) {
|
|
||||||
debug(userId, 'model.get userId');
|
|
||||||
} else {
|
|
||||||
newUser = {
|
newUser = {
|
||||||
stats: {
|
stats: {
|
||||||
money: 0,
|
money: 0,
|
||||||
@@ -156,7 +157,7 @@ get('/:userId?', function(page, model, _arg) {
|
|||||||
|
|
||||||
ready(function(model) {
|
ready(function(model) {
|
||||||
var endOfDayTally, expModifier, hpModifier, poormanscron, setupSortable, step, tour, type, updateStats, _i, _j, _len, _len1, _ref1, _ref2;
|
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();
|
$('[rel=popover]').popover();
|
||||||
model.on('set', '*', function() {
|
model.on('set', '*', function() {
|
||||||
return $('[rel=popover]').popover();
|
return $('[rel=popover]').popover();
|
||||||
|
|||||||
@@ -48,24 +48,20 @@ debug = (obj, message) ->
|
|||||||
console.log obj, "[debug] #{message}"
|
console.log obj, "[debug] #{message}"
|
||||||
|
|
||||||
get '/:userId?', (page, model, {userId}) ->
|
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) ->
|
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
|
# The session middleware will assign a _userId automatically
|
||||||
# Render page if a userId is already stored in session data
|
# Render page if a userId is already stored in session data
|
||||||
userId = model.get '_userId'
|
userId = model.get '_userId'
|
||||||
debug userId, 'model.get _userId'
|
|
||||||
if model.get "users.#{userId}"
|
unless model.get "users.#{userId}"
|
||||||
debug userId, 'model.get userId'
|
|
||||||
else
|
|
||||||
# Otherwise, select a new userId and initialize user
|
# Otherwise, select a new userId and initialize user
|
||||||
newUser = {
|
newUser = {
|
||||||
stats: { money: 0, exp: 0, lvl: 1, hp: 50 }
|
stats: { money: 0, exp: 0, lvl: 1, hp: 50 }
|
||||||
@@ -108,7 +104,7 @@ get '/:userId?', (page, model, {userId}) ->
|
|||||||
|
|
||||||
ready (model) ->
|
ready (model) ->
|
||||||
|
|
||||||
model.set '_purl', window.location.origin + '/' + model.get('_user.id')
|
model.set '_purl', window.location.origin + '/' + model.get('_userId')
|
||||||
|
|
||||||
$('[rel=popover]').popover()
|
$('[rel=popover]').popover()
|
||||||
#TODO: this isn't very efficient, do model.on set for specific attrs for popover
|
#TODO: this isn't very efficient, do model.on set for specific attrs for popover
|
||||||
|
|||||||
Reference in New Issue
Block a user