Finished up with email password reset system.
This commit is contained in:
parent
3671b43789
commit
478edeeddf
13 changed files with 233 additions and 34 deletions
|
|
@ -14,6 +14,10 @@ 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/>.*/
|
||||
|
||||
//Node Imports
|
||||
const crypto = require('node:crypto');
|
||||
|
||||
//NPM Imports
|
||||
const bcrypt = require('bcrypt');
|
||||
|
||||
module.exports.hashPassword = function(pass){
|
||||
|
|
@ -23,4 +27,15 @@ module.exports.hashPassword = function(pass){
|
|||
|
||||
module.exports.comparePassword = function(pass, hash){
|
||||
return bcrypt.compareSync(pass, hash);
|
||||
}
|
||||
|
||||
module.exports.hashIP = function(ip){
|
||||
//Create hash object
|
||||
const hashObj = crypto.createHash('md5');
|
||||
|
||||
//add IP to the hash
|
||||
hashObj.update(ip);
|
||||
|
||||
//return the IP hash as a string
|
||||
return hashObj.digest('hex');
|
||||
}
|
||||
57
src/utils/mailUtils.js
Normal file
57
src/utils/mailUtils.js
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/*Canopy - The next generation of stoner streaming software
|
||||
Copyright (C) 2024 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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue