diff --git a/foftickets.js b/foftickets.js index a927e00..582cb8e 100644 --- a/foftickets.js +++ b/foftickets.js @@ -329,8 +329,7 @@ app.get('/manytickets', requireLogin, (req,res) => { return res.render("manytickets",edit); }) - -app.get('/mytickets',requireLogin, async (req,res)=> { +async function renderOneOrManyTickets(req,res) { let username=req.session.username; let claimed=0; let owned=0; @@ -363,7 +362,10 @@ app.get('/mytickets',requireLogin, async (req,res)=> { return res.render("oneticket",data); } else return res.render("manytickets",edit); -}); + } + +app.get('/mytickets',requireLogin, renderOneOrManyTickets); + app.get("/oneticket",requireLogin, async (req,res) => { let username=req.session.username; @@ -478,7 +480,7 @@ app.get("/useticket",(req,res) => { -async function EmailTickets(email) { +async function EmailTickets_fof(email) { let offered=0; for (const ticket in tickets) if (tickets[ticket].offered==email) offered++; if (offered==0) return; @@ -496,6 +498,24 @@ async function EmailTickets(email) { }); } +async function EmailTickets(email) { + let offered=0; + for (const ticket in tickets) if (tickets[ticket].offered==email) offered++; + if (offered==0) return; + const textbody="You have been offered "+offered+" tickets to the Frostburn Decompression! To claim them, visit this link:\n"+GetMagicLink(email); + const htmlbody="You have been offered "+offered+" tickets to the Frostburn Decompression! To claim them, click here."; + if (!settings['enable-email']) { + console.log("Email disabled. Would have sent to "+email+": "+textbody); + return; + } + await client.sendEmail({ From: "tickets@fallsonfire.net", + To: email, + Subject: "Frostburn Decompression: You've Got Tickets!", + TextBody: textbody, + HTMLBody: htmlbody + }); + } + app.get('/testemail', (req,res) => { client.sendEmail({ From: 'tickets@fallsonfire.net', @@ -516,7 +536,7 @@ app.get('/testemail', // Routes app.get('/', (req, res) => { - if (req.session.username) return res.redirect("/mytickets"); + if (req.session.username) return renderOneOrManyTickets(req,res); return res.render("login", { superuser:false }); }); @@ -567,21 +587,22 @@ app.get('/create', (req, res) => { app.post('/create', async (req, res) => { const { username, password1, password2 } = req.body; - if (password1!=password2) return res.render("error",{ message: "Passwords do not match."} ); - if (users[username] && !users[username].needsconfirm) return res.render("error",{ message: "Email (username) already exists."} ); + if (password1!=password2) { req.session.message="Passwords do not match."; return res.redirect('/'); } + if (users[username] && !users[username].needsconfirm) { req.session.error="Email (username) already exists."; return res.redirect('/'); } if (users[username] && users[username].needsconfirm) { await client.sendEmail({ From: "tickets@fallsonfire.net", To: username, - Subject: "Falls on Fire: Confirm Account Creation", + Subject: "Confirm Account Creation", TextBody: "Click here to confirm creation of account "+username, HTMLBody: "Click here to confirm creation of account "+username }); - return res.render("message",{ message: "Email has not yet been confirmed. Resent confirm link." }); + req.session.message="Email has not yet been confirmed. Resent confirm link."; + return res.redirect('/'); } users[username] = { password: hashPW(password1), needsconfirm:false }; - console.log("Created new account:",username); - if (users[username].needsconfirm) return res.render("message",{ message: "Check email to confirm account creation." }); - return res.render("message",{ message: "Account created. You may now log in." }); + if (users[username].needsconfirm) req.session.message="Check email to confirm account creation."; + else req.session.message="Account created. You may now log in."; + return res.redirect('/'); }); @@ -606,10 +627,11 @@ app.get('/changepassword', requireLogin,(req, res) => { app.post('/changepassword', requireLogin,(req, res) => { const { password0, password1, password2 } = req.body; - if (users[req.session.username].password!=hashPW(password0)) return res.render("error",{ message: "Old Password is not correct."}); - if (password1!=password2) return res.render("error",{ message: "Passwords do not match."}) + if (users[req.session.username].password!=hashPW(password0)) { req.session.error="Old Password is not correct."; return res.redirect('/changepassword'); } + if (password1!=password2) { req.session.error="Passwords do not match"; return res.redirect('/changepassword'); } users[req.session.username].password=hashPW(password1); - return res.render("message",{ message: "Password changed."}) + req.session.message="Password Changed."; + return res.redirect('/'); });