First version of OpenAuth remake

This commit is contained in:
Fabian Stamm
2018-11-06 20:48:50 +01:00
commit ac69e73344
89 changed files with 14355 additions and 0 deletions

36
src/models/client.ts Normal file
View File

@ -0,0 +1,36 @@
import DB from "../database";
import { ModelDataBase } from "@hibas123/safe_mongo/lib/model";
import { ObjectID } from "mongodb";
import { v4 } from "uuid";
export interface IClient extends ModelDataBase {
maintainer: ObjectID
internal: boolean
name: string
redirect_url: string
website: string
logo?: string
client_id: string
client_secret: string
}
const Client = DB.addModel<IClient>({
name: "client",
versions: [
{
migration: () => { },
schema: {
maintainer: { type: ObjectID },
internal: { type: Boolean, default: false },
name: { type: String },
redirect_url: { type: String },
website: { type: String },
logo: { type: String, optional: true },
client_id: { type: String, default: () => v4() },
client_secret: { type: String }
}
}
]
})
export default Client;

27
src/models/client_code.ts Normal file
View File

@ -0,0 +1,27 @@
import DB from "../database";
import { ModelDataBase } from "@hibas123/safe_mongo/lib/model";
import { ObjectID } from "mongodb";
import { v4 } from "uuid";
export interface IClientCode extends ModelDataBase {
user: ObjectID
code: string;
client: ObjectID
permissions: ObjectID[]
validTill: Date;
}
const ClientCode = DB.addModel<IClientCode>({
name: "client_code",
versions: [{
migration: () => { },
schema: {
user: { type: ObjectID },
code: { type: String },
client: { type: ObjectID },
permissions: { type: Array },
validTill: { type: Date }
}
}]
});
export default ClientCode;

26
src/models/login_token.ts Normal file
View File

@ -0,0 +1,26 @@
import DB from "../database";
import { ModelDataBase } from "@hibas123/safe_mongo/lib/model";
import { ObjectID } from "mongodb";
export interface ILoginToken extends ModelDataBase {
token: string;
special: boolean;
user: ObjectID;
validTill: Date;
valid: boolean;
}
const LoginToken = DB.addModel<ILoginToken>({
name: "login_token",
versions: [{
migration: () => { },
schema: {
token: { type: String },
special: { type: Boolean, default: () => false },
user: { type: ObjectID },
validTill: { type: Date },
valid: { type: Boolean }
}
}]
})
export default LoginToken;

24
src/models/mail.ts Normal file
View File

@ -0,0 +1,24 @@
import DB from "../database";
import { ModelDataBase } from "@hibas123/safe_mongo/lib/model";
import { ObjectID } from "mongodb";
import { v4 } from "uuid";
export interface IMail extends ModelDataBase {
mail: string;
verified: boolean;
primary: boolean;
}
const Mail = DB.addModel<IMail>({
name: "mail",
versions: [{
migration: () => { },
schema: {
mail: { type: String },
verified: { type: Boolean, default: false },
primary: { type: Boolean }
}
}]
})
export default Mail;

24
src/models/permissions.ts Normal file
View File

@ -0,0 +1,24 @@
import DB from "../database";
import { ModelDataBase } from "@hibas123/safe_mongo/lib/model";
import { ObjectID } from "mongodb";
import { v4 } from "uuid";
export interface IPermission extends ModelDataBase {
name: string;
description: string;
client: ObjectID;
}
const Permission = DB.addModel<IPermission>({
name: "permission",
versions: [{
migration: () => { },
schema: {
name: { type: String },
description: { type: String },
client: { type: ObjectID }
}
}]
})
export default Permission;

View File

@ -0,0 +1,30 @@
import DB from "../database";
import { ModelDataBase } from "@hibas123/safe_mongo/lib/model";
import { ObjectID } from "mongodb";
import { v4 } from "uuid";
export interface IRefreshToken extends ModelDataBase {
token: string;
user: ObjectID;
client: ObjectID;
permissions: ObjectID[];
validTill: Date;
valid: boolean;
}
const RefreshToken = DB.addModel<IRefreshToken>({
name: "refresh_token",
versions: [{
migration: () => { },
schema: {
token: { type: String },
user: { type: ObjectID },
client: { type: ObjectID },
permissions: { type: Array },
validTill: { type: Date },
valid: { type: Boolean }
}
}]
})
export default RefreshToken;

55
src/models/regcodes.ts Normal file
View File

@ -0,0 +1,55 @@
import DB from "../database";
import { ModelDataBase } from "@hibas123/safe_mongo/lib/model";
import { ObjectID } from "mongodb";
import { v4 } from "uuid";
export interface IRegCode extends ModelDataBase {
token: string;
valid: boolean;
validTill: Date;
}
const RegCode = DB.addModel<IRegCode>({
name: "reg_code",
versions: [{
migration: () => { },
schema: {
token: { type: String },
valid: { type: Boolean },
validTill: { type: Date }
}
}]
})
export default RegCode;
// import { Model, Table, Column, ForeignKey, BelongsTo, Unique, CreatedAt, UpdatedAt, DeletedAt, HasMany, BelongsToMany, Default, DataType } from "sequelize-typescript"
// import User from "./user";
// import Permission from "./permissions";
// import RefreshPermission from "./refresh_permission";
// @Table
// export default class RegCode extends Model<RegCode> {
// @Unique
// @Default(DataType.UUIDV4)
// @Column(DataType.UUID)
// token: string
// @Column
// validTill: Date
// @Column
// valid: boolean
// @Column
// @CreatedAt
// creationDate: Date;
// @Column
// @UpdatedAt
// updatedOn: Date;
// @Column
// @DeletedAt
// deletionDate: Date;
// }

69
src/models/user.ts Normal file
View File

@ -0,0 +1,69 @@
import DB from "../database";
import { ModelDataBase } from "@hibas123/safe_mongo/lib/model";
import { ObjectID } from "mongodb";
import { v4 } from "uuid";
export enum Gender {
none,
male,
female,
other
}
export enum TokenTypes {
OTC,
BACKUP_CODE
}
export interface IUser extends ModelDataBase {
uid: string;
username: string;
name: string;
birthday?: Date
gender: Gender;
admin: boolean;
password: string;
salt: string;
mails: ObjectID[];
phones: { phone: string, verified: boolean, primary: boolean }[];
twofactor: { token: string, valid: boolean, type: TokenTypes }[];
}
const User = DB.addModel<IUser>({
name: "user",
versions: [{
migration: () => { },
schema: {
uid: { type: String, default: () => v4() },
username: { type: String },
name: { type: String },
birthday: { type: Date, optional: true },
gender: { type: Number },
admin: { type: Boolean },
password: { type: String },
salt: { type: String },
mails: { type: Array, default: [] },
phones: {
array: true,
model: true,
type: {
phone: { type: String },
verified: { type: Boolean },
primary: { type: Boolean }
}
},
twofactor: {
array: true,
model: true,
type: {
token: { type: String },
valid: { type: Boolean },
type: { type: Number }
}
}
}
}]
})
export default User;