mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
Test userObj on server route, attempt to fixing crashing server
This commit is contained in:
@@ -179,16 +179,6 @@ score = function(taskId, direction, options) {
|
||||
_ref = [model.at(taskPath), model.get(taskPath)], task = _ref[0], taskObj = _ref[1];
|
||||
type = taskObj.type, value = taskObj.value;
|
||||
userObj = user.get();
|
||||
if (_.isEmpty(userObj) || _.isEmpty(userObj.stats) || _.isEmpty(userObj.tasks)) {
|
||||
console.log({
|
||||
taskId: taskId,
|
||||
direction: direction,
|
||||
options: options,
|
||||
user: userObj,
|
||||
error: 'non-user attempted to score'
|
||||
});
|
||||
return 0;
|
||||
}
|
||||
if (!task) {
|
||||
_ref1 = userObj.stats, money = _ref1.money, hp = _ref1.hp, exp = _ref1.exp;
|
||||
if (direction === "up") {
|
||||
|
||||
@@ -35,11 +35,20 @@ module.exports = function(expressApp, root, derby) {
|
||||
model = req.getModel();
|
||||
model.session.userId = uid;
|
||||
return model.fetch("users." + uid, function(err, user) {
|
||||
var delta, result;
|
||||
if (err || _.isEmpty(user.get())) {
|
||||
err || (err = 'No user with that ID');
|
||||
var delta, result, userObj;
|
||||
if (err) {
|
||||
return res.send(500, err);
|
||||
}
|
||||
userObj = user.get();
|
||||
if (!(userObj && userObj.stats && userObj.stats.money && !_.isEmpty(userObj.tasks))) {
|
||||
console.log({
|
||||
taskId: taskId,
|
||||
direction: direction,
|
||||
user: userObj,
|
||||
error: 'non-user attempted to score'
|
||||
});
|
||||
return res.send(500, "User " + uid + " not found");
|
||||
}
|
||||
model.ref('_user', user);
|
||||
if (!model.get("_user.tasks." + taskId)) {
|
||||
model.refList("_habitList", "_user.tasks", "_user.habitIds");
|
||||
|
||||
@@ -140,12 +140,6 @@ score = (taskId, direction, options={cron:false, times:1}) ->
|
||||
{type, value} = taskObj
|
||||
userObj = user.get()
|
||||
|
||||
# FIXME seem to be finding issues here
|
||||
if _.isEmpty(userObj) || _.isEmpty(userObj.stats) || _.isEmpty(userObj.tasks)
|
||||
console.log {taskId:taskId, direction:direction, options:options, user:userObj, error: 'non-user attempted to score'}
|
||||
return 0
|
||||
|
||||
|
||||
# up / down was called by itself, probably as REST from 3rd party service
|
||||
#FIXME handle this
|
||||
if !task
|
||||
|
||||
@@ -30,9 +30,13 @@ module.exports = (expressApp, root, derby) ->
|
||||
model = req.getModel()
|
||||
model.session.userId = uid
|
||||
model.fetch "users.#{uid}", (err, user) ->
|
||||
if err || _.isEmpty(user.get())
|
||||
err ||= 'No user with that ID'
|
||||
return res.send(500, err)
|
||||
return res.send(500, err) if err
|
||||
userObj = user.get()
|
||||
#FIXME The server keeps crashing. I think it's because some users are entering non-guids as their userId, test that here
|
||||
unless userObj && userObj.stats && userObj.stats.money && !_.isEmpty(userObj.tasks)
|
||||
console.log {taskId:taskId, direction:direction, user:userObj, error: 'non-user attempted to score'}
|
||||
return res.send(500, "User #{uid} not found")
|
||||
|
||||
model.ref('_user', user)
|
||||
|
||||
# Create task if doesn't exist
|
||||
|
||||
Reference in New Issue
Block a user