28 lines
637 B
JavaScript
28 lines
637 B
JavaScript
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
|
|
}));
|
|
}
|
|
});
|
|
});
|
|
};
|