Compare commits
2 Commits
f7dd1e4a58
...
91fe66b202
Author | SHA1 | Date | |
---|---|---|---|
91fe66b202 | |||
59fb43feda |
@ -1,7 +1,6 @@
|
||||
import { AbstractUser } from "../src/server/interfaces/index.js";
|
||||
import { ObjectId } from 'mongodb';
|
||||
import { LoggerClientOptions } from '@navy.gif/logger';
|
||||
import { MariaOptions, MongoOptions } from '@navy.gif/wrappers';
|
||||
import { MariaOptions, MongoOptions, ObjectId } from '@navy.gif/wrappers';
|
||||
import { Request as ExpressRequest, Response as ExpressResponse, NextFunction } from "express";
|
||||
import http from 'http';
|
||||
import { UploadedFile } from "express-fileupload";
|
||||
@ -167,3 +166,9 @@ export type EndpointOptions = {
|
||||
auth?: MiddlewareFunction | true | null,
|
||||
loadOrder?: number
|
||||
}
|
||||
|
||||
export type RegistrationInvite = {
|
||||
code: string,
|
||||
validFor: number,
|
||||
created: number
|
||||
}
|
@ -15,7 +15,7 @@
|
||||
"@navy.gif/commandparser": "^1.4.5",
|
||||
"@navy.gif/logger": "^2.3.3",
|
||||
"@navy.gif/passport-discord": "^0.2.2-b",
|
||||
"@navy.gif/wrappers": "^1.3.11",
|
||||
"@navy.gif/wrappers": "^1.3.12",
|
||||
"@types/cors": "^2.8.13",
|
||||
"@types/express-fileupload": "^1.4.1",
|
||||
"@types/express-session": "^1.17.7",
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { OptionType, CommandOptionDefinition, ArgsResult } from '@navy.gif/commandparser';
|
||||
import { OptionType, ArgsResult } from '@navy.gif/commandparser';
|
||||
import BaseCommand from '../BaseCommand.js';
|
||||
import Controller from '../Controller.js';
|
||||
import { IPCMessage, SignupCode } from '../../../@types/Other.js';
|
||||
@ -12,13 +12,13 @@ class CreateCommand extends BaseCommand {
|
||||
name: 'registration-code',
|
||||
aliases: [ 'code' ],
|
||||
type: OptionType.SUB_COMMAND,
|
||||
options: [ {
|
||||
options: [{
|
||||
name: 'amount',
|
||||
flag: true,
|
||||
type: OptionType.INTEGER,
|
||||
valueOptional: true,
|
||||
defaultValue: 1
|
||||
} as CommandOptionDefinition ]
|
||||
}]
|
||||
}]
|
||||
});
|
||||
|
||||
@ -37,8 +37,13 @@ class CreateCommand extends BaseCommand {
|
||||
const response = await shard.send(msg, true);
|
||||
if (!response)
|
||||
return 'Did not get a response from shard';
|
||||
const code = response.code as SignupCode;
|
||||
return `Code ${code.code}, valid until ${new Date(code.created + code.validFor).toUTCString()}`;
|
||||
|
||||
const codes = response.codes as SignupCode[];
|
||||
let out = `Created codes, valid until ${new Date(codes[0].created + codes[0].validFor).toUTCString()}:\n`;
|
||||
for (const invite of codes)
|
||||
out += `${invite.code}\n`;
|
||||
|
||||
return out;
|
||||
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ import { Authenticator, RateLimiter } from './middleware/index.js';
|
||||
import { UserDatabaseInterface } from './interfaces/index.js';
|
||||
import { ExternalProfile, OAuthProvider, Request, Response, ServerOptions, SessionLimit } from '../../@types/Server.js';
|
||||
import { MongoMemory } from './database/index.js';
|
||||
import { IPCMessage } from '../../@types/Other.js';
|
||||
import { IPCMessage, SignupCode } from '../../@types/Other.js';
|
||||
import { DoneCallback } from 'passport';
|
||||
|
||||
// const pkg = JSON.parse(readFileSync('../../package.json', { encoding: 'utf8' }));
|
||||
@ -292,8 +292,13 @@ class Server extends EventEmitter {
|
||||
if (!process.send)
|
||||
throw new Error('Missing process.send???');
|
||||
if (msg.type === 'reqregcode') {
|
||||
const codes: SignupCode[] = [];
|
||||
const amount = msg.amount as number;
|
||||
for (let i = 0; i < amount; i++) {
|
||||
const code = await this.users.createRegistrationCode();
|
||||
process.send({ _id: msg._id, code });
|
||||
codes.push(code);
|
||||
}
|
||||
process.send({ _id: msg._id, codes });
|
||||
}
|
||||
}
|
||||
|
||||
@ -366,6 +371,18 @@ class Server extends EventEmitter {
|
||||
return this.#_port;
|
||||
}
|
||||
|
||||
get mongodb () {
|
||||
return this.#_mongodb;
|
||||
}
|
||||
|
||||
get memoryStoreProvider () {
|
||||
return this.#_memoryStoreProvider;
|
||||
}
|
||||
|
||||
get mariadb () {
|
||||
return this.#_mariadb;
|
||||
}
|
||||
|
||||
get users () {
|
||||
return this.#_userDatabase;
|
||||
}
|
||||
|
@ -1,21 +1,14 @@
|
||||
// const { Collection } = require("@discordjs/collection");
|
||||
// const { ObjectId } = require("mongodb");
|
||||
|
||||
// const { UserDatabaseInterface, Entity } = require("../interfaces/");
|
||||
// const { User, UserApplication, Role } = require("../structures");
|
||||
// const { Util } = require("../../util");
|
||||
|
||||
import { Collection } from '@discordjs/collection';
|
||||
import { ObjectId, Document } from 'mongodb';
|
||||
|
||||
import { LoggerClient } from '@navy.gif/logger';
|
||||
import { MongoDB } from '@navy.gif/wrappers';
|
||||
import { MongoDB, ObjectId, Document } from '@navy.gif/wrappers';
|
||||
|
||||
import Server from "../Server.js";
|
||||
import { Entity, UserDatabaseInterface } from "../interfaces/index.js";
|
||||
import { Role, User, UserApplication } from "../structures/index.js";
|
||||
import { ApplicationData, ExternalProfile, RoleData, UserData } from '../../../@types/Server.js';
|
||||
import { Util } from '../../util/index.js';
|
||||
import { SignupCode } from '../../../@types/Other.js';
|
||||
|
||||
type UserDBOptions = {
|
||||
userCollection?: string,
|
||||
@ -380,7 +373,7 @@ class UserDatabase implements UserDatabaseInterface {
|
||||
* @param {number} [validFor=1] Amount of days the code is valid
|
||||
* @memberof UserDatabase
|
||||
*/
|
||||
async createRegistrationCode (validFor = 1) {
|
||||
async createRegistrationCode (validFor = 1): Promise<SignupCode> {
|
||||
const string = Util.randomString();
|
||||
const now = Date.now();
|
||||
const obj = { code: string, validFor: validFor * 24 * 60 * 60 * 1000, created: now };
|
||||
|
@ -1,11 +1,8 @@
|
||||
// const { ObjectId } = require("mongodb");
|
||||
// const { PermissionManager } = require("../../util");
|
||||
// const UserDatabaseInterface = require("./UserDatabaseInterface");
|
||||
import { ObjectId } from 'mongodb';
|
||||
import { PermissionManager } from '../../util/index.js';
|
||||
import UserDatabaseInterface from './UserDatabaseInterface.js';
|
||||
import Server from '../Server.js';
|
||||
import { EntityData, EntityJson, Permissions } from '../../../@types/Server.js';
|
||||
import { ObjectId } from '@navy.gif/wrappers';
|
||||
|
||||
// API entity superclass
|
||||
class Entity {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { DeleteResult } from 'mongodb';
|
||||
import { DeleteResult } from "@navy.gif/wrappers";
|
||||
import { SignupCode } from "../../../@types/Other.js";
|
||||
import { ApplicationData, ExternalProfile, RoleData } from "../../../@types/Server.js";
|
||||
import { Role, User, UserApplication } from "../structures/index.js";
|
||||
|
@ -1,10 +1,10 @@
|
||||
// const { AbstractUser } = require("../interfaces");
|
||||
// const { ObjectId } = require("mongodb");
|
||||
|
||||
import { ObjectId } from "@navy.gif/wrappers";
|
||||
import { ApplicationData } from "../../../@types/Server.js";
|
||||
import Server from "../Server.js";
|
||||
import { AbstractUser } from "../interfaces/index.js";
|
||||
import { ObjectId } from 'mongodb';
|
||||
|
||||
class UserApplication extends AbstractUser {
|
||||
|
||||
|
@ -61,7 +61,6 @@ class PermissionManager {
|
||||
const resolveables = perm.split(':');
|
||||
let selector = null;
|
||||
|
||||
|
||||
if (typeof perms.developer === 'number' && perms.developer > 0
|
||||
|| typeof perms.developer === 'object' && typeof perms.developer.default === 'number' && perms.developer?.default > 0)
|
||||
return true;
|
||||
|
10
yarn.lock
10
yarn.lock
@ -1773,15 +1773,15 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@navy.gif/wrappers@npm:^1.3.11":
|
||||
version: 1.3.11
|
||||
resolution: "@navy.gif/wrappers@npm:1.3.11"
|
||||
"@navy.gif/wrappers@npm:^1.3.12":
|
||||
version: 1.3.12
|
||||
resolution: "@navy.gif/wrappers@npm:1.3.12"
|
||||
dependencies:
|
||||
amqp-connection-manager: ^4.1.12
|
||||
amqplib: ^0.10.3
|
||||
mongodb: ^5.2.0
|
||||
mysql: ^2.18.1
|
||||
checksum: e0170f5e0d78e77e464781f6c00fb979fa86a4360faea31df832b64b78799182234656b97098bb8e1c8b2ca0ef5558e477f59c6cb51d1dce01ab8d2c6547dc4a
|
||||
checksum: 4e95129ff4dfb43037ebb47d55ab16be730cbf43030c5b75e1adc7f92251f92e8abc689ebe429ae3b60f2efc5761c3c78e617e72470c68fc9818bd431a0f4de3
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@ -7038,7 +7038,7 @@ __metadata:
|
||||
"@navy.gif/commandparser": ^1.4.5
|
||||
"@navy.gif/logger": ^2.3.3
|
||||
"@navy.gif/passport-discord": ^0.2.2-b
|
||||
"@navy.gif/wrappers": ^1.3.11
|
||||
"@navy.gif/wrappers": ^1.3.12
|
||||
"@types/cors": ^2.8.13
|
||||
"@types/express-fileupload": ^1.4.1
|
||||
"@types/express-session": ^1.17.7
|
||||
|
Loading…
Reference in New Issue
Block a user