tracman-server/config/routes/test.js

52 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-04-12 11:41:27 -06:00
'use strict';
const router = require('express').Router(),
2017-06-30 10:48:29 -06:00
zxcvbn = require('zxcvbn'),
2017-04-12 11:41:27 -06:00
mw = require('../middleware.js'),
mail = require('../mail.js');
router
2017-04-12 11:41:27 -06:00
.get('/mail', (req,res,next)=>{
mail.send({
to: `"Keith Irwin" <hypergeek14@gmail.com>`,
2017-05-08 15:45:06 -06:00
from: mail.noReply,
subject: 'Test email',
text: mail.text("Looks like everything's working! "),
html: mail.html("<p>Looks like everything's working! </p>")
2017-04-15 08:22:13 -06:00
})
.then(()=>{
console.log("Test email should have sent...");
res.sendStatus(200);
2017-04-15 08:22:13 -06:00
})
.catch((err)=>{
mw.throwErr(err,req);
2017-04-15 08:22:13 -06:00
res.sendStatus(500);
});
})
.get('/password', (req,res)=>{
res.render('password');
2017-04-15 08:22:13 -06:00
})
2017-04-15 08:48:37 -06:00
.post('/password', (req,res,next)=>{
2017-06-30 11:14:59 -06:00
let zxcvbnResult = zxcvbn(req.body.password);
if (zxcvbnResult.crack_times_seconds.online_no_throttling_10_per_second < 864000) { // Less than ten days
let err = new Error(`That password could be cracked in ${zxcvbnResult.crack_times_display.online_no_throttling_10_per_second}! Come up with a more complex password that would take at least 10 days to crack. `);
2017-04-20 21:07:35 -06:00
mw.throwErr(err,req);
2017-04-15 08:48:37 -06:00
next(err);
}
else {
res.sendStatus(200);
}
})
.get('/settings', (req,res)=>{
res.render('settings');
})
.post('/settings', (req,res)=>{
2017-04-20 20:15:00 -06:00
//TODO: Test validation here?
});
2017-04-12 11:41:27 -06:00
module.exports = router;