mirror of
https://github.com/PretendoNetwork/account.git
synced 2026-09-30 22:28:00 -05:00
Renamed user variables to better match their types
This commit is contained in:
@@ -85,19 +85,19 @@ export async function getUserBasic(token: string): Promise<HydratedPNIDDocument
|
||||
const username: string = parts[0];
|
||||
const password: string = parts[1];
|
||||
|
||||
const user: HydratedPNIDDocument | null = await getUserByUsername(username);
|
||||
const pnid: HydratedPNIDDocument | null = await getUserByUsername(username);
|
||||
|
||||
if (!user) {
|
||||
if (!pnid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const hashedPassword: string = nintendoPasswordHash(password, user.pid);
|
||||
const hashedPassword: string = nintendoPasswordHash(password, pnid.pid);
|
||||
|
||||
if (!bcrypt.compareSync(hashedPassword, user.password)) {
|
||||
if (!bcrypt.compareSync(hashedPassword, pnid.password)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return user;
|
||||
return pnid;
|
||||
}
|
||||
|
||||
export async function getUserBearer(token: string): Promise<HydratedPNIDDocument | null> {
|
||||
@@ -107,9 +107,9 @@ export async function getUserBearer(token: string): Promise<HydratedPNIDDocument
|
||||
const decryptedToken: Buffer = await decryptToken(Buffer.from(token, 'base64'));
|
||||
const unpackedToken: Token = unpackToken(decryptedToken);
|
||||
|
||||
const user: HydratedPNIDDocument | null = await getUserByPID(unpackedToken.pid);
|
||||
const pnid: HydratedPNIDDocument | null = await getUserByPID(unpackedToken.pid);
|
||||
|
||||
if (user) {
|
||||
if (pnid) {
|
||||
const expireTime: number = Math.floor((Number(unpackedToken.expire_time) / 1000));
|
||||
|
||||
if (Math.floor(Date.now() / 1000) > expireTime) {
|
||||
@@ -117,7 +117,7 @@ export async function getUserBearer(token: string): Promise<HydratedPNIDDocument
|
||||
}
|
||||
}
|
||||
|
||||
return user;
|
||||
return pnid;
|
||||
} catch (error: any) {
|
||||
// TODO: Handle error
|
||||
LOG_ERROR(error);
|
||||
@@ -128,13 +128,13 @@ export async function getUserBearer(token: string): Promise<HydratedPNIDDocument
|
||||
export async function getUserProfileJSONByPID(pid: number): Promise<PNIDProfile | null> {
|
||||
verifyConnected();
|
||||
|
||||
const user: HydratedPNIDDocument | null = await getUserByPID(pid);
|
||||
const pnid: HydratedPNIDDocument | null = await getUserByPID(pid);
|
||||
|
||||
if (!user) {
|
||||
if (!pnid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const device: IDevice = user.devices[0]; // * Just grab the first device
|
||||
const device: IDevice = pnid.devices[0]; // * Just grab the first device
|
||||
let device_attributes: {
|
||||
device_attribute: {
|
||||
name: string;
|
||||
@@ -161,50 +161,50 @@ export async function getUserProfileJSONByPID(pid: number): Promise<PNIDProfile
|
||||
|
||||
return {
|
||||
//accounts: {}, // * We need to figure this out, no idea what these values mean or what they do
|
||||
active_flag: user.flags.active ? 'Y' : 'N',
|
||||
birth_date: user.birthdate,
|
||||
country: user.country,
|
||||
create_date: user.creation_date,
|
||||
active_flag: pnid.flags.active ? 'Y' : 'N',
|
||||
birth_date: pnid.birthdate,
|
||||
country: pnid.country,
|
||||
create_date: pnid.creation_date,
|
||||
device_attributes: device_attributes,
|
||||
gender: user.gender,
|
||||
language: user.language,
|
||||
updated: user.updated,
|
||||
marketing_flag: user.flags.marketing ? 'Y' : 'N',
|
||||
off_device_flag: user.flags.off_device ? 'Y' : 'N',
|
||||
pid: user.pid,
|
||||
gender: pnid.gender,
|
||||
language: pnid.language,
|
||||
updated: pnid.updated,
|
||||
marketing_flag: pnid.flags.marketing ? 'Y' : 'N',
|
||||
off_device_flag: pnid.flags.off_device ? 'Y' : 'N',
|
||||
pid: pnid.pid,
|
||||
email: {
|
||||
address: user.email.address,
|
||||
id: user.email.id,
|
||||
parent: user.email.parent ? 'Y' : 'N',
|
||||
primary: user.email.primary ? 'Y' : 'N',
|
||||
reachable: user.email.reachable ? 'Y' : 'N',
|
||||
address: pnid.email.address,
|
||||
id: pnid.email.id,
|
||||
parent: pnid.email.parent ? 'Y' : 'N',
|
||||
primary: pnid.email.primary ? 'Y' : 'N',
|
||||
reachable: pnid.email.reachable ? 'Y' : 'N',
|
||||
type: 'DEFAULT',
|
||||
updated_by: 'USER', // * Can also be INTERNAL WS, don't know the difference
|
||||
validated: user.email.validated ? 'Y' : 'N',
|
||||
validated_date: user.email.validated ? user.email.validated_date : ''
|
||||
validated: pnid.email.validated ? 'Y' : 'N',
|
||||
validated_date: pnid.email.validated ? pnid.email.validated_date : ''
|
||||
},
|
||||
mii: {
|
||||
status: 'COMPLETED',
|
||||
data: user.mii.data.replace(/(\r\n|\n|\r)/gm, ''),
|
||||
id: user.mii.id,
|
||||
mii_hash: user.mii.hash,
|
||||
data: pnid.mii.data.replace(/(\r\n|\n|\r)/gm, ''),
|
||||
id: pnid.mii.id,
|
||||
mii_hash: pnid.mii.hash,
|
||||
mii_images: {
|
||||
mii_image: {
|
||||
// * Images MUST be loaded over HTTPS or console ignores them
|
||||
// * Bunny CDN is the only CDN which seems to support TLS 1.0/1.1 (required)
|
||||
cached_url: `${config.cdn.base_url}/mii/${user.pid}/standard.tga`,
|
||||
id: user.mii.image_id,
|
||||
url: `${config.cdn.base_url}/mii/${user.pid}/standard.tga`,
|
||||
cached_url: `${config.cdn.base_url}/mii/${pnid.pid}/standard.tga`,
|
||||
id: pnid.mii.image_id,
|
||||
url: `${config.cdn.base_url}/mii/${pnid.pid}/standard.tga`,
|
||||
type: 'standard'
|
||||
}
|
||||
},
|
||||
name: user.mii.name,
|
||||
primary: user.mii.primary ? 'Y' : 'N',
|
||||
name: pnid.mii.name,
|
||||
primary: pnid.mii.primary ? 'Y' : 'N',
|
||||
},
|
||||
region: user.region,
|
||||
tz_name: user.timezone.name,
|
||||
user_id: user.username,
|
||||
utc_offset: user.timezone.offset
|
||||
region: pnid.region,
|
||||
tz_name: pnid.timezone.name,
|
||||
user_id: pnid.username,
|
||||
utc_offset: pnid.timezone.offset
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -11,9 +11,9 @@ async function APIMiddleware(request: express.Request, _response: express.Respon
|
||||
}
|
||||
|
||||
const token: string = authHeader.split(' ')[1];
|
||||
const user: HydratedPNIDDocument | null = await getUserBearer(token);
|
||||
const pnid: HydratedPNIDDocument | null = await getUserBearer(token);
|
||||
|
||||
request.pnid = user;
|
||||
request.pnid = pnid;
|
||||
|
||||
return next();
|
||||
}
|
||||
|
||||
@@ -174,14 +174,14 @@ async function NASCMiddleware(request: express.Request, response: express.Respon
|
||||
}
|
||||
}
|
||||
|
||||
const nexUser: HydratedNEXAccountDocument | null = await NEXAccount.findOne({ pid });
|
||||
const nexAccount: HydratedNEXAccountDocument | null = await NEXAccount.findOne({ pid });
|
||||
|
||||
if (!nexUser || nexUser.access_level < 0) {
|
||||
if (!nexAccount || nexAccount.access_level < 0) {
|
||||
response.status(200).send(nascError('102'));
|
||||
return;
|
||||
}
|
||||
|
||||
request.nexUser = nexUser;
|
||||
request.nexAccount = nexAccount;
|
||||
|
||||
return next();
|
||||
}
|
||||
|
||||
@@ -14,19 +14,19 @@ async function PNIDMiddleware(request: express.Request, response: express.Respon
|
||||
const parts: string[] = authHeader.split(' ');
|
||||
const type: string = parts[0];
|
||||
let token: string = parts[1];
|
||||
let user: HydratedPNIDDocument | null;
|
||||
let pnid: HydratedPNIDDocument | null;
|
||||
|
||||
if (request.isCemu) {
|
||||
token = Buffer.from(token, 'hex').toString('base64');
|
||||
}
|
||||
|
||||
if (type === 'Basic') {
|
||||
user = await getUserBasic(token);
|
||||
pnid = await getUserBasic(token);
|
||||
} else {
|
||||
user = await getUserBearer(token);
|
||||
pnid = await getUserBearer(token);
|
||||
}
|
||||
|
||||
if (!user) {
|
||||
if (!pnid) {
|
||||
response.status(401);
|
||||
|
||||
if (type === 'Bearer') {
|
||||
@@ -55,7 +55,7 @@ async function PNIDMiddleware(request: express.Request, response: express.Respon
|
||||
return;
|
||||
}
|
||||
|
||||
if (user.access_level < 0) {
|
||||
if (pnid.access_level < 0) {
|
||||
response.status(400).send(xmlbuilder.create({
|
||||
errors: {
|
||||
error: {
|
||||
@@ -68,7 +68,7 @@ async function PNIDMiddleware(request: express.Request, response: express.Respon
|
||||
return;
|
||||
}
|
||||
|
||||
request.pnid = user;
|
||||
request.pnid = pnid;
|
||||
|
||||
return next();
|
||||
}
|
||||
|
||||
@@ -35,9 +35,9 @@ router.post('/', async (request: express.Request, response: express.Response) =>
|
||||
async function processLoginRequest(request: express.Request): Promise<URLSearchParams> {
|
||||
const requestParams: NASCRequestParams = request.body;
|
||||
const titleID: string = nintendoBase64Decode(requestParams.titleid).toString();
|
||||
const nexUser: HydratedNEXAccountDocument | null = request.nexUser;
|
||||
const nexAccount: HydratedNEXAccountDocument | null = request.nexAccount;
|
||||
|
||||
if (!nexUser) {
|
||||
if (!nexAccount) {
|
||||
// TODO - Research this error more
|
||||
return nascError('null');
|
||||
}
|
||||
@@ -47,7 +47,7 @@ async function processLoginRequest(request: express.Request): Promise<URLSearchP
|
||||
// THAT WAY EVERYONE CAN GET AN ASSIGNED PID
|
||||
let serverAccessLevel: string = 'test';
|
||||
if (titleID !== '0004013000003202') {
|
||||
serverAccessLevel = nexUser.server_access_level;
|
||||
serverAccessLevel = nexAccount.server_access_level;
|
||||
}
|
||||
|
||||
const server: HydratedServerDocument | null = await getServerByTitleId(titleID, serverAccessLevel);
|
||||
@@ -71,7 +71,7 @@ async function processLoginRequest(request: express.Request): Promise<URLSearchP
|
||||
const tokenOptions: TokenOptions = {
|
||||
system_type: 0x2, // 3DS
|
||||
token_type: 0x3, // nex token,
|
||||
pid: nexUser.pid,
|
||||
pid: nexAccount.pid,
|
||||
access_level: 0,
|
||||
title_id: BigInt(parseInt(titleID, 16)),
|
||||
expire_time: BigInt(Date.now() + (3600 * 1000))
|
||||
|
||||
@@ -210,11 +210,11 @@ router.get('/nex_token/@me', async (request: express.Request, response: express.
|
||||
expire_time: BigInt(Date.now() + (3600 * 1000))
|
||||
};
|
||||
|
||||
const nexUser: HydratedNEXAccountDocument | null = await NEXAccount.findOne({
|
||||
const nexAccount: HydratedNEXAccountDocument | null = await NEXAccount.findOne({
|
||||
owning_pid: pnid.pid
|
||||
});
|
||||
|
||||
if (!nexUser) {
|
||||
if (!nexAccount) {
|
||||
return response.status(404).send(xmlbuilder.create({
|
||||
errors: {
|
||||
error: {
|
||||
@@ -237,8 +237,8 @@ router.get('/nex_token/@me', async (request: express.Request, response: express.
|
||||
response.send(xmlbuilder.create({
|
||||
nex_token: {
|
||||
host: ip,
|
||||
nex_password: nexUser.password,
|
||||
pid: nexUser.pid,
|
||||
nex_password: nexAccount.password,
|
||||
pid: nexAccount.pid,
|
||||
port: port,
|
||||
token: nexToken
|
||||
}
|
||||
|
||||
2
src/types/express.d.ts
vendored
2
src/types/express.d.ts
vendored
@@ -6,7 +6,7 @@ declare global {
|
||||
namespace Express {
|
||||
interface Request {
|
||||
pnid: HydratedPNIDDocument | null;
|
||||
nexUser: HydratedNEXAccountDocument | null;
|
||||
nexAccount: HydratedNEXAccountDocument | null;
|
||||
isCemu?: boolean;
|
||||
files?: Record<string, any>;
|
||||
certificate?: NintendoCertificate;
|
||||
|
||||
Reference in New Issue
Block a user