Exemplo n.º 1
0
api.unlock = function(req, res) {
  var user = res.locals.user;
  var path = req.query.path;
  var fullSet = ~path.indexOf(',');

  // 5G per set, 2G per individual
  cost = fullSet ? 1.25 : 0.5;

  if (user.balance < cost)
    return res.json(401, {err: 'Not enough gems'});

  if (fullSet) {
    var paths = path.split(',');
    _.each(paths, function(p){
      helpers.dotSet('purchased.' + p, true, user);
    });
  } else {
    if (helpers.dotGet('purchased.' + path, user) === true)
      return res.json(401, {err: 'User already purchased that'});
    helpers.dotSet('purchased.' + path, true, user);
  }

  user.balance -= cost;
  user._v++;
  user.markModified('purchased');
  user.save(function(err, saved){
    if (err) res.json(500, {err:err});
    res.send(200);
  })
}
Exemplo n.º 2
0
  _.each(req.body, function(v, k) {
    var found = _.find(acceptableAttrs, function(attr) { return k.indexOf(attr) == 0; })
    if (found) {
//      if (_.isObject(v)) {
//        errors.push("Value for " + k + " was an object. Be careful here, you could clobber stuff.");
//      }
      helpers.dotSet(k, v, user);
    } else {
      errors.push("path `" + k + "` was not saved, as it's a protected path. Make sure to send `PUT /api/v1/user` request bodies as `{'set.this.path':value}` instead of `{set:{this:{path:value}}}`");
    }
    return true;
  });
Exemplo n.º 3
0
 _.each(paths, function(p){
   helpers.dotSet('purchased.' + p, true, user);
 });