diff --git a/backend/src/graphql/arg/CreateUserArgs.ts b/backend/src/graphql/arg/CreateUserArgs.ts index 0d63e76bb..3a8914200 100644 --- a/backend/src/graphql/arg/CreateUserArgs.ts +++ b/backend/src/graphql/arg/CreateUserArgs.ts @@ -11,6 +11,9 @@ export default class CreateUserArgs { @Field(() => String) lastName: string + @Field(() => String) + password: string + @Field(() => String) language?: string // Will default to DEFAULT_LANGUAGE diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 323df11fb..edf2dde2a 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -343,7 +343,7 @@ export class UserResolver { @Authorized([RIGHTS.CREATE_USER]) @Mutation(() => String) async createUser( - @Args() { email, firstName, lastName, language, publisherId }: CreateUserArgs, + @Args() { email, firstName, lastName, password, language, publisherId }: CreateUserArgs, ): Promise { // TODO: wrong default value (should be null), how does graphql work here? Is it an required field? // default int publisher_id = 0; @@ -353,13 +353,12 @@ export class UserResolver { language = DEFAULT_LANGUAGE } - // TODO: Register process // Validate Password - // if (!isPassword(password)) { - // throw new Error( - // 'Please enter a valid password with at least 8 characters, upper and lower case letters, at least one number and one special character!', - // ) - // } + if (!isPassword(password)) { + throw new Error( + 'Please enter a valid password with at least 8 characters, upper and lower case letters, at least one number and one special character!', + ) + } // Validate username // TODO: never true @@ -377,13 +376,11 @@ export class UserResolver { throw new Error(`User already exists.`) } - // TODO: Register process - // const passphrase = PassphraseGenerate() - // const keyPair = KeyPairEd25519Create(passphrase) // return pub, priv Key - // const passwordHash = SecretKeyCryptographyCreateKey(email, password) // return short and long hash - // const encryptedPrivkey = SecretKeyCryptographyEncrypt(keyPair[1], passwordHash[1]) - + const passphrase = PassphraseGenerate() + const keyPair = KeyPairEd25519Create(passphrase) // return pub, priv Key + const passwordHash = SecretKeyCryptographyCreateKey(email, password) // return short and long hash const emailHash = getEmailHash(email) + const encryptedPrivkey = SecretKeyCryptographyEncrypt(keyPair[1], passwordHash[1]) // Table: login_users const loginUser = new LoginUser() @@ -392,15 +389,13 @@ export class UserResolver { loginUser.lastName = lastName loginUser.username = username loginUser.description = '' - // TODO: Register process - // loginUser.password = passwordHash[0].readBigUInt64LE() // using the shorthash + loginUser.password = passwordHash[0].readBigUInt64LE() // using the shorthash loginUser.emailHash = emailHash loginUser.language = language loginUser.groupId = 1 loginUser.publisherId = publisherId - // TODO: Register process - // loginUser.pubKey = keyPair[0] - // loginUser.privKey = encryptedPrivkey + loginUser.pubKey = keyPair[0] + loginUser.privKey = encryptedPrivkey const queryRunner = getConnection().createQueryRunner() await queryRunner.connect() @@ -412,24 +407,21 @@ export class UserResolver { throw new Error('insert user failed') }) - // TODO: Register process // Table: login_user_backups - // const loginUserBackup = new LoginUserBackup() - // loginUserBackup.userId = loginUserId - // loginUserBackup.passphrase = passphrase.join(' ') + ' ' // login server saves trailing space - // loginUserBackup.mnemonicType = 2 // ServerConfig::MNEMONIC_BIP0039_SORTED_ORDER; + const loginUserBackup = new LoginUserBackup() + loginUserBackup.userId = loginUserId + loginUserBackup.passphrase = passphrase.join(' ') + ' ' // login server saves trailing space + loginUserBackup.mnemonicType = 2 // ServerConfig::MNEMONIC_BIP0039_SORTED_ORDER; - // TODO: Register process - // await queryRunner.manager.save(loginUserBackup).catch((error) => { - // // eslint-disable-next-line no-console - // console.log('insert LoginUserBackup failed', error) - // throw new Error('insert user backup failed') - // }) + await queryRunner.manager.save(loginUserBackup).catch((error) => { + // eslint-disable-next-line no-console + console.log('insert LoginUserBackup failed', error) + throw new Error('insert user backup failed') + }) // Table: state_users const dbUser = new DbUser() - // TODO: Register process - // dbUser.pubkey = keyPair[0] + dbUser.pubkey = keyPair[0] dbUser.email = email dbUser.firstName = firstName dbUser.lastName = lastName