Example #1
0
  async.forEach(profiles, function (item, cb) {
    // Skip any that don't look right
    if (!item.profile || item.profile.indexOf('@') === -1) {
      return process.nextTick(cb);
    }

    var parts = item.profile.split('@');
    if (!ret[parts[1]]) ret[parts[1]] = [];
    if (!lutil.isTrue(req.query.data) && !lutil.isTrue(req.query.verify)) {
      ret[parts[1]].push(parts[0]);
      return process.nextTick(cb);
    }
    profileManager.authGetAcct(item.profile, req._authsome.app, req._authsome.account, function (err, auth) {
      // handling err further below (and profileManager logs a warning for us)
      if (!lutil.isTrue(req.query.verify)) {
        if (auth) ret[parts[1]].push(auth.profile);
        return cb();
      }
      // if verified, run self synclet!
      var self;
      var wrapper = {id: parts[0]};
      // changes format to wrapper object so it can be validated
      ret[parts[1]].push(wrapper);
      if (!auth) {
        wrapper.error = err;
        return cb();
      }
      try {
        self = require(path.join('services', parts[1], 'self.js'));
      } catch (E) {
        // services w/o synclet are custom/internal ones and just skip this
        wrapper.profile = auth.profile;
        return cb();
      }
      logger.info("running verification self for ", item.profile);
      self.sync({auth: auth, config: {}}, function (err, data) {
        if (!err && (!data || !data.auth)) {
          err = "no error and no profile data returned, empty response";
        }
        if (err) {
          wrapper.error = err;
        } else {
          wrapper.profile = data.auth.profile;
        }
        cb();
      });
    });
  }, function (err) {
Example #2
0
exports.options = function(query, path)
{
  var options = {};
  if(!query) return options;

  // normalize the selective options
  options.since = parseInt(query['since']) || undefined;
  options.until = parseInt(query['until']) || undefined;
  options.limit = parseInt(query['limit']) || 20;
  options.q = query.q;
  if(query.participants) options.participants = query.participants.split(",");
  options.dedup = lutil.isTrue(query.dedup);

  // legacy, to be deleted when unused or v1
  if(query.min_count) options.limit = parseInt(query.min_count);
  if(query.max_count) options.limit = parseInt(query.max_count);

  // sanity checks
  if(options.limit < 0) options.limit = 20;

  // near=lat,lng&within=X
  if(query.near)
  {
    var ll = query.near.split(",");
    var lat = parseFloat(ll[0]);
    var lng = parseFloat(ll[1]);
    var within = parseFloat(query.within||10); // kilometers
    if(typeof within != 'number' || isNaN(within) || typeof lat != 'number' || isNaN(lat) || typeof lng != 'number' || isNaN(lng) ) {
      logger.warn("invalid near/within",query.near,within)
    }else{
      var diff = (Math.asin(Math.sin((within / 6371) / 2)) * 2) / Math.PI * 180; // radians, bounding box
      options.box = {lat:[lat+diff, lat-diff], lng:[lng+diff, lng-diff]};
      options.box.lat.sort(function(a,b){return a-b});
      options.box.lng.sort(function(a,b){return a-b});
    }
  }

  // normalize the response options
  options.map = lutil.isTrue(query.map);
  options.fields = query.fields;
  options.select = query.select;

  // optionally extract the desired type from the path
  if(path && path.indexOf('?') >= 0) path = path.substr(0,path.indexOf('?'));
  if(path && path.split('/')[1] == 'types') options.type = path.split('/')[2];

  return options;
}
Example #3
0
hallway.get('/profile', function (req, res) {
  res.increment('profile');

  var options = {
    app: req._authsome.app,
    account: req._authsome.account,
    auth: lutil.isTrue(req.query.auth),
    fresh: lutil.isTrue(req.query.fresh),
    full: lutil.isTrue(req.query.full)
  };

  profileManager.genProfile(req._authsome.profiles, options,
    function (err, ret) {
    if (err) return res.jsonErr(err);
    res.json(ret);
    anubis.log(req, { count: 1 });
  });
});
Example #4
0
      acl.getProfiles(account, function (err, profiles) {
        profiles = profiles || {};
        var options = {};
        options.app = app.app;
        options.account = account;
        options.auth = lutil.isTrue(req.param('auth'));
        options.full = lutil.isTrue(req.param('full'));

        // only use the last pid if requested
        if (profile === 'last') {
          var good = [];
          profiles.forEach(function (x) {
            if (x.profile === grant.pid) good.push(x);
          });
          profiles = good;
        }

        profileManager.genProfile(profiles, options, function (err, ret) {
          end(null, { profile: ret });
        });
      });
Example #5
0
 it('should return true if "true"', function () {
   assert.isTrue(lutil.isTrue("true"));
 });
Example #6
0
 it('should return true if true', function() {
   assert.isTrue(lutil.isTrue(true));
 });
Example #7
0
 it('should return false if "string"', function() {
   assert.isFalse(lutil.isTrue("string"));
 });
Example #8
0
 it('should return false if 0', function() {
   assert.isFalse(lutil.isTrue(0));
 });
Example #9
0
 it('should return true if 1', function() {
   assert.isTrue(lutil.isTrue(1));
 });