From 91959aea287bc1391de67eda5f29faed01da7cee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Mon, 20 Jun 2022 16:08:35 +0200 Subject: [PATCH] Fulfill Moriz suggestions --- backend/.env.dist | 2 +- backend/src/config/index.ts | 2 +- backend/src/graphql/resolver/UserResolver.ts | 173 +++++++++---------- deployment/bare_metal/.env.dist | 2 +- 4 files changed, 89 insertions(+), 90 deletions(-) diff --git a/backend/.env.dist b/backend/.env.dist index 41eeeaf58..db01cf4cc 100644 --- a/backend/.env.dist +++ b/backend/.env.dist @@ -1,4 +1,4 @@ -CONFIG_VERSION=v7.2022-06-15 +CONFIG_VERSION=v8.2022-06-20 # Server PORT=4000 diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index 4e6dd8099..a9cae6770 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -17,7 +17,7 @@ const constants = { LOG_LEVEL: process.env.LOG_LEVEL || 'info', CONFIG_VERSION: { DEFAULT: 'DEFAULT', - EXPECTED: 'v7.2022-06-15', + EXPECTED: 'v8.2022-06-20', CURRENT: '', }, } diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 1ce7d668f..0bde22ae6 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -338,7 +338,6 @@ export class UserResolver { const user = new User(communityDbUser) user.id = sodium.randombytes_random() % (2048 * 16) // TODO: for a better faking derive id from email so that it will be always the same id when the same email comes in? user.email = email - user.emailChecked = true user.firstName = firstName user.lastName = lastName user.language = language @@ -360,93 +359,93 @@ export class UserResolver { logger.info('createUser() faked and send multi registration mail...') return user - } else { - 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 emailHash = getEmailHash(email) - - const dbUser = new DbUser() - dbUser.email = email - dbUser.firstName = firstName - dbUser.lastName = lastName - dbUser.emailHash = emailHash - dbUser.language = language - dbUser.publisherId = publisherId - dbUser.passphrase = passphrase.join(' ') - logger.debug('new dbUser=' + dbUser) - if (redeemCode) { - if (redeemCode.match(/^CL-/)) { - const contributionLink = await dbContributionLink.findOne({ - code: redeemCode.replace('CL-', ''), - }) - logger.info('redeemCode found contributionLink=' + contributionLink) - if (contributionLink) { - dbUser.contributionLinkId = contributionLink.id - } - } else { - const transactionLink = await dbTransactionLink.findOne({ code: redeemCode }) - logger.info('redeemCode found transactionLink=' + transactionLink) - if (transactionLink) { - dbUser.referrerId = transactionLink.userId - } - } - } - // TODO this field has no null allowed unlike the loginServer table - // dbUser.pubKey = Buffer.from(randomBytes(32)) // Buffer.alloc(32, 0) default to 0000... - // dbUser.pubkey = keyPair[0] - // loginUser.password = passwordHash[0].readBigUInt64LE() // using the shorthash - // loginUser.pubKey = keyPair[0] - // loginUser.privKey = encryptedPrivkey - - const queryRunner = getConnection().createQueryRunner() - await queryRunner.connect() - await queryRunner.startTransaction('READ UNCOMMITTED') - try { - await queryRunner.manager.save(dbUser).catch((error) => { - logger.error('Error while saving dbUser', error) - throw new Error('error saving user') - }) - - const emailOptIn = newEmailOptIn(dbUser.id) - await queryRunner.manager.save(emailOptIn).catch((error) => { - logger.error('Error while saving emailOptIn', error) - throw new Error('error saving email opt in') - }) - - const activationLink = CONFIG.EMAIL_LINK_VERIFICATION.replace( - /{optin}/g, - emailOptIn.verificationCode.toString(), - ).replace(/{code}/g, redeemCode ? '/' + redeemCode : '') - - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const emailSent = await sendAccountActivationEmail({ - link: activationLink, - firstName, - lastName, - email, - duration: printTimeDuration(CONFIG.EMAIL_CODE_VALID_TIME), - }) - logger.info(`sendAccountActivationEmail of ${firstName}.${lastName} to ${email}`) - /* uncomment this, when you need the activation link on the console */ - // In case EMails are disabled log the activation link for the user - if (!emailSent) { - logger.debug(`Account confirmation link: ${activationLink}`) - } - - await queryRunner.commitTransaction() - } catch (e) { - logger.error(`error during create user with ${e}`) - await queryRunner.rollbackTransaction() - throw e - } finally { - await queryRunner.release() - } - logger.info('createUser() successful...') - - return new User(dbUser) } + + 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 emailHash = getEmailHash(email) + + const dbUser = new DbUser() + dbUser.email = email + dbUser.firstName = firstName + dbUser.lastName = lastName + dbUser.emailHash = emailHash + dbUser.language = language + dbUser.publisherId = publisherId + dbUser.passphrase = passphrase.join(' ') + logger.debug('new dbUser=' + dbUser) + if (redeemCode) { + if (redeemCode.match(/^CL-/)) { + const contributionLink = await dbContributionLink.findOne({ + code: redeemCode.replace('CL-', ''), + }) + logger.info('redeemCode found contributionLink=' + contributionLink) + if (contributionLink) { + dbUser.contributionLinkId = contributionLink.id + } + } else { + const transactionLink = await dbTransactionLink.findOne({ code: redeemCode }) + logger.info('redeemCode found transactionLink=' + transactionLink) + if (transactionLink) { + dbUser.referrerId = transactionLink.userId + } + } + } + // TODO this field has no null allowed unlike the loginServer table + // dbUser.pubKey = Buffer.from(randomBytes(32)) // Buffer.alloc(32, 0) default to 0000... + // dbUser.pubkey = keyPair[0] + // loginUser.password = passwordHash[0].readBigUInt64LE() // using the shorthash + // loginUser.pubKey = keyPair[0] + // loginUser.privKey = encryptedPrivkey + + const queryRunner = getConnection().createQueryRunner() + await queryRunner.connect() + await queryRunner.startTransaction('READ UNCOMMITTED') + try { + await queryRunner.manager.save(dbUser).catch((error) => { + logger.error('Error while saving dbUser', error) + throw new Error('error saving user') + }) + + const emailOptIn = newEmailOptIn(dbUser.id) + await queryRunner.manager.save(emailOptIn).catch((error) => { + logger.error('Error while saving emailOptIn', error) + throw new Error('error saving email opt in') + }) + + const activationLink = CONFIG.EMAIL_LINK_VERIFICATION.replace( + /{optin}/g, + emailOptIn.verificationCode.toString(), + ).replace(/{code}/g, redeemCode ? '/' + redeemCode : '') + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const emailSent = await sendAccountActivationEmail({ + link: activationLink, + firstName, + lastName, + email, + duration: printTimeDuration(CONFIG.EMAIL_CODE_VALID_TIME), + }) + logger.info(`sendAccountActivationEmail of ${firstName}.${lastName} to ${email}`) + /* uncomment this, when you need the activation link on the console */ + // In case EMails are disabled log the activation link for the user + if (!emailSent) { + logger.debug(`Account confirmation link: ${activationLink}`) + } + + await queryRunner.commitTransaction() + } catch (e) { + logger.error(`error during create user with ${e}`) + await queryRunner.rollbackTransaction() + throw e + } finally { + await queryRunner.release() + } + logger.info('createUser() successful...') + + return new User(dbUser) } @Authorized([RIGHTS.SEND_RESET_PASSWORD_EMAIL]) diff --git a/deployment/bare_metal/.env.dist b/deployment/bare_metal/.env.dist index d9e159382..67c153661 100644 --- a/deployment/bare_metal/.env.dist +++ b/deployment/bare_metal/.env.dist @@ -26,7 +26,7 @@ COMMUNITY_REDEEM_CONTRIBUTION_URL=https://stage1.gradido.net/redeem/CL-{code} COMMUNITY_DESCRIPTION="Gradido Development Stage1 Test Community" # backend -BACKEND_CONFIG_VERSION=v7.2022-06-15 +BACKEND_CONFIG_VERSION=v8.2022-06-20 JWT_EXPIRES_IN=30m GDT_API_URL=https://gdt.gradido.net