hallway.del('/profiles', function (req, res) { logger.info("DELETE account", req._authsome); acl.delProfiles(req._authsome.account, function (err) { if (err) logger.error(err); anubis.log(req); res.json({success: true}); }); });
hallway.post('/profiles', function (req, res) { var account = req._authsome.account; if (!account) { return res.jsonErr('That account does not exist.', 404); } if (!req.param('delete')) { return res.json(lutil.jsonErr('A "delete" parameter is required.', { see: "https://singly.com/docs/profiles#Deleting-Profiles" }), 400); } if (req.param('delete') === account) { acl.delProfiles(account, function (err) { if (err) logger.error(err); anubis.log(req); // def clear the session cookie too so the old id doesn't stick around res.clearCookie('account-' + req._authsome.app); res.json(!err); }); } else { var profileID = req.param('delete'); var lastAt = profileID.lastIndexOf('@'); // split out the service name and the profile id if (lastAt > -1) { var service = profileID.substring(lastAt); var id = profileID.substring(0, lastAt); // the profile id is uri encoded in the DB // first we decode it in case it was copied in it's encoded form id = decodeURIComponent(id); // then we encode it to match id = encodeURIComponent(id); profileID = id + service; } acl.getProfile(account, profileID, function (err, profile) { if (err) logger.error(err); if (!profile) { return res.jsonErr('That profile is not connected.', 404); } logger.info("deleting account profiles for " + account, profileID, req._authsome.profiles ); acl.delProfile(account, profileID, function (err) { if (err) logger.error(err); anubis.log(req); res.json(!err); }); }); } });
}, function(){ acl.delProfiles(source.account, done); });