var url = require ('url'); module.exports = function(app) { var User = app.models.User; var applications = app.get('applications'); var queryObject; app.post('/', function(req, res) { User.login({ email: req.body.email, password: req.body.password }, 'user', function(err, token) { if (err) { res.status (401); res.send(JSON.stringify({ title: 'Login failed', content: err, redirectTo: '/', redirectToLinkText: 'Try again' })); } else { queryObject = url.parse (req.body.appId,true).query; res.send(JSON.stringify({ location: applications[queryObject.api_key], accessToken: token.id })); } }); }); }; require('q');