Skip to content

Commit

Permalink
Merge pull request #99 from ItzSwirlz/dev
Browse files Browse the repository at this point in the history
Implement email confirmation for parental controls (send_confirmation/pin/:email)
  • Loading branch information
binaryoverload authored Feb 1, 2025
2 parents 25c9b8b + 4058d42 commit bc406ec
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
35 changes: 32 additions & 3 deletions src/services/nnas/routes/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import dns from 'node:dns';
import express from 'express';
import xmlbuilder from 'xmlbuilder';
import moment from 'moment';
import { getPNIDByPID } from '@/database';
import { sendEmailConfirmedEmail, sendConfirmationEmail, sendForgotPasswordEmail } from '@/util';
import { getPNIDByEmailAddress, getPNIDByPID } from '@/database';
import { sendEmailConfirmedEmail, sendConfirmationEmail, sendForgotPasswordEmail, sendEmailConfirmedParentalControlsEmail } from '@/util';

const router = express.Router();

Expand Down Expand Up @@ -125,6 +125,35 @@ router.get('/resend_confirmation', async (request: express.Request, response: ex
response.status(200).send('');
});

/**
* [GET]
* Replacement for: https://account.nintendo.net/v1/api/support/send_confirmation/pin/:email
* Description: Sends a users confirmation email that their email has been registered for parental controls
*/
router.get('/send_confirmation/pin/:email', async (request: express.Request, response: express.Response): Promise<void> => {
const email = request.params.email;

const pnid = await getPNIDByEmailAddress(email);

if (!pnid) {
// TODO - Unsure if this is the right error
response.status(400).send(xmlbuilder.create({
errors: {
error: {
code: '0130',
message: 'PID has not been registered yet'
}
}
}).end());

return;
}

await sendEmailConfirmedParentalControlsEmail(pnid);

response.status(200).send('');
});

/**
* [GET]
* Replacement for: https://account.nintendo.net/v1/api/support/forgotten_password/PID
Expand Down Expand Up @@ -156,4 +185,4 @@ router.get('/forgotten_password/:pid', async (request: express.Request, response
response.status(200).send('');
});

export default router;
export default router;
12 changes: 12 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,18 @@ export async function sendEmailConfirmedEmail(pnid: mongoose.HydratedDocument<IP
await sendMail(options);
}

export async function sendEmailConfirmedParentalControlsEmail(pnid: mongoose.HydratedDocument<IPNID, IPNIDMethods>): Promise<void> {
const options = {
to: pnid.email.address,
subject: '[Pretendo Network] Email address confirmed for Parental Controls',
username: pnid.username,
paragraph: 'your email address has been confirmed for use with Parental Controls.',
text: `Dear ${pnid.username}, \r\n\r\nYour email address has been confirmed for use with Parental Controls.`
};

await sendMail(options);
}

export async function sendForgotPasswordEmail(pnid: mongoose.HydratedDocument<IPNID, IPNIDMethods>): Promise<void> {
const tokenOptions = {
system_type: 0xF, // * API
Expand Down

0 comments on commit bc406ec

Please sign in to comment.