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

28 lines
637 B
JavaScript
Raw Normal View History

2016-11-08 08:07:39 +00:00
module.exports = function(app) {
var User = app.models.User;
app.get('/login',(req,res)=>{
res.render('index.ejs',{});
});
app.post('/login', function(req, res) {
User.login({
email: req.body.email,
password: req.body.password
}, 'user', function(err, token) {
if (err) {
res.send(JSON.stringify({
title: 'Login failed',
content: err,
redirectTo: '/',
redirectToLinkText: 'Try again'
}));
} else {
res.send(JSON.stringify({
email: req.body.email,
accessToken: token.id
}));
}
});
});
};