From 7000eff5a045dd97f7cf4288bc73bb75ad5c7fd7 Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Sat, 20 Jul 2024 12:31:54 +0200 Subject: [PATCH] Create Account.ts model --- src/models/Account.ts | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/models/Account.ts diff --git a/src/models/Account.ts b/src/models/Account.ts new file mode 100644 index 0000000..cf12bcc --- /dev/null +++ b/src/models/Account.ts @@ -0,0 +1,51 @@ +import {Schema, ObjectId, model} from "mongoose"; +import speakeasy from "speakeasy"; + +export interface IAccount { + _id: ObjectId, + username: string, + email: string, + password: string, + verified: boolean, + verificationSecret: number | undefined, + totpSecret?: string, + totpEnabled: boolean, + allowInvites: boolean +} + +const AccountSchema = new Schema({ + username: { + type: String, + required: true + }, + email: { + type: String, + required: true, + }, + password: { + type: String, + required: true + }, + verificationSecret: { + type: Number, + default: () => Math.floor(Math.random() * (999999 - 100000 + 1)) + 100000 + }, + verified: { + type: Boolean, + default: false + }, + totpSecret: { + type: String, + default: () => speakeasy.generateSecret({name: "LicenseAPI"}).base32 + }, + totpEnabled: { + type: Boolean, + default: false + }, + allowInvites: { + type: Boolean, + default: true + } +}); + +export const Account = model("accounts", AccountSchema); \ No newline at end of file