Login: display feedback.

This commit is contained in:
Matthew Dillon 2015-03-26 10:43:36 -08:00
parent 8e16295244
commit c5cb0ec145
6 changed files with 98 additions and 19 deletions

View file

@ -4,18 +4,26 @@ module.exports = function(app) {
var authenticateRouter = express.Router();
authenticateRouter.post('/', function(req, res) {
var token = jwt.sign({
'name': 'Test User',
'role': 'admin'
}, 'secret',
{
expiresInMinutes: 60,
issuer: 'bactdb',
subject: 'Test User',
});
res.send({
'token': token
});
// wait for a bit to simulate cold boot of heroku api
var ms = 3000 + new Date().getTime();
while (new Date() < ms){}
if (req.body.username === 'test' && req.body.password === 'test') {
var token = jwt.sign({
'name': 'Test User',
'role': 'admin'
}, 'secret',
{
expiresInMinutes: 60,
issuer: 'bactdb',
subject: 'Test User',
});
res.send({
'token': token
});
} else {
res.status(401).send({'error':'Invalid username or password'});
}
});
app.use('/api/authenticate', authenticateRouter);