mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Peter Lustig Seed as User (not admin yet)
This commit is contained in:
parent
4d57487f8f
commit
a14f37a5f4
@ -1,4 +1,5 @@
|
||||
import { BaseEntity, Entity, PrimaryGeneratedColumn, Column } from 'typeorm'
|
||||
import { BaseEntity, Entity, PrimaryGeneratedColumn, Column, OneToOne } from 'typeorm'
|
||||
import { LoginUserBackup } from '../LoginUserBackup'
|
||||
|
||||
// Moriz: I do not like the idea of having two user tables
|
||||
@Entity('login_users')
|
||||
@ -53,4 +54,7 @@ export class LoginUser extends BaseEntity {
|
||||
|
||||
@Column({ name: 'publisher_id', default: 0 })
|
||||
publisherId: number
|
||||
|
||||
@OneToOne(() => LoginUserBackup, (loginUserBackup) => loginUserBackup.loginUser)
|
||||
loginUserBackup: LoginUserBackup
|
||||
}
|
||||
|
||||
@ -15,7 +15,7 @@ export class LoginUserBackup extends BaseEntity {
|
||||
@Column({ name: 'mnemonic_type', default: -1 })
|
||||
mnemonicType: number
|
||||
|
||||
@OneToOne(() => LoginUser, { nullable: false })
|
||||
@OneToOne(() => LoginUser, (loginUser) => loginUser.loginUserBackup, { nullable: false })
|
||||
@JoinColumn({ name: 'user_id' })
|
||||
loginUser: LoginUser
|
||||
}
|
||||
|
||||
@ -3,16 +3,20 @@ import { define } from 'typeorm-seeding'
|
||||
import { LoginUserBackup } from '../../entity/LoginUserBackup'
|
||||
|
||||
interface LoginUserBackupContext {
|
||||
userId?: number
|
||||
passphrase?: string
|
||||
mnemonicType?: number
|
||||
}
|
||||
|
||||
define(LoginUserBackup, (faker: typeof Faker, context?: LoginUserBackupContext) => {
|
||||
if (!context) context = {}
|
||||
if (!context.userId) throw new Error('LoginUserBackup: No iserId present!')
|
||||
|
||||
const userBackup = new LoginUserBackup()
|
||||
// TODO: Get the real passphrase
|
||||
userBackup.passphrase = context.passphrase ? context.passphrase : faker.random.words(24)
|
||||
userBackup.mnemonicType = context.mnemonicType ? context.mnemonicType : 2
|
||||
userBackup.userId = context.userId
|
||||
|
||||
return userBackup
|
||||
})
|
||||
|
||||
@ -31,6 +31,7 @@ define(LoginUser, (faker: typeof Faker, context?: LoginUserContext) => {
|
||||
user.lastName = context.lastName ? context.lastName : faker.name.lastName()
|
||||
user.username = context.username ? context.username : faker.internet.userName()
|
||||
user.description = context.description ? context.description : faker.random.words(4)
|
||||
// TODO Create real password and keys/hash
|
||||
user.password = context.password ? context.password : BigInt(0)
|
||||
user.pubKey = context.pubKey ? context.pubKey : randomBytes(32)
|
||||
user.privKey = context.privKey ? context.privKey : randomBytes(80)
|
||||
|
||||
@ -5,7 +5,7 @@ import CONFIG from './config'
|
||||
import prepare from './prepare'
|
||||
import connection from './typeorm/connection'
|
||||
import { useSeeding, runSeeder } from 'typeorm-seeding'
|
||||
import { CreateUserSeed } from './seeds/create-user.seed'
|
||||
import { CreatePeterLustigSeed } from './seeds/users/peter-lustig.admin.seed'
|
||||
|
||||
const run = async (command: string) => {
|
||||
// Database actions not supported by our migration library
|
||||
@ -54,7 +54,7 @@ const run = async (command: string) => {
|
||||
root: process.cwd(),
|
||||
configName: 'ormconfig.js',
|
||||
})
|
||||
await runSeeder(CreateUserSeed)
|
||||
await runSeeder(CreatePeterLustigSeed)
|
||||
break
|
||||
default:
|
||||
throw new Error(`Unsupported command ${command}`)
|
||||
|
||||
29
database/src/interface/UserContext.ts
Normal file
29
database/src/interface/UserContext.ts
Normal file
@ -0,0 +1,29 @@
|
||||
export interface UserContext {
|
||||
// from login user (contains state user)
|
||||
email?: string
|
||||
firstName?: string
|
||||
lastName?: string
|
||||
username?: string
|
||||
description?: string
|
||||
password?: BigInt
|
||||
pubKey?: Buffer
|
||||
privKey?: Buffer
|
||||
emailHash?: Buffer
|
||||
createdAt?: Date
|
||||
emailChecked?: boolean
|
||||
passphraseShown?: boolean
|
||||
language?: string
|
||||
disabled?: boolean
|
||||
groupId?: number
|
||||
publisherId?: number
|
||||
// from login user backup
|
||||
passphrase?: string
|
||||
mnemonicType?: number
|
||||
// from server user
|
||||
role?: string
|
||||
activated?: number
|
||||
lastLogin?: Date
|
||||
modified?: Date
|
||||
// flag for admin
|
||||
isAdmin?: boolean
|
||||
}
|
||||
@ -2,38 +2,6 @@ import { Factory, Seeder } from 'typeorm-seeding'
|
||||
import { User } from '../../entity/User'
|
||||
// import { LoginUser } from '../../entity/LoginUser'
|
||||
|
||||
/*
|
||||
interface UserContext {
|
||||
// from login user (contains state user)
|
||||
email?: string
|
||||
firstName?: string
|
||||
lastName?: string
|
||||
username?: string
|
||||
description?: string
|
||||
password?: BigInt
|
||||
pubKey?: Buffer
|
||||
privKey?: Buffer
|
||||
emailHash?: Buffer
|
||||
createdAt?: Date
|
||||
emailChecked?: boolean
|
||||
passphraseShown?: boolean
|
||||
language?: string
|
||||
disabled?: boolean
|
||||
groupId?: number
|
||||
publisherId?: number
|
||||
// from login user backup
|
||||
passphrase?: string
|
||||
mnemonicType?: number
|
||||
// from server user
|
||||
role?: string
|
||||
activated?: number
|
||||
lastLogin?: Date
|
||||
modified?: Date
|
||||
// flag for admin
|
||||
isAdmin?: boolean
|
||||
}
|
||||
*/
|
||||
|
||||
export class CreateUserSeed implements Seeder {
|
||||
public async run(factory: Factory): Promise<void> {
|
||||
// const loginUser = await factory(LoginUser)().make()
|
||||
|
||||
73
database/src/seeds/users/peter-lustig.admin.seed.ts
Normal file
73
database/src/seeds/users/peter-lustig.admin.seed.ts
Normal file
@ -0,0 +1,73 @@
|
||||
import { Factory, Seeder } from 'typeorm-seeding'
|
||||
import { User } from '../../../entity/User'
|
||||
import { LoginUser } from '../../../entity/LoginUser'
|
||||
import { LoginUserBackup } from '../../../entity/LoginUserBackup'
|
||||
// import { ServerUser } from '../../../entity/ServerUser'
|
||||
|
||||
const peterLustig = {
|
||||
email: 'peter@lustig.de',
|
||||
firstName: 'Peter',
|
||||
lastName: 'Lustig',
|
||||
username: 'peter',
|
||||
description: 'Latzhose und Nickelbrille',
|
||||
password: BigInt('3917921995996627700'),
|
||||
pubKey: Buffer.from('7281e0ee3258b08801f3ec73e431b4519677f65c03b0382c63a913b5784ee770', 'hex'),
|
||||
privKey: Buffer.from(
|
||||
'3c7c0253033212ed983f6bb10ce73362a99f0bd01d4d1b21ca702d532ca32710ba36abf72a22a963b9026e764e954f441f4905b87a66861bd6b9d9689b7f8aefea66cc493e21da4244e85be81660b9c4',
|
||||
'hex',
|
||||
),
|
||||
emailHash: Buffer.from('9f700e6f6ec351a140b674c0edd4479509697b023bd8bee8826915ef6c2af036', 'hex'),
|
||||
createdAt: new Date('2021-11-25T10:48:43'),
|
||||
emailChecked: true,
|
||||
passphraseShown: false,
|
||||
language: 'de',
|
||||
disabled: false,
|
||||
groupId: 1,
|
||||
publisherId: null,
|
||||
passphrase:
|
||||
'okay property choice naive calm present weird increase stuff royal vibrant frame attend wood one else tribe pull hedgehog woman kitchen hawk snack smart ',
|
||||
mnemonicType: 2,
|
||||
role: 'admin',
|
||||
activated: 0,
|
||||
lastLogin: new Date('2021-10-27T12:25:57'),
|
||||
modified: new Date('2021-10-27T12:25:57'),
|
||||
isAdmin: true,
|
||||
}
|
||||
|
||||
export class CreatePeterLustigSeed implements Seeder {
|
||||
public async run(factory: Factory): Promise<void> {
|
||||
await factory(User)({
|
||||
pubkey: peterLustig.pubKey,
|
||||
email: peterLustig.email,
|
||||
firstName: peterLustig.firstName,
|
||||
lastName: peterLustig.lastName,
|
||||
username: peterLustig.username,
|
||||
disabled: peterLustig.disabled,
|
||||
}).create()
|
||||
|
||||
const loginUser = await factory(LoginUser)({
|
||||
email: peterLustig.email,
|
||||
firstName: peterLustig.firstName,
|
||||
lastName: peterLustig.lastName,
|
||||
username: peterLustig.username,
|
||||
description: peterLustig.description,
|
||||
password: peterLustig.password,
|
||||
pubKey: peterLustig.pubKey,
|
||||
privKey: peterLustig.privKey,
|
||||
emailHash: peterLustig.emailHash,
|
||||
createdAt: peterLustig.createdAt,
|
||||
emailChecked: peterLustig.emailChecked,
|
||||
passphraseShown: peterLustig.passphraseShown,
|
||||
language: peterLustig.language,
|
||||
disabled: peterLustig.disabled,
|
||||
groupId: peterLustig.groupId,
|
||||
publisherId: peterLustig.publisherId,
|
||||
}).create()
|
||||
|
||||
await factory(LoginUserBackup)({
|
||||
passphrase: peterLustig.passphrase,
|
||||
mnemonicType: peterLustig.mnemonicType,
|
||||
userId: loginUser.id,
|
||||
}).create()
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user