✨ use new config
This commit is contained in:
+22
-15
@@ -1,6 +1,7 @@
|
||||
import Ajv, { JSONSchemaType } from "ajv"
|
||||
// @ts-nocheck
|
||||
import Ajv, { JSONSchemaType } from "ajv";
|
||||
import { getConfigPathForFile } from "@fosscord/server-util/dist/util/Config";
|
||||
import {Config} from "@fosscord/server-util"
|
||||
import { Config } from "@fosscord/server-util";
|
||||
|
||||
export interface RateLimitOptions {
|
||||
count: number;
|
||||
@@ -95,11 +96,10 @@ export interface DefaultOptions {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
const schema: JSONSchemaType<DefaultOptions> & {
|
||||
definitions: {
|
||||
rateLimitOptions: JSONSchemaType<RateLimitOptions>
|
||||
}
|
||||
rateLimitOptions: JSONSchemaType<RateLimitOptions>;
|
||||
};
|
||||
} = {
|
||||
type: "object",
|
||||
definitions: {
|
||||
@@ -107,10 +107,10 @@ const schema: JSONSchemaType<DefaultOptions> & {
|
||||
type: "object",
|
||||
properties: {
|
||||
count: { type: "number" },
|
||||
timespan: { type: "number" },
|
||||
timespan: { type: "number" }
|
||||
},
|
||||
required: ["count", "timespan"],
|
||||
},
|
||||
required: ["count", "timespan"]
|
||||
}
|
||||
},
|
||||
properties: {
|
||||
gateway: {
|
||||
@@ -238,8 +238,8 @@ const schema: JSONSchemaType<DefaultOptions> & {
|
||||
auth: {
|
||||
type: "object",
|
||||
properties: {
|
||||
login: { $ref: '#/definitions/rateLimitOptions' },
|
||||
register: { $ref: '#/definitions/rateLimitOptions' }
|
||||
login: { $ref: "#/definitions/rateLimitOptions" },
|
||||
register: { $ref: "#/definitions/rateLimitOptions" }
|
||||
},
|
||||
nullable: true,
|
||||
required: [],
|
||||
@@ -348,18 +348,25 @@ const schema: JSONSchemaType<DefaultOptions> & {
|
||||
additionalProperties: false
|
||||
}
|
||||
},
|
||||
required: ["allowMultipleAccounts", "allowNewRegistration", "dateOfBirth", "email", "password", "requireCaptcha", "requireInvite"],
|
||||
required: [
|
||||
"allowMultipleAccounts",
|
||||
"allowNewRegistration",
|
||||
"dateOfBirth",
|
||||
"email",
|
||||
"password",
|
||||
"requireCaptcha",
|
||||
"requireInvite"
|
||||
],
|
||||
additionalProperties: false
|
||||
},
|
||||
}
|
||||
},
|
||||
required: ["gateway", "general", "limits", "login", "permissions", "register", "security"],
|
||||
additionalProperties: false
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
const ajv = new Ajv();
|
||||
const validator = ajv.compile(schema);
|
||||
|
||||
const configPath = getConfigPathForFile("fosscord", "api", ".json");
|
||||
|
||||
export const apiConfig = new Config<DefaultOptions>({path: configPath, schemaValidator: validator, schema: schema});
|
||||
export const apiConfig = new Config<DefaultOptions>({ path: configPath, schemaValidator: validator, schema: schema });
|
||||
|
||||
+3
-3
@@ -10,11 +10,11 @@ import {
|
||||
RoleModel,
|
||||
toObject,
|
||||
UserModel,
|
||||
GuildDocument
|
||||
GuildDocument,
|
||||
Config
|
||||
} from "@fosscord/server-util";
|
||||
|
||||
import { HTTPError } from "lambert-server";
|
||||
import * as Config from "./Config";
|
||||
import { emitEvent } from "./Event";
|
||||
import { getPublicUser } from "./User";
|
||||
|
||||
@@ -39,7 +39,7 @@ export async function isMember(user_id: string, guild_id: string) {
|
||||
export async function addMember(user_id: string, guild_id: string, cache?: { guild?: GuildDocument }) {
|
||||
const user = await getPublicUser(user_id, { guilds: true });
|
||||
|
||||
const { maxGuilds } = Config.apiConfig.getAll().limits.user;
|
||||
const { maxGuilds } = Config.get().limits.user;
|
||||
if (user.guilds.length >= maxGuilds) {
|
||||
throw new HTTPError(`You are at the ${maxGuilds} server limit.`, 403);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Config } from "@fosscord/server-util";
|
||||
import "missing-native-js-functions";
|
||||
import * as Config from "./Config";
|
||||
|
||||
const reNUMBER = /[0-9]/g;
|
||||
const reUPPERCASELETTER = /[A-Z]/g;
|
||||
@@ -17,13 +17,7 @@ const blocklist: string[] = []; // TODO: update ones passwordblocklist is stored
|
||||
* Returns: 0 > pw > 1
|
||||
*/
|
||||
export function check(password: string): number {
|
||||
const {
|
||||
minLength,
|
||||
minNumbers,
|
||||
minUpperCase,
|
||||
minSymbols,
|
||||
blockInsecureCommonPasswords,
|
||||
} = Config.apiConfig.getAll().register.password;
|
||||
const { minLength, minNumbers, minUpperCase, minSymbols } = Config.get().register.password;
|
||||
var strength = 0;
|
||||
|
||||
// checks for total password len
|
||||
@@ -51,10 +45,5 @@ export function check(password: string): number {
|
||||
strength = 0;
|
||||
}
|
||||
|
||||
if (blockInsecureCommonPasswords) {
|
||||
if (blocklist.includes(password)) {
|
||||
strength = 0;
|
||||
}
|
||||
}
|
||||
return strength;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user