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];
|
_ref = [model.at(taskPath), model.get(taskPath)], task = _ref[0], taskObj = _ref[1];
|
||||||
type = taskObj.type, value = taskObj.value;
|
type = taskObj.type, value = taskObj.value;
|
||||||
userObj = user.get();
|
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) {
|
if (!task) {
|
||||||
_ref1 = userObj.stats, money = _ref1.money, hp = _ref1.hp, exp = _ref1.exp;
|
_ref1 = userObj.stats, money = _ref1.money, hp = _ref1.hp, exp = _ref1.exp;
|
||||||
if (direction === "up") {
|
if (direction === "up") {
|
||||||
|
|||||||
@@ -35,11 +35,20 @@ module.exports = function(expressApp, root, derby) {
|
|||||||
model = req.getModel();
|
model = req.getModel();
|
||||||
model.session.userId = uid;
|
model.session.userId = uid;
|
||||||
return model.fetch("users." + uid, function(err, user) {
|
return model.fetch("users." + uid, function(err, user) {
|
||||||
var delta, result;
|
var delta, result, userObj;
|
||||||
if (err || _.isEmpty(user.get())) {
|
if (err) {
|
||||||
err || (err = 'No user with that ID');
|
|
||||||
return res.send(500, 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);
|
model.ref('_user', user);
|
||||||
if (!model.get("_user.tasks." + taskId)) {
|
if (!model.get("_user.tasks." + taskId)) {
|
||||||
model.refList("_habitList", "_user.tasks", "_user.habitIds");
|
model.refList("_habitList", "_user.tasks", "_user.habitIds");
|
||||||
|
|||||||
@@ -140,12 +140,6 @@ score = (taskId, direction, options={cron:false, times:1}) ->
|
|||||||
{type, value} = taskObj
|
{type, value} = taskObj
|
||||||
userObj = user.get()
|
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
|
# up / down was called by itself, probably as REST from 3rd party service
|
||||||
#FIXME handle this
|
#FIXME handle this
|
||||||
if !task
|
if !task
|
||||||
|
|||||||
@@ -30,9 +30,13 @@ module.exports = (expressApp, root, derby) ->
|
|||||||
model = req.getModel()
|
model = req.getModel()
|
||||||
model.session.userId = uid
|
model.session.userId = uid
|
||||||
model.fetch "users.#{uid}", (err, user) ->
|
model.fetch "users.#{uid}", (err, user) ->
|
||||||
if err || _.isEmpty(user.get())
|
return res.send(500, err) if err
|
||||||
err ||= 'No user with that ID'
|
userObj = user.get()
|
||||||
return res.send(500, err)
|
#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)
|
model.ref('_user', user)
|
||||||
|
|
||||||
# Create task if doesn't exist
|
# Create task if doesn't exist
|
||||||
|
|||||||
Reference in New Issue
Block a user