2017-04-12 11:41:27 -06:00
'use strict' ;
const router = require ( 'express' ) . Router ( ) ,
2017-04-15 08:48:37 -06:00
mellt = require ( 'mellt' ) ,
2017-04-12 11:41:27 -06:00
mw = require ( '../middleware.js' ) ,
mail = require ( '../mail.js' ) ;
2017-04-12 12:32:28 -06:00
router
2017-04-12 11:41:27 -06:00
2017-04-13 16:53:18 -06:00
. get ( '/mail' , ( req , res , next ) => {
2017-04-12 12:32:28 -06:00
mail . send ( {
to : ` "Keith Irwin" <hypergeek14@gmail.com> ` ,
from : mail . from ,
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 ( ( ) => {
2017-04-12 12:32:28 -06:00
console . log ( "Test email should have sent..." ) ;
res . sendStatus ( 200 ) ;
2017-04-15 08:22:13 -06:00
} )
. catch ( ( err ) => {
2017-04-12 12:32:28 -06:00
mw . throwErr ( err , req ) ;
2017-04-15 08:22:13 -06:00
res . sendStatus ( 500 ) ;
2017-04-12 12:32:28 -06:00
} ) ;
} )
2017-04-13 16:53:18 -06:00
. get ( '/password' , ( req , res ) => {
2017-04-12 12:32:28 -06:00
res . render ( 'password' ) ;
2017-04-15 08:22:13 -06:00
} )
2017-04-15 08:48:37 -06:00
. post ( '/password' , ( req , res , next ) => {
let daysToCrack = mellt . CheckPassword ( req . body . password ) ;
if ( daysToCrack < 10 ) {
2017-04-15 09:00:04 -06:00
let err = new Error ( ` That password could be cracked in ${ daysToCrack } days! Come up with a more complex password that would take at least 10 days to crack. ` ) ;
2017-04-15 08:48:37 -06:00
mw . throwErr ( err ) ;
next ( err ) ;
}
else {
res . sendStatus ( 200 ) ;
}
2017-04-16 17:26:48 -06:00
} )
. get ( '/settings' , ( req , res ) => {
res . render ( 'settings' ) ;
} )
. post ( '/settings' , ( req , res ) => {
2017-04-16 19:17:20 -06:00
2017-04-16 17:26:48 -06:00
//TODO: Test validation here.
2017-04-16 19:17:20 -06:00
2017-04-13 16:53:18 -06:00
} ) ;
2017-04-12 12:32:28 -06:00
2017-04-12 11:41:27 -06:00
module . exports = router ;