2017-03-15 02:01:55 -06:00
|
|
|
'use strict';
|
|
|
|
|
2017-04-10 01:00:56 -06:00
|
|
|
const mw = require('../middleware.js'),
|
|
|
|
router = require('express').Router(),
|
|
|
|
slug = require('slug'),
|
2017-04-17 22:12:39 -06:00
|
|
|
xss = require('xss'),
|
2017-04-10 01:00:56 -06:00
|
|
|
User = require('../models.js').user;
|
2017-03-14 22:05:03 -06:00
|
|
|
|
2017-04-25 15:22:23 -06:00
|
|
|
module.exports = router
|
|
|
|
|
|
|
|
// Index
|
|
|
|
.get('/', (req,res,next)=>{
|
|
|
|
res.render('index');
|
|
|
|
})
|
2017-04-10 01:00:56 -06:00
|
|
|
|
2017-04-25 15:22:23 -06:00
|
|
|
// Help
|
2017-04-28 01:21:16 -06:00
|
|
|
.get('/help', (req,res)=>{
|
2017-04-25 15:22:23 -06:00
|
|
|
res.render('help');
|
|
|
|
})
|
2017-04-16 19:17:20 -06:00
|
|
|
|
2017-05-08 15:12:49 -06:00
|
|
|
// Contact
|
|
|
|
.get('/contact', (req,res)=>{
|
|
|
|
res.render('contact');
|
|
|
|
})
|
|
|
|
.post('/contact', (req,res)=>{
|
|
|
|
//TODO: Get contact stuff
|
|
|
|
})
|
|
|
|
|
2017-04-25 15:22:23 -06:00
|
|
|
// Terms of Service and Privacy Policy
|
|
|
|
.get('/terms', (req,res)=>{
|
|
|
|
res.render('terms');
|
|
|
|
})
|
|
|
|
.get('/privacy', (req,res)=>{
|
|
|
|
res.render('privacy');
|
|
|
|
})
|
2017-04-16 19:17:20 -06:00
|
|
|
|
2017-04-25 15:22:23 -06:00
|
|
|
// robots.txt
|
|
|
|
.get('/robots.txt', (req,res)=>{
|
|
|
|
res.type('text/plain');
|
|
|
|
res.send("User-agent: *\n"+
|
|
|
|
"Disallow: /map/*\n"
|
|
|
|
);
|
|
|
|
})
|
2017-04-16 19:17:20 -06:00
|
|
|
|
2017-04-25 15:22:23 -06:00
|
|
|
// favicon.ico
|
|
|
|
.get('/favicon.ico', (req,res)=>{
|
|
|
|
res.redirect('/static/img/icon/by/16-32-48.ico');
|
|
|
|
})
|
2017-04-17 10:45:48 -06:00
|
|
|
|
2017-04-25 15:22:23 -06:00
|
|
|
// Endpoint to validate forms
|
2017-04-27 14:44:49 -06:00
|
|
|
.get('/validate', (req,res,next)=>{
|
2017-04-25 15:22:23 -06:00
|
|
|
|
|
|
|
// Validate unique slug
|
|
|
|
if (req.query.slug) {
|
|
|
|
User.findOne({ slug: slug(req.query.slug) })
|
|
|
|
.then( (existingUser)=>{
|
|
|
|
if (existingUser && existingUser.id!==req.user.id) {
|
|
|
|
res.sendStatus(400);
|
|
|
|
}
|
|
|
|
else { res.sendStatus(200); }
|
|
|
|
})
|
2017-04-27 14:44:49 -06:00
|
|
|
.catch( (err)=>{
|
|
|
|
console.error(err);
|
|
|
|
res.sendStatus(500);
|
|
|
|
});
|
2017-04-25 15:22:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Validate unique email
|
|
|
|
else if (req.query.email) {
|
|
|
|
User.findOne({ email: req.query.email })
|
|
|
|
.then( (existingUser)=>{
|
|
|
|
if (existingUser && existingUser.id!==req.user.id) {
|
|
|
|
res.sendStatus(400);
|
|
|
|
}
|
|
|
|
else { res.sendStatus(200); }
|
|
|
|
})
|
2017-04-27 14:44:49 -06:00
|
|
|
.catch( (err)=>{
|
|
|
|
console.error(err);
|
|
|
|
res.sendStatus(500);
|
|
|
|
});
|
2017-04-25 15:22:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create slug
|
|
|
|
else if (req.query.slugify) {
|
|
|
|
res.send(slug(xss(req.query.slugify)));
|
|
|
|
}
|
|
|
|
|
2017-04-27 14:44:49 -06:00
|
|
|
// Sanitize for XSS
|
2017-04-25 15:22:23 -06:00
|
|
|
else if (req.query.xss) {
|
|
|
|
res.send(xss(req.query.xss));
|
|
|
|
}
|
|
|
|
|
2017-04-27 14:44:49 -06:00
|
|
|
// 404
|
|
|
|
else { next(); }
|
|
|
|
|
2017-04-25 15:22:23 -06:00
|
|
|
})
|
2017-04-17 22:12:39 -06:00
|
|
|
|
2017-04-25 15:22:23 -06:00
|
|
|
// Link to androidapp in play store
|
|
|
|
.get('/android', (req,res)=>{
|
|
|
|
res.redirect('https://play.google.com/store/apps/details?id=us.keithirwin.tracman');
|
|
|
|
})
|
|
|
|
|
|
|
|
// Link to iphone app in the apple store
|
|
|
|
// ... maybe someday
|
|
|
|
.get('/ios', (req,res)=>{
|
|
|
|
res.redirect('/help#why-is-there-no-ios-app');
|
|
|
|
})
|
2017-04-10 01:00:56 -06:00
|
|
|
|
2017-04-25 15:22:23 -06:00
|
|
|
;
|