From 9e8a39967fc5c4e6c6f89b15f84dca3854adc3b0 Mon Sep 17 00:00:00 2001 From: Jonathan Barrow Date: Mon, 13 Sep 2021 22:15:54 -0400 Subject: [PATCH] Quick PNID fixes for new NEX account backend --- src/models/pnid.js | 2 +- src/services/account/routes/people.js | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/models/pnid.js b/src/models/pnid.js index 387da94..f015dde 100644 --- a/src/models/pnid.js +++ b/src/models/pnid.js @@ -215,7 +215,7 @@ PNIDSchema.pre('save', async function(next) { } this.set('usernameLower', this.get('username').toLowerCase()); - await this.generatePID(); + //await this.generatePID(); await this.generateEmailValidationCode(); await this.generateEmailValidationToken(); await this.generateMiiImages(); diff --git a/src/services/account/routes/people.js b/src/services/account/routes/people.js index 40e659d..b799453 100644 --- a/src/services/account/routes/people.js +++ b/src/services/account/routes/people.js @@ -64,10 +64,18 @@ router.post('/', clientHeaderCheck, ratelimit, deviceCertificateMiddleware, asyn }).end()); } + // Create new NEX account + const newNEXAccount = new NEXAccount({ + pid: 0, + password: '', + owning_pid: 0, + }); + await newNEXAccount.save(); + const creationDate = moment().format('YYYY-MM-DDTHH:MM:SS'); const document = { - pid: 1, // will be overwritten before saving + pid: newNEXAccount.get('pid'), creation_date: creationDate, updated: creationDate, username: person.get('user_id'), @@ -112,10 +120,16 @@ router.post('/', clientHeaderCheck, ratelimit, deviceCertificateMiddleware, asyn const newPNID = new PNID(document); await newPNID.save(); - const newNEXAccount = new NEXAccount({ - owning_pid: newPNID.get('pid'), + // Quick hack to get the PIDs to match + // TODO: Change this + // NN with a NNID will always use the NNID PID + // even if the provided NEX PID is different + // To fix this we make them the same PID + await NEXAccount.updateOne({ + pid: newNEXAccount.get('pid') + }, { + owning_pid: newNEXAccount.get('pid') }); - await newNEXAccount.save(); await mailer.send( newPNID.get('email'),