aboutsummaryrefslogtreecommitdiff
path: root/src/server.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/server.js')
-rw-r--r--src/server.js23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/server.js b/src/server.js
index e680266..b2b8d25 100644
--- a/src/server.js
+++ b/src/server.js
@@ -220,6 +220,7 @@ function setUpRoutes(models, jwtFunctions, database, templates) {
server.get('/login', cache('5 minutes'), (req, res) => res.sendFile(__dirname + "/html/login.html"))
server.get('/email', cache('5 minutes'), (req, res) => res.sendFile(__dirname + "/html/email.html"))
server.get('/email-success', cache('5 minutes'), (req, res) => res.sendFile(__dirname + "/html/email-success.html"))
+ server.get('/email-unsubscribe', cache('5 minutes'), (req, res) => res.sendFile(__dirname + "/html/email-unsubscribe.html"))
server.get('/feed', cache('5 minutes'), (req, res) => res.sendFile(__dirname + "/html/feed.html"));
server.get('/essay', cache('5 minutes'), (req, res) => res.sendFile(__dirname + "/html/essay.html"));
server.get('/word-square', cache('5 minutes'), (req, res) => res.sendFile(__dirname + "/html/word-square.html"));
@@ -228,6 +229,10 @@ function setUpRoutes(models, jwtFunctions, database, templates) {
server.get('/zines', cache('5 minutes'), (req, res) => res.sendFile(__dirname + "/public/zines.html"));
server.use('/static', express.static(__dirname + '/public'))
+ server.get('/hello/:path', async (req, res) => {
+ await models.hellos.create({page: req.params.path})
+ res.status(200).send()
+ })
server.get('/misc', cache('5 minutes'), async (req, res) => {
let body = templates["misc"]();
res.status(200).send(body)
@@ -272,7 +277,7 @@ function setUpRoutes(models, jwtFunctions, database, templates) {
try {
var sessionResult = await database.query("SELECT session, count(id) as c FROM requests GROUP BY session HAVING c > 1", { type: database.QueryTypes.SELECT })
var total = await database.query("select count(distinct session) as t FROM requests", { type: database.QueryTypes.SELECT })
- var urlResult = await database.query("SELECT method, url, count(id) as c FROM requests GROUP BY method, url", { type: database.QueryTypes.SELECT })
+ var urlResult = await database.query("SELECT method, url, count(id) as c FROM requests GROUP BY method, url ORDER BY c DESC", { type: database.QueryTypes.SELECT })
let urls = (await get_routes(models)).map(obj => obj.route)
urlResult = urlResult.filter(obj => { return urls.includes(obj.url) })
var logResult = await database.query("SELECT createdAt, session, method, url FROM requests order by createdAt desc limit 15", { type: database.QueryTypes.SELECT })
@@ -334,6 +339,11 @@ function setUpRoutes(models, jwtFunctions, database, templates) {
res.status(400).send(e.message);
}
})
+ server.delete('/admin/email/:id', async (req, res, next) => {
+ await models.emails.destroy({ where: { id: req.params.id } });
+ var emails = await models.emails.findAll();
+ res.status(200).send(emails);
+ })
server.post('/login', async (req, res, next) => {
const user = await models.users.findOne({ where: { username: req.body.username} })
const hash = hashWithSalt(req.body.password, user.salt)
@@ -351,12 +361,20 @@ function setUpRoutes(models, jwtFunctions, database, templates) {
const name = req.body.name;
const email = req.body.email;
if (name && email) {
- models.emails.create({"name": name, "address": email})
+ const code = crypto.randomBytes(40).toString('hex').slice(0, 40)
+ models.emails.create({"name": name, "address": email, "code": code})
res.redirect('/email-success');
} else {
console.debug("Error with email submission")
}
})
+ server.get('/email/unsubscribe/:code/check', async (req, res, next) => {
+ res.sendFile(__dirname + "/html/email-confirm.html")
+ })
+ server.get('/email/unsubscribe/:code/confirm', async (req, res, next) => {
+ await models.emails.destroy({ where: {"code": req.params.code}})
+ res.redirect('/email-unsubscribe');
+ })
server.post('/wordsquares', async (req, res, next) => {
const words = req.body.words;
const name = req.body.name;
@@ -384,7 +402,6 @@ function setUpRoutes(models, jwtFunctions, database, templates) {
res.status(200).send(game);
})
-
server.get('/favicon.ico', cache('5 minutes'), (req, res) => res.sendFile(__dirname + "/icon/favicon.ico"))
server.get('/favicon.svg', cache('5 minutes'), (req, res) => res.sendFile(__dirname + "/icon/favicon.svg"))
server.get('/css/:id', cache('5 minutes'), (req, res) => {