diff options
Diffstat (limited to 'server.js')
-rw-r--r-- | server.js | 60 |
1 files changed, 31 insertions, 29 deletions
@@ -139,9 +139,11 @@ if (process.env.MAIL_HOST && process.env.MAIL_PORT && process.env.MAIL_FROM) { console.log("Mail notifications enabled: ", mailer.options) } else { console.log("Mail notifications disabled.") - mailer = { - sendMail(mail) { - console.log("MAIL (DEBUG):", mail) + if (DEBUG) { + mailer = { + sendMail(mail) { + console.log("MAIL (DEBUG):", mail) + } } } } @@ -541,7 +543,7 @@ app.get("/", function (req, res) { }) app.get("/create", function (req, res) { - res.render("create-index.pug") + res.render("create_index.pug") }) app.get("/about", function (req, res) { @@ -639,7 +641,7 @@ app.post("/account/mail/verify", must_be_logged_in, function (req, res) { app.get("/account/forgot-password", function (req, res) { if (req.user) return res.redirect("/") - res.render("forgot_password.pug") + res.render("account_forgot_password.pug") }) app.post("/account/forgot-password", must_pass_altcha, function (req, res) { @@ -650,7 +652,7 @@ app.post("/account/forgot-password", must_pass_altcha, function (req, res) { mail_password_reset_token(user, token) return res.redirect("/account/reset-password?mail=" + mail) } - res.render("forgot_password.pug", { flash: "User not found." }) + res.render("account_forgot_password.pug", { flash: "User not found." }) }) app.get("/account/reset-password", function (req, res) { @@ -658,7 +660,7 @@ app.get("/account/reset-password", function (req, res) { return res.redirect("/") var mail = req.query.mail var token = req.query.token - res.render("reset_password.pug", { mail, token }) + res.render("account_reset_password.pug", { mail, token }) }) app.post("/account/reset-password", must_pass_altcha, function (req, res) { @@ -666,7 +668,7 @@ app.post("/account/reset-password", must_pass_altcha, function (req, res) { let token = req.body.token let password = req.body.password function err(msg) { - res.render("reset_password.pug", { mail: mail, token: token, flash: msg }) + res.render("account_reset_password.pug", { mail: mail, token: token, flash: msg }) } let user = SQL_SELECT_LOGIN_BY_MAIL.get(mail) if (!user) @@ -684,7 +686,7 @@ app.post("/account/reset-password", must_pass_altcha, function (req, res) { }) app.get("/account/change-password", must_be_logged_in, function (req, res) { - res.render("change_password.pug") + res.render("account_change_password.pug") }) app.post("/account/change-password", must_be_logged_in, function (req, res) { @@ -693,9 +695,9 @@ app.post("/account/change-password", must_be_logged_in, function (req, res) { // Get full user record including password and salt let user = SQL_SELECT_LOGIN.get(req.user.user_id) if (!is_valid_password(newpass)) - return res.render("change_password.pug", { flash: "New password is invalid!" }) + return res.render("account_change_password.pug", { flash: "New password is invalid!" }) if (!verify_password(req.user, oldpass)) - return res.render("change_password.pug", { flash: "Wrong password!" }) + return res.render("account_change_password.pug", { flash: "Wrong password!" }) let salt = crypto.randomBytes(32).toString("hex") let hash = hash_password(newpass, salt) SQL_UPDATE_USER_PASSWORD.run(user.user_id, hash, salt) @@ -717,7 +719,7 @@ function may_delete_account(user_id) { app.get("/account/delete", must_be_logged_in, function (req, res) { if (!may_delete_account(req.user.user_id)) return res.status(401).send("You may not delete your account while you have unfinished games.") - res.render("delete_account.pug") + res.render("account_delete.pug") }) const SQL_SELECT_GAME_ROLE_FOR_DELETED_USER = SQL(` @@ -733,7 +735,7 @@ app.post("/account/delete", must_be_logged_in, function (req, res) { let user = SQL_SELECT_LOGIN.get(req.user.user_id) let hash = hash_password(password, user.salt) if (hash !== user.password) - return res.render("delete_account.pug", { flash: "Wrong password!" }) + return res.render("account_delete.pug", { flash: "Wrong password!" }) let list = SQL_SELECT_GAME_ROLE_FOR_DELETED_USER.all(req.user.user_id) for (let item of list) @@ -771,12 +773,12 @@ app.get("/account/mail/unsubscribe", must_be_logged_in, function (req, res) { app.get("/account/webhook", must_be_logged_in, function (req, res) { let webhook = SQL_SELECT_WEBHOOK.get(req.user.user_id) - res.render("webhook.pug", { webhook: webhook }) + res.render("account_webhook.pug", { webhook: webhook }) }) app.post("/account/webhook/delete", must_be_logged_in, function (req, res) { SQL_DELETE_WEBHOOK.run(req.user.user_id) - res.redirect("/webhook") + res.redirect("/account/webhook") }) app.post("/account/webhook/update", must_be_logged_in, function (req, res) { @@ -787,38 +789,38 @@ app.post("/account/webhook/update", must_be_logged_in, function (req, res) { const webhook = SQL_SELECT_WEBHOOK_SEND.get(req.user.user_id) if (webhook) send_webhook(req.user.user_id, webhook, "Test message!", 0) - res.setHeader("refresh", "3; url=/webhook") + res.setHeader("refresh", "3; url=/account/webhook") res.send("Testing Webhook. Please wait...") }) app.get("/account/change-name", must_be_logged_in, function (req, res) { - res.render("change_name.pug") + res.render("account_change_name.pug") }) app.post("/account/change-name", must_be_logged_in, function (req, res) { let newname = clean_user_name(req.body.newname) if (!is_valid_user_name(newname)) - return res.render("change_name.pug", { flash: "Invalid user name!" }) + return res.render("account_change_name.pug", { flash: "Invalid user name!" }) if (SQL_EXISTS_USER_NAME.get(newname)) - return res.render("change_name.pug", { flash: "That name is already taken!" }) + return res.render("account_change_name.pug", { flash: "That name is already taken!" }) if (!verify_password(req.user, req.body.password)) - return res.render("change_name.pug", { flash: "Wrong password!" }) + return res.render("account_change_name.pug", { flash: "Wrong password!" }) SQL_UPDATE_USER_NAME.run(newname, req.user.user_id) return res.redirect("/profile") }) app.get("/account/change-mail", must_be_logged_in, function (req, res) { - res.render("change_mail.pug") + res.render("account_change_mail.pug") }) app.post("/account/change-mail", must_be_logged_in, function (req, res) { let newmail = req.body.newmail if (!is_valid_email(newmail) || is_forbidden_mail(newmail)) - return res.render("change_mail.pug", { flash: "Invalid mail address!" }) + return res.render("account_change_mail.pug", { flash: "Invalid mail address!" }) if (SQL_EXISTS_USER_MAIL.get(newmail)) - return res.render("change_mail.pug", { flash: "That mail address is already taken!" }) + return res.render("account_change_mail.pug", { flash: "That mail address is already taken!" }) if (!verify_password(req.user, req.body.password)) - return res.render("change_mail.pug", { flash: "Wrong password!" }) + return res.render("account_change_mail.pug", { flash: "Wrong password!" }) SQL_UPDATE_USER_MAIL.run(newmail, req.user.user_id) SQL_UPDATE_USER_VERIFIED.run(0, req.user.user_id) SQL_UPDATE_USER_NOTIFY.run(0, req.user.user_id) @@ -827,7 +829,7 @@ app.post("/account/change-mail", must_be_logged_in, function (req, res) { app.get("/account/change-about", must_be_logged_in, function (req, res) { let about = SQL_SELECT_USER_ABOUT.get(req.user.user_id) - res.render("change_about.pug", { about }) + res.render("account_change_about.pug", { about }) }) app.post("/account/change-about", must_be_logged_in, function (req, res) { @@ -909,13 +911,13 @@ app.get("/contacts/search", must_be_logged_in, function (req, res) { if (!q.includes("%")) q = "%" + q + "%" let results = SQL_SELECT_USER_BY_SEARCH.all(q) - res.render("search_user.pug", { + res.render("contacts_search.pug", { user: req.user, search: req.query.q, results }) } else { - res.render("search_user.pug", { + res.render("contacts_search.pug", { user: req.user, search: null, results: null, @@ -1823,7 +1825,7 @@ function get_title_page(req, res, title_id) { let active_pools = TM_POOL_LIST_TITLE_ACTIVE.all(title_id) let finished_pools = TM_POOL_LIST_TITLE_FINISHED.all(title_id) - res.render("info.pug", { + res.render("title.pug", { user: req.user, title: title, open_games, @@ -1844,7 +1846,7 @@ app.get("/create/:title_id", function (req, res) { let title = TITLE_TABLE[title_id] if (!title) return res.status(404).send("Invalid title.") - res.render("create.pug", { + res.render("create_title.pug", { user: req.user, title: title, limit: req.user ? check_create_game_limit(req.user) : null, |