Implemented Profile Migration Backend
This commit is contained in:
parent
da9428205f
commit
6cbb726764
8 changed files with 228 additions and 17 deletions
|
|
@ -17,9 +17,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
|||
//NPM Imports
|
||||
const { csrfSync } = require('csrf-sync');
|
||||
|
||||
//Local Imports
|
||||
const {errorHandler} = require('./loggerUtils');
|
||||
|
||||
//Pull needed methods from csrfSync
|
||||
const {generateToken, revokeToken, csrfSynchronisedProtection, isRequestValid} = csrfSync();
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ module.exports.hashPassword = function(pass){
|
|||
}
|
||||
|
||||
/**
|
||||
* Sitewide password for authenticating/comparing passwords agianst hashes
|
||||
* Sitewide method for authenticating/comparing passwords agianst hashes
|
||||
* @param {String} pass - Plaintext Password
|
||||
* @param {String} hash - Salty Hash
|
||||
* @returns {Boolean} True if authentication success
|
||||
|
|
@ -43,6 +43,16 @@ module.exports.comparePassword = function(pass, hash){
|
|||
return bcrypt.compareSync(pass, hash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sitewide method for authenticating/comparing passwords agianst hashes for legacy profiles
|
||||
* @param {String} pass - Plaintext Password
|
||||
* @param {String} hash - Salty Hash
|
||||
* @returns {Boolean} True if authentication success
|
||||
*/
|
||||
module.exports.compareLegacyPassword = function(pass, hash){
|
||||
return bcrypt.compareSync(pass, hash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Site-wide IP hashing/salting function
|
||||
*
|
||||
|
|
|
|||
|
|
@ -72,16 +72,40 @@ module.exports.mailem = async function(to, subject, body, htmlBody = false){
|
|||
* @param {Mongoose.Document} requestDB - DB Document Object for the current email change request token
|
||||
* @param {Mongoose.Document} userDB - DB Document Object for the user we're verifying email against
|
||||
* @param {String} newEmail - New email address to send to
|
||||
* @param {Boolean} newUser - Denotes an email going out to a new account
|
||||
* @param {Boolean} migration - Denotes an email going out to an account which was just mirated
|
||||
*/
|
||||
module.exports.sendAddressVerification = async function(requestDB, userDB, newEmail){
|
||||
module.exports.sendAddressVerification = async function(requestDB, userDB, newEmail, newUser = false, migration = false,){
|
||||
let subject = `Email Change Request - ${userDB.user}`;
|
||||
let content = `<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>`;
|
||||
|
||||
if(newUser){
|
||||
subject = `New User Email Confirmation - ${userDB.user}`;
|
||||
|
||||
content = `<h1>New user email confirmation</h1>
|
||||
<p>a new ${config.instanceName} account '${userDB.user}' was created with this email address.<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>`;
|
||||
}
|
||||
|
||||
if(migration){
|
||||
subject = `User Migration Email Confirmation - ${userDB.user}`;
|
||||
|
||||
content = `<h1>User migration email confirmation</h1>
|
||||
<p>The ${config.instanceName} account '${userDB.user}' was successfully migrated to our <a href="https://git.ourfore.st/rainbownapkin/canopy">fancy new codebase</a>.<br>
|
||||
<a href="${requestDB.getChangeURL()}">click here</a> to confirm this change.</p>
|
||||
<sup>if you received this email without request, reach out to an admin, as your old account might be getting jacked! -tokebot</sup>`;
|
||||
}
|
||||
|
||||
|
||||
//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>`,
|
||||
subject,
|
||||
content,
|
||||
true
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue