salix/@salix-services/account/server/boot/routes.js

33 lines
778 B
JavaScript
Raw Normal View History

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