82 lines
2.9 KiB
JavaScript
82 lines
2.9 KiB
JavaScript
/*Canopy - The next generation of stoner streaming software
|
|
Copyright (C) 2024-2025 Rainbownapkin and the TTN Community
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as
|
|
published by the Free Software Foundation, either version 3 of the
|
|
License, or (at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
|
|
|
//Config
|
|
const config = require('../../config.json');
|
|
|
|
//NPM imports
|
|
const nodeMailer = require("nodemailer");
|
|
|
|
//Setup mail transport
|
|
const transporter = nodeMailer.createTransport({
|
|
host: config.mail.host,
|
|
port: config.mail.port,
|
|
secure: config.mail.secure,
|
|
auth: {
|
|
user: config.mail.address,
|
|
pass: config.mail.pass
|
|
}
|
|
});
|
|
|
|
module.exports.mailem = async function(to, subject, body, htmlBody = false){
|
|
//Create mail object
|
|
const mailObj = {
|
|
from: `"Tokebot🤖💨"<${config.mail.address}>`,
|
|
to,
|
|
subject
|
|
};
|
|
|
|
//If we're sending HTML
|
|
if(htmlBody){
|
|
//set body as html
|
|
mailObj.html = body;
|
|
//If we're sending plaintext
|
|
}else{
|
|
//Set body as plaintext
|
|
mailObj.text = body
|
|
}
|
|
|
|
//Send mail based on mail object
|
|
const sentMail = await transporter.sendMail(mailObj);
|
|
|
|
//return the mail info
|
|
return sentMail;
|
|
}
|
|
|
|
module.exports.sendAddressVerification = async function(requestDB, userDB, newEmail){
|
|
//Send the reset url via email
|
|
await module.exports.mailem(
|
|
newEmail,
|
|
`Email Change Request - ${userDB.user}`,
|
|
`<h1>Email Change Request</h1>
|
|
<p>A request to change the email associated with the ${config.instanceName} account '${userDB.user}' to this address has been requested.<br>
|
|
<a href="${requestDB.getChangeURL()}">Click here</a> to confirm this change.</p>
|
|
<sup>If you received this email without request, feel free to ignore and delete it! -Tokebot</sup>`,
|
|
true
|
|
);
|
|
|
|
//If the user has a pre-existing email address
|
|
if(userDB.email != null && userDB.email != ""){
|
|
await module.exports.mailem(
|
|
userDB.email,
|
|
`Email Change Request - ${userDB.user}`,
|
|
`<h1>Email Change Request Notification</h1>
|
|
<p>A request to change the email associated with the ${config.instanceName} account '${userDB.user}' to another address has been requested.<br>
|
|
<sup>If you received this email without request, you should <strong>immediately</strong> change your password and contact the server adminsitrator! -Tokebot</sup>`,
|
|
true
|
|
);
|
|
}
|
|
} |