Skip to content

Commit bc406ec

Browse files
Merge pull request #99 from ItzSwirlz/dev
Implement email confirmation for parental controls (send_confirmation/pin/:email)
2 parents 25c9b8b + 4058d42 commit bc406ec

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

src/services/nnas/routes/support.ts

+32-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import dns from 'node:dns';
22
import express from 'express';
33
import xmlbuilder from 'xmlbuilder';
44
import moment from 'moment';
5-
import { getPNIDByPID } from '@/database';
6-
import { sendEmailConfirmedEmail, sendConfirmationEmail, sendForgotPasswordEmail } from '@/util';
5+
import { getPNIDByEmailAddress, getPNIDByPID } from '@/database';
6+
import { sendEmailConfirmedEmail, sendConfirmationEmail, sendForgotPasswordEmail, sendEmailConfirmedParentalControlsEmail } from '@/util';
77

88
const router = express.Router();
99

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

128+
/**
129+
* [GET]
130+
* Replacement for: https://account.nintendo.net/v1/api/support/send_confirmation/pin/:email
131+
* Description: Sends a users confirmation email that their email has been registered for parental controls
132+
*/
133+
router.get('/send_confirmation/pin/:email', async (request: express.Request, response: express.Response): Promise<void> => {
134+
const email = request.params.email;
135+
136+
const pnid = await getPNIDByEmailAddress(email);
137+
138+
if (!pnid) {
139+
// TODO - Unsure if this is the right error
140+
response.status(400).send(xmlbuilder.create({
141+
errors: {
142+
error: {
143+
code: '0130',
144+
message: 'PID has not been registered yet'
145+
}
146+
}
147+
}).end());
148+
149+
return;
150+
}
151+
152+
await sendEmailConfirmedParentalControlsEmail(pnid);
153+
154+
response.status(200).send('');
155+
});
156+
128157
/**
129158
* [GET]
130159
* Replacement for: https://account.nintendo.net/v1/api/support/forgotten_password/PID
@@ -156,4 +185,4 @@ router.get('/forgotten_password/:pid', async (request: express.Request, response
156185
response.status(200).send('');
157186
});
158187

159-
export default router;
188+
export default router;

src/util.ts

+12
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,18 @@ export async function sendEmailConfirmedEmail(pnid: mongoose.HydratedDocument<IP
224224
await sendMail(options);
225225
}
226226

227+
export async function sendEmailConfirmedParentalControlsEmail(pnid: mongoose.HydratedDocument<IPNID, IPNIDMethods>): Promise<void> {
228+
const options = {
229+
to: pnid.email.address,
230+
subject: '[Pretendo Network] Email address confirmed for Parental Controls',
231+
username: pnid.username,
232+
paragraph: 'your email address has been confirmed for use with Parental Controls.',
233+
text: `Dear ${pnid.username}, \r\n\r\nYour email address has been confirmed for use with Parental Controls.`
234+
};
235+
236+
await sendMail(options);
237+
}
238+
227239
export async function sendForgotPasswordEmail(pnid: mongoose.HydratedDocument<IPNID, IPNIDMethods>): Promise<void> {
228240
const tokenOptions = {
229241
system_type: 0xF, // * API

0 commit comments

Comments
 (0)