From 1baf756c08953784111e28cd29e9a72f95e9e42a Mon Sep 17 00:00:00 2001 From: elweyn Date: Thu, 11 Nov 2021 06:31:00 +0100 Subject: [PATCH] HasElopage has been called, search loginUser catch instead of if no user, context get's the pubKey at the end of the login call instead of the start. --- backend/src/graphql/resolver/UserResolver.ts | 27 ++++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 437d7072e..bee35d676 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -31,6 +31,7 @@ import { LoginElopageBuys } from '@entity/LoginElopageBuys' import { LoginUserBackup } from '@entity/LoginUserBackup' import { LoginEmailOptIn } from '@entity/LoginEmailOptIn' import { sendEMail } from '../../util/sendEMail' +import { LoginElopageBuysRepository } from '../../typeorm/repository/LoginElopageBuys' // eslint-disable-next-line @typescript-eslint/no-var-requires const sodium = require('sodium-native') @@ -195,14 +196,9 @@ export class UserResolver { // const result = await apiPost(CONFIG.LOGIN_API_URL + 'unsecureLogin', { email, password }) // UnsecureLogin const loginUserRepository = getCustomRepository(LoginUserRepository) - const loginUser = await loginUserRepository.findByEmail(email) - if (!loginUser) { + const loginUser = await loginUserRepository.findByEmail(email).catch(() => { throw new Error('No user with this credentials') - } - if (!isPassword(password)) { - throw new Error('No user with this credentials') - } - + }) const passwordHash = SecretKeyCryptographyCreateKey(email, password) // return short and long hash const loginUserPassword = BigInt(loginUser.password.toString()) if (loginUserPassword !== passwordHash[0].readBigUInt64LE()) { @@ -210,11 +206,6 @@ export class UserResolver { } // TODO: If user has no pubKey Create it again and update user. - context.setHeaders.push({ - key: 'token', - value: encode(loginUser.pubKey), - }) - const userRepository = getCustomRepository(UserRepository) let userEntity: void | DbUser const loginUserPubKey = loginUser.pubKey @@ -244,11 +235,7 @@ export class UserResolver { user.description = loginUser.description user.pubkey = loginUserPubKeyString user.language = loginUser.language - // TODO: Get Method from PR (hasElopage) - // auto elopage_buy = Poco::AutoPtr(new model::table::ElopageBuy); - // mHasElopage = elopage_buy->isExistInDB("payer_email", mEmail); - // else undefined - // user.hasElopage = result.data.hasElopage + user.hasElopage = await this.hasElopage({ pubkey: loginUser.pubKey }) // TODO: Get Method from PR (publisherId) // Hack: Database Field is not validated properly and not nullable @@ -272,6 +259,12 @@ export class UserResolver { throw new Error(error) }) user.coinanimation = coinanimation + + context.setHeaders.push({ + key: 'token', + value: encode(loginUser.pubKey), + }) + return user }