mirror of
https://github.com/gnmyt/LicenseAPI.git
synced 2026-01-11 18:51:47 +00:00
Create Account.ts model
This commit is contained in:
51
src/models/Account.ts
Normal file
51
src/models/Account.ts
Normal file
@ -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<IAccount>({
|
||||
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<IAccount>("accounts", AccountSchema);
|
||||
Reference in New Issue
Block a user