Merge pull request #335 from PretendoNetwork/fix/#332

Update "PNID deleted" email to mention the 7 day grace period
This commit is contained in:
Jonathan Barrow
2026-05-12 11:41:25 -04:00
committed by GitHub
5 changed files with 44 additions and 8 deletions

View File

@@ -235,9 +235,35 @@ PNIDSchema.method('generateMiiImages', async function generateMiiImages(): Promi
await uploadCDNAsset(config.s3.bucket, `${userMiiKey}/body.png`, miiStudioBodyImageData, 'public-read');
});
PNIDSchema.method('markForDeletion', function markForDeletion() {
PNIDSchema.method('markForDeletion', async function markForDeletion() {
this.marked_for_deletion = true;
this.hard_delete_time = new Date(Date.now() + (7 * 24 * 3600 * 1000)); // * 7 day grace period
if (this.connections?.stripe?.subscription_id) {
const subscriptionID = this.connections.stripe.subscription_id;
try {
if (stripe) {
// * If a user has an active subscription when they mark themselves for deletion, then they
// * may get charged again in those 7 days while not having access to their account. To prevent
// * that, just update the subscription to cancel at the end of the period. That way the charge
// * doesn't happen, and the user likely won't be restoring their account anyway. If they do
// * restore the account and do want their subscription back then they can create a new one
// * after this one expires which is effectively the same as the old subscription renewing.
// * Pausing collection is another option however it requires much more effort on our end to
// * properly resume the paused charges and recitify any missed ones to prevent invoices
// * from being skipped. This method is just way easier for us to deal with right now, at the
// * expense of making the user do a tad more work on their end
await stripe.subscriptions.update(subscriptionID, {
cancel_at_period_end: true
});
} else {
LOG_WARN(`UPDATING SUBSCRIPTION FOR USER ${this.username}. HAS STRIPE DATA UDER ID ${this.connections.stripe.customer_id}, BUT STRIPE CLIENT NOT ENABLED.`);
}
} catch (error) {
LOG_ERROR(`ERROR UPDATING SUBSCRIPTION FOR USER ${this.username} (${subscriptionID}). ${error}`);
}
}
});
PNIDSchema.method('scrub', async function scrub() {

View File

@@ -21,7 +21,7 @@ export async function deleteAccount(request: DeleteAccountRequest): Promise<Dele
if (request.bypassGracePeriod) {
await pnid.scrub();
} else {
pnid.markForDeletion();
await pnid.markForDeletion();
}
await pnid.save();

View File

@@ -17,7 +17,7 @@ export async function deleteAccount(request: DeleteAccountRequest): Promise<Dele
try {
const email = pnid.email.address;
pnid.markForDeletion();
await pnid.markForDeletion();
await pnid.save();
await sendPNIDDeletedEmail(email, pnid.username);

View File

@@ -580,7 +580,7 @@ router.post('/@me/deletion', async (request: express.Request, response: express.
const email = pnid.email.address;
pnid.markForDeletion();
await pnid.markForDeletion();
await pnid.save();
try {

View File

@@ -281,14 +281,24 @@ export async function sendForgotPasswordEmail(pnid: mongoose.HydratedDocument<IP
}
export async function sendPNIDDeletedEmail(emailAddress: string, username: string): Promise<void> {
const deletionDate = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000).toLocaleString('en-US', {
timeZone: 'UTC',
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric'
});
const email = new CreateEmail()
.addHeader('Dear {{pnid}},', { pnid: username })
.addParagraph('your PNID has successfully been deleted.')
.addParagraph('If you had a tier subscription, a separate cancellation email will be sent. If you do not receive this cancellation email, or you are still being charged for your subscription, please contact <b>@jonbarrow</b> on our [Discord server](https://discord.pretendo.network/).');
.addHeader('Dear {{pnid}}.', { pnid: username })
.addParagraph('Your PNID has been scheduled for deletion.')
.addParagraph(`Your account and related data will be permanently deleted in 7 days (${deletionDate}). Note that this will not free the username associated with the account for use in future accounts.`)
.addParagraph('You may restore your account at any time before the deletion date. To do so, email [restore-account@pretendo.network](mailto:restore-account@pretendo.network?subject=Requesting%20account%20restore&body=Please%20restore%20my%20account) from the email address used to register, with the subject "Requesting account restore" and your PNID username in the body. Requests must be submitted more than 24 hours before the deletion date, as after this point your data may be unrecoverable. For additional help, visit our [Forum](https://forum.pretendo.network/) or [Discord server](https://discord.pretendo.network/).')
.addParagraph('If you have or have had an active tier subscription, your associated Stripe data (including payment info and invoices) will be permanently deleted on the deletion date and cannot be restored.')
.addParagraph('No new charges will be made during the grace period, even if a renewal would normally occur. If your account is restored with an active subscription, you may need to resubscribe. If you notice unexpected charges during the grace period, please contact us via our [Forum](https://forum.pretendo.network/) or [Discord server](https://discord.pretendo.network/) before the deletion date.');
const options = {
to: emailAddress,
subject: '[Pretendo Network] PNID Deleted',
subject: '[Pretendo Network] PNID Deletion',
email
};