From 5a14161284c4d4d23cafb6f0ba4e2d7dcd159422 Mon Sep 17 00:00:00 2001 From: elweyn Date: Wed, 13 Oct 2021 12:07:23 +0200 Subject: [PATCH] Adding the publisherId to the login call and that it stores it to the user profile. --- backend/src/graphql/arg/UnsecureLoginArgs.ts | 3 +++ backend/src/graphql/model/User.ts | 1 - backend/src/graphql/resolver/UserResolver.ts | 14 +++++++++++++- backend/src/middleware/klicktippMiddleware.ts | 4 +--- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/backend/src/graphql/arg/UnsecureLoginArgs.ts b/backend/src/graphql/arg/UnsecureLoginArgs.ts index 9e9cde0d9..42e467eee 100644 --- a/backend/src/graphql/arg/UnsecureLoginArgs.ts +++ b/backend/src/graphql/arg/UnsecureLoginArgs.ts @@ -7,4 +7,7 @@ export default class UnsecureLoginArgs { @Field(() => String) password: string + + @Field(() => Number, { nullable: true }) + publisherId: number } diff --git a/backend/src/graphql/model/User.ts b/backend/src/graphql/model/User.ts index 7d2d4af05..890e8bdba 100644 --- a/backend/src/graphql/model/User.ts +++ b/backend/src/graphql/model/User.ts @@ -19,7 +19,6 @@ export class User { this.pubkey = json.public_hex this.language = json.language this.publisherId = json.publisher_id - this.hasElopage = json.hasElopage } @Field(() => String) diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 2f1ee9c21..1f5667e8f 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -31,7 +31,10 @@ import { UserRepository } from '../../typeorm/repository/User' export class UserResolver { @Query(() => User) @UseMiddleware(klicktippNewsletterStateMiddleware) - async login(@Args() { email, password }: UnsecureLoginArgs, @Ctx() context: any): Promise { + async login( + @Args() { email, password, publisherId }: UnsecureLoginArgs, + @Ctx() context: any, + ): Promise { email = email.trim().toLowerCase() const result = await apiPost(CONFIG.LOGIN_API_URL + 'unsecureLogin', { email, password }) @@ -65,6 +68,15 @@ export class UserResolver { throw new Error('error with cannot happen') } + if (publisherId) { + // Save it + user.publisherId = publisherId + await this.updateUserInfos( + { publisherId }, + { sessionId: result.data.session_id, pubKey: result.data.user.public_hex }, + ) + } + const userSettingRepository = getCustomRepository(UserSettingRepository) const coinanimation = await userSettingRepository .readBoolean(userEntity.id, Setting.COIN_ANIMATION) diff --git a/backend/src/middleware/klicktippMiddleware.ts b/backend/src/middleware/klicktippMiddleware.ts index 856dd9d75..e81087097 100644 --- a/backend/src/middleware/klicktippMiddleware.ts +++ b/backend/src/middleware/klicktippMiddleware.ts @@ -29,9 +29,7 @@ export const klicktippNewsletterStateMiddleware: MiddlewareFn = async ( if (klickTippUser) { klickTipp = new KlickTipp(klickTippUser) } - } catch (err) { - console.log('Something went wrong', err) - } + } catch (err) {} } result.klickTipp = klickTipp return result