diff --git a/src/server/routes/adminRoutes.ts b/src/server/routes/adminRoutes.ts index 83debcb..7b24baa 100644 --- a/src/server/routes/adminRoutes.ts +++ b/src/server/routes/adminRoutes.ts @@ -49,10 +49,11 @@ adminRoutes.post("/reset", parser, (req,res) => { auth.invalidate(v.token) }) - - sendMail(req.body.email, `Your login details have been updated`, `Hello there! This email is to notify you of a password change that an administrator, ${acc.username}, has initiated. You have been logged out of your devices. Thank you for using monofile.`).then(() => { - res.send("OK") - }).catch((err) => {}) + if (targetAccount.email) { + sendMail(targetAccount.email, `Your login details have been updated`, `Hello there! This email is to notify you of a password change that an administrator, ${acc.username}, has initiated. You have been logged out of your devices. Thank you for using monofile.`).then(() => { + res.send("OK") + }).catch((err) => {}) + } res.send() diff --git a/src/server/routes/authRoutes.ts b/src/server/routes/authRoutes.ts index e27f685..9596eae 100644 --- a/src/server/routes/authRoutes.ts +++ b/src/server/routes/authRoutes.ts @@ -240,9 +240,11 @@ authRoutes.post("/change_username", requiresAccount, parser, (req,res) => { acc.username = req.body.username Accounts.save() - sendMail(req.body.email, `Your login details have been updated`, `Hello there! Your username has been updated to ${req.body.username}. Please update your devices accordingly. Thank you for using monofile.`).then(() => { - res.send("OK") - }).catch((err) => {}) + if (acc.email) { + sendMail(acc.email, `Your login details have been updated`, `Hello there! Your username has been updated to ${req.body.username}. Please update your devices accordingly. Thank you for using monofile.`).then(() => { + res.send("OK") + }).catch((err) => {}) + } res.send("username changed") }) @@ -407,9 +409,11 @@ authRoutes.post("/change_password", requiresAccount, parser, (req,res) => { auth.invalidate(v.token) }) - sendMail(req.body.email, `Your login details have been updated`, `Hello there! This email is to notify you of a password change that you have initiated. You have been logged out of your devices. Thank you for using monofile.`).then(() => { - res.send("OK") - }).catch((err) => {}) + if (acc.email) { + sendMail(acc.email, `Your login details have been updated`, `Hello there! This email is to notify you of a password change that you have initiated. You have been logged out of your devices. Thank you for using monofile.`).then(() => { + res.send("OK") + }).catch((err) => {}) + } res.send("password changed - logged out all sessions") })