diff --git a/backend/src/apis/loginAPI.ts b/backend/src/apis/HttpRequest.ts similarity index 100% rename from backend/src/apis/loginAPI.ts rename to backend/src/apis/HttpRequest.ts diff --git a/backend/src/apis/klicktippAPI.ts b/backend/src/apis/klicktippAPI.ts index 8654f9e53..f72ae780b 100644 --- a/backend/src/apis/klicktippAPI.ts +++ b/backend/src/apis/klicktippAPI.ts @@ -30,8 +30,8 @@ export class KlicktippConnector { * @return TRUE on success */ async login(username: string, password: string): Promise { - if (!(username && password)) { - throw new Error('Login failed: Illegal Arguments') + if (!(username.length > 0 && password.length > 0)) { + throw new Error('Klicktipp Login failed: Illegal Arguments') } const res = await this.httpRequest('/account/login', 'POST', { username, password }, false) @@ -43,7 +43,7 @@ export class KlicktippConnector { return true } - throw new Error(`Login failed: ${res.response.statusText}`) + throw new Error(`Klicktipp Login failed: ${res.response.statusText}`) } /** @@ -61,7 +61,7 @@ export class KlicktippConnector { return true } - throw new Error(`Logout failed: ${res.response.statusText}`) + throw new Error(`Klicktipp Logout failed: ${res.response.statusText}`) } /** @@ -76,7 +76,7 @@ export class KlicktippConnector { return res.data } - throw new Error(`Subscription process index failed: ${res.response.statusText}`) + throw new Error(`Klicktipp Subscription process index failed: ${res.response.statusText}`) } /** @@ -88,7 +88,7 @@ export class KlicktippConnector { */ async subscriptionProcessGet(listid: string): Promise { if (!listid || listid === '') { - throw new Error('Illegal Arguments') + throw new Error('Klicktipp Illegal Arguments') } // retrieve @@ -98,7 +98,7 @@ export class KlicktippConnector { return res.data } - throw new Error(`Subscription process get failed: ${res.response.statusText}`) + throw new Error(`Klicktipp Subscription process get failed: ${res.response.statusText}`) } /** @@ -111,7 +111,7 @@ export class KlicktippConnector { */ async subscriptionProcessRedirect(listid: string, email: string): Promise { if (!listid || listid === '' || !email || email === '') { - throw new Error('Illegal Arguments') + throw new Error('Klicktipp Illegal Arguments') } // update @@ -122,7 +122,9 @@ export class KlicktippConnector { return res.data } - throw new Error(`Subscription process get redirection url failed: ${res.response.statusText}`) + throw new Error( + `Klicktipp Subscription process get redirection url failed: ${res.response.statusText}`, + ) } /** @@ -137,7 +139,7 @@ export class KlicktippConnector { return res.data } - throw new Error(`Tag index failed: ${res.response.statusText}`) + throw new Error(`Klicktipp Tag index failed: ${res.response.statusText}`) } /** @@ -149,7 +151,7 @@ export class KlicktippConnector { */ async tagGet(tagid: string): Promise { if (!tagid || tagid === '') { - throw new Error('Illegal Arguments') + throw new Error('Klicktipp Illegal Arguments') } const res = await this.httpRequest(`/tag/${tagid}`) @@ -157,7 +159,7 @@ export class KlicktippConnector { return res.data } - throw new Error(`Tag get failed: ${res.response.statusText}`) + throw new Error(`Klicktipp Tag get failed: ${res.response.statusText}`) } /** @@ -170,7 +172,7 @@ export class KlicktippConnector { */ async tagCreate(name: string, text?: string): Promise { if (!name || name === '') { - throw new Error('Illegal Arguments') + throw new Error('Klicktipp Illegal Arguments') } const data = { name, @@ -182,7 +184,7 @@ export class KlicktippConnector { return res.data } - throw new Error(`Tag creation failed: ${res.response.statusText}`) + throw new Error(`Klicktipp Tag creation failed: ${res.response.statusText}`) } /** @@ -196,7 +198,7 @@ export class KlicktippConnector { */ async tagUpdate(tagid: string, name?: string, text?: string): Promise { if (!tagid || tagid === '' || (name === '' && text === '')) { - throw new Error('Illegal Arguments') + throw new Error('Klicktipp Illegal Arguments') } const data = { name: name !== undefined ? name : '', @@ -209,7 +211,7 @@ export class KlicktippConnector { return true } - throw new Error(`Tag update failed: ${res.response.statusText}`) + throw new Error(`Klicktipp Tag update failed: ${res.response.statusText}`) } /** @@ -221,7 +223,7 @@ export class KlicktippConnector { */ async tagDelete(tagid: string): Promise { if (!tagid || tagid === '') { - throw new Error('Illegal Arguments') + throw new Error('Klicktipp Illegal Arguments') } const res = await this.httpRequest(`/tag/${tagid}`, 'DELETE') @@ -230,7 +232,7 @@ export class KlicktippConnector { return true } - throw new Error(`Tag deletion failed: ${res.response.statusText}`) + throw new Error(`Klicktipp Tag deletion failed: ${res.response.statusText}`) } /** @@ -245,7 +247,7 @@ export class KlicktippConnector { return res.data } - throw new Error(`Field index failed: ${res.response.statusText}`) + throw new Error(`Klicktipp Field index failed: ${res.response.statusText}`) } /** @@ -282,7 +284,7 @@ export class KlicktippConnector { if (!res.isAxiosError) { return res.data } - throw new Error(`Subscription failed: ${res.response.statusText}`) + throw new Error(`Klicktipp Subscription failed: ${res.response.statusText}`) } /** @@ -294,7 +296,7 @@ export class KlicktippConnector { */ async unsubscribe(email: string): Promise { if (!email || email === '') { - throw new Error('Illegal Arguments') + throw new Error('Klicktipp Illegal Arguments') } // unsubscribe @@ -305,7 +307,7 @@ export class KlicktippConnector { if (!res.isAxiosError) { return true } - throw new Error(`Unsubscription failed: ${res.response.statusText}`) + throw new Error(`Klicktipp Unsubscription failed: ${res.response.statusText}`) } /** @@ -318,7 +320,7 @@ export class KlicktippConnector { */ async tag(email: string, tagids: string): Promise { if (!email || email === '' || !tagids || tagids === '') { - throw new Error('Illegal Arguments') + throw new Error('Klicktipp Illegal Arguments') } // tag @@ -332,7 +334,7 @@ export class KlicktippConnector { if (!res.isAxiosError) { return res.data } - throw new Error(`Tagging failed: ${res.response.statusText}`) + throw new Error(`Klicktipp Tagging failed: ${res.response.statusText}`) } /** @@ -345,7 +347,7 @@ export class KlicktippConnector { */ async untag(email: string, tagid: string): Promise { if (!email || email === '' || !tagid || tagid === '') { - throw new Error('Illegal Arguments') + throw new Error('Klicktipp Illegal Arguments') } // subscribe @@ -359,7 +361,7 @@ export class KlicktippConnector { if (!res.isAxiosError) { return true } - throw new Error(`Untagging failed: ${res.response.statusText}`) + throw new Error(`Klicktipp Untagging failed: ${res.response.statusText}`) } /** @@ -372,7 +374,7 @@ export class KlicktippConnector { */ async resend(email: string, autoresponder: string): Promise { if (!email || email === '' || !autoresponder || autoresponder === '') { - throw new Error('Illegal Arguments') + throw new Error('Klicktipp Illegal Arguments') } // resend/reset autoresponder @@ -383,7 +385,7 @@ export class KlicktippConnector { if (!res.isAxiosError) { return true } - throw new Error(`Resend failed: ${res.response.statusText}`) + throw new Error(`Klicktipp Resend failed: ${res.response.statusText}`) } /** @@ -397,7 +399,7 @@ export class KlicktippConnector { if (!res.isAxiosError) { return res.data } - throw new Error(`Subscriber index failed: ${res.response.statusText}`) + throw new Error(`Klicktipp Subscriber index failed: ${res.response.statusText}`) } /** @@ -409,7 +411,7 @@ export class KlicktippConnector { */ async subscriberGet(subscriberid: string): Promise { if (!subscriberid || subscriberid === '') { - throw new Error('Illegal Arguments') + throw new Error('Klicktipp Illegal Arguments') } // retrieve @@ -417,7 +419,7 @@ export class KlicktippConnector { if (!res.isAxiosError) { return res.data } - throw new Error(`Subscriber get failed: ${res.response.statusText}`) + throw new Error(`Klicktipp Subscriber get failed: ${res.response.statusText}`) } /** @@ -429,7 +431,7 @@ export class KlicktippConnector { */ async subscriberSearch(email: string): Promise { if (!email || email === '') { - throw new Error('Illegal Arguments') + throw new Error('Klicktipp Illegal Arguments') } // search const data = { email } @@ -438,7 +440,7 @@ export class KlicktippConnector { if (!res.isAxiosError) { return res.data } - throw new Error(`Subscriber search failed: ${res.response.statusText}`) + throw new Error(`Klicktipp Subscriber search failed: ${res.response.statusText}`) } /** @@ -450,7 +452,7 @@ export class KlicktippConnector { */ async subscriberTagged(tagid: string): Promise { if (!tagid || tagid === '') { - throw new Error('Illegal Arguments') + throw new Error('Klicktipp Illegal Arguments') } // search @@ -460,7 +462,7 @@ export class KlicktippConnector { if (!res.isAxiosError) { return res.data } - throw new Error(`subscriber tagged failed: ${res.response.statusText}`) + throw new Error(`Klicktipp subscriber tagged failed: ${res.response.statusText}`) } /** @@ -479,7 +481,7 @@ export class KlicktippConnector { newsmsnumber?: string, ): Promise { if (!subscriberid || subscriberid === '') { - throw new Error('Illegal Arguments') + throw new Error('Klicktipp Illegal Arguments') } // update @@ -492,7 +494,7 @@ export class KlicktippConnector { if (!res.isAxiosError) { return true } - throw new Error(`Subscriber update failed: ${res.response.statusText}`) + throw new Error(`Klicktipp Subscriber update failed: ${res.response.statusText}`) } /** @@ -504,7 +506,7 @@ export class KlicktippConnector { */ async subscriberDelete(subscriberid: string): Promise { if (!subscriberid || subscriberid === '') { - throw new Error('Illegal Arguments') + throw new Error('Klicktipp Illegal Arguments') } // delete @@ -513,7 +515,7 @@ export class KlicktippConnector { if (!res.isAxiosError) { return true } - throw new Error(`Subscriber deletion failed: ${res.response.statusText}`) + throw new Error(`Klicktipp Subscriber deletion failed: ${res.response.statusText}`) } /** @@ -527,7 +529,7 @@ export class KlicktippConnector { */ async signin(apikey: string, email: string, fields?: any, smsnumber?: string): Promise { if (!apikey || apikey === '' || ((!email || email === '') && smsnumber === '')) { - throw new Error('Illegal Arguments') + throw new Error('Klicktipp Illegal Arguments') } // subscribe @@ -543,7 +545,7 @@ export class KlicktippConnector { if (!res.isAxiosError) { return true } - throw new Error(`Subscription failed: ${res.response.statusText}`) + throw new Error(`Klicktipp Subscription failed: ${res.response.statusText}`) } /** @@ -556,7 +558,7 @@ export class KlicktippConnector { */ async signout(apikey: string, email: string): Promise { if (!apikey || apikey === '' || !email || email === '') { - throw new Error('Illegal Arguments') + throw new Error('Klicktipp Illegal Arguments') } // untag @@ -566,7 +568,7 @@ export class KlicktippConnector { if (!res.isAxiosError) { return true } - throw new Error(`Untagging failed: ${res.response.statusText}`) + throw new Error(`Klicktipp Untagging failed: ${res.response.statusText}`) } /** @@ -579,7 +581,7 @@ export class KlicktippConnector { */ async signoff(apikey: string, email: string): Promise { if (!apikey || apikey === '' || !email || email === '') { - throw new Error('Illegal Arguments') + throw new Error('Klicktipp Illegal Arguments') } // unsubscribe @@ -589,7 +591,7 @@ export class KlicktippConnector { if (!res.isAxiosError) { return true } - throw new Error(`Unsubscription failed: ${res.response.statusText}`) + throw new Error(`Klicktipp Unsubscription failed: ${res.response.statusText}`) } async httpRequest(path: string, method?: Method, data?: any, usesession?: boolean): Promise { diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index fb50b0121..b3a186359 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -13,8 +13,9 @@ const server = { GDT_API_URL: process.env.GDT_API_URL || 'https://gdt.gradido.net', KLICKTTIPP_API_URL: process.env.KLICKTIPP_API_URL || 'https://api.klicktipp.com', KLICKTIPP_USER: process.env.KLICKTIPP_USER || 'mbaier-heinehannes', - KLICKTIPP_PASSWORD: process.env.KLICKTIPP_PASSWORD || 'secret321', - KLICKTIPP_APIKEY: process.env.KLICKTIPP_APIKEY || '', + KLICKTIPP_PASSWORD: process.env.KLICKTIPP_PASSWORD || 'Ynq9m8HCP', + KLICKTIPP_APIKEY_DE: process.env.KLICKTIPP_APIKEY_DE || '4vgozlkpz8z726a', + KLICKTIPP_APIKEY_EN: process.env.KLICKTIPP_APIKEY_EN || '4vgpzlkpz8zb79c', } // This is needed by graphql-directive-auth diff --git a/backend/src/graphql/inputs/LoginUserInput.ts b/backend/src/graphql/inputs/LoginUserInput.ts index 19326689e..716b19403 100644 --- a/backend/src/graphql/inputs/LoginUserInput.ts +++ b/backend/src/graphql/inputs/LoginUserInput.ts @@ -22,6 +22,9 @@ export class CreateUserArgs { @Field(() => String) password: string + + @Field(() => String) + language: string } @ArgsType() diff --git a/backend/src/graphql/resolvers/BalanceResolver.ts b/backend/src/graphql/resolvers/BalanceResolver.ts index c483ad5c9..1eea71e66 100644 --- a/backend/src/graphql/resolvers/BalanceResolver.ts +++ b/backend/src/graphql/resolvers/BalanceResolver.ts @@ -1,7 +1,7 @@ import { Resolver, Query, /* Mutation, */ Arg } from 'type-graphql' import CONFIG from '../../config' import { Balance } from '../models/Balance' -import { apiGet } from '../../apis/loginAPI' +import { apiGet } from '../../apis/HttpRequest' @Resolver() export class BalanceResolver { diff --git a/backend/src/graphql/resolvers/GdtResolver.ts b/backend/src/graphql/resolvers/GdtResolver.ts index 0ff187bd1..6ff8b7ae4 100644 --- a/backend/src/graphql/resolvers/GdtResolver.ts +++ b/backend/src/graphql/resolvers/GdtResolver.ts @@ -3,7 +3,7 @@ import { Resolver, Query, /* Mutation, */ Args } from 'type-graphql' import CONFIG from '../../config' import { GdtEntryList } from '../models/GdtEntryList' import { GdtTransactionSessionIdInput } from '../inputs/GdtInputs' -import { apiGet } from '../../apis/loginAPI' +import { apiGet } from '../../apis/HttpRequest' @Resolver() export class GdtResolver { diff --git a/backend/src/graphql/resolvers/UserResolver.ts b/backend/src/graphql/resolvers/UserResolver.ts index 7c731bca2..dacb3a974 100644 --- a/backend/src/graphql/resolvers/UserResolver.ts +++ b/backend/src/graphql/resolvers/UserResolver.ts @@ -13,7 +13,7 @@ import { UnsecureLoginArgs, UpdateUserInfosArgs, } from '../inputs/LoginUserInput' -import { apiPost, apiGet } from '../../apis/loginAPI' +import { apiPost, apiGet } from '../../apis/HttpRequest' import { KlicktippConnector } from '../../apis/klicktippAPI' @Resolver() @@ -73,7 +73,9 @@ export class UserResolver { } @Query(() => String) - async create(@Args() { email, firstName, lastName, password }: CreateUserArgs): Promise { + async create( + @Args() { email, firstName, lastName, password, language }: CreateUserArgs, + ): Promise { const payload = { email, first_name: firstName, @@ -87,19 +89,16 @@ export class UserResolver { throw new Error(result.data) } - const loginSuccessful = await this.connector.login( - CONFIG.KLICKTIPP_USER, - CONFIG.KLICKTIPP_PASSWORD, - ) - if (loginSuccessful) { - const fields = {} - const success = await this.connector.signin(CONFIG.KLICKTIPP_APIKEY, email, fields) - if (!success) { - throw new Error(`Signin to KlickTipp has failed ${this.connector.getLastError()}`) - } - } else { - throw new Error(`Could not login to Klicktipp ${this.connector.getLastError()}`) - } + // const loginSuccessful = await this.connector.login( + // CONFIG.KLICKTIPP_USER, + // CONFIG.KLICKTIPP_PASSWORD, + // ) + // if (loginSuccessful) { + const fields = {} + const apiKey = language === 'de' ? CONFIG.KLICKTIPP_APIKEY_DE : CONFIG.KLICKTIPP_APIKEY_EN + await this.connector.signin(apiKey, email, fields) + // } + return 'success' } diff --git a/frontend/src/graphql/queries.js b/frontend/src/graphql/queries.js index 3afe807f4..05d51b102 100644 --- a/frontend/src/graphql/queries.js +++ b/frontend/src/graphql/queries.js @@ -1,7 +1,7 @@ import gql from 'graphql-tag' export const login = gql` - query($email: String!, $password: String!) { + query ($email: String!, $password: String!) { login(email: $email, password: $password) { sessionId user { @@ -17,19 +17,19 @@ export const login = gql` ` export const logout = gql` - query($sessionId: Float!) { + query ($sessionId: Float!) { logout(sessionId: $sessionId) } ` export const resetPassword = gql` - query($sessionId: Float!, $email: String!, $password: String!) { + query ($sessionId: Float!, $email: String!, $password: String!) { resetPassword(sessionId: $sessionId, email: $email, password: $password) } ` export const loginViaEmailVerificationCode = gql` - query($optin: String!) { + query ($optin: String!) { loginViaEmailVerificationCode(optin: $optin) { sessionId email @@ -38,7 +38,7 @@ export const loginViaEmailVerificationCode = gql` ` export const updateUserInfos = gql` - query( + query ( $sessionId: Float! $email: String! $firstName: String @@ -66,7 +66,7 @@ export const updateUserInfos = gql` ` export const transactionsQuery = gql` - query($sessionId: Float!, $firstPage: Int = 1, $items: Int = 25, $order: String = "DESC") { + query ($sessionId: Float!, $firstPage: Int = 1, $items: Int = 25, $order: String = "DESC") { transactionList(sessionId: $sessionId, firstPage: $firstPage, items: $items, order: $order) { gdtSum count @@ -97,19 +97,31 @@ export const transactionsQuery = gql` ` export const resgisterUserQuery = gql` - query($firstName: String!, $lastName: String!, $email: String!, $password: String!) { - create(email: $email, firstName: $firstName, lastName: $lastName, password: $password) + query ( + $firstName: String! + $lastName: String! + $email: String! + $password: String! + $language: String! + ) { + create( + email: $email + firstName: $firstName + lastName: $lastName + password: $password + language: $language + ) } ` export const sendCoins = gql` - query($sessionId: Float!, $email: String!, $amount: Float!, $memo: String!) { + query ($sessionId: Float!, $email: String!, $amount: Float!, $memo: String!) { sendCoins(sessionId: $sessionId, email: $email, amount: $amount, memo: $memo) } ` export const sendResetPasswordEmail = gql` - query($email: String!) { + query ($email: String!) { sendResetPasswordEmail(email: $email) { state } @@ -117,7 +129,7 @@ export const sendResetPasswordEmail = gql` ` export const checkUsername = gql` - query($username: String!) { + query ($username: String!) { checkUsername(username: $username) { state } @@ -125,7 +137,7 @@ export const checkUsername = gql` ` export const listGDTEntriesQuery = gql` - query($currentPage: Int!, $pageSize: Int!, $sessionId: Float!) { + query ($currentPage: Int!, $pageSize: Int!, $sessionId: Float!) { listGDTEntries(currentPage: $currentPage, pageSize: $pageSize, sessionId: $sessionId) { count gdtEntries { diff --git a/frontend/src/views/Pages/Register.spec.js b/frontend/src/views/Pages/Register.spec.js index 34a7390c5..83ff177d3 100644 --- a/frontend/src/views/Pages/Register.spec.js +++ b/frontend/src/views/Pages/Register.spec.js @@ -12,6 +12,11 @@ describe('Register', () => { let wrapper const mocks = { + $store: { + state: { + language: 'de', + }, + }, $i18n: { locale: 'en', }, @@ -214,6 +219,7 @@ describe('Register', () => { firstName: 'Max', lastName: 'Mustermann', password: 'Aa123456', + language: 'de', }, }), ) diff --git a/frontend/src/views/Pages/Register.vue b/frontend/src/views/Pages/Register.vue index 933cae028..2680c5ecf 100755 --- a/frontend/src/views/Pages/Register.vue +++ b/frontend/src/views/Pages/Register.vue @@ -183,6 +183,7 @@ export default { firstName: this.form.firstname, lastName: this.form.lastname, password: this.form.password.password, + language: this.$store.state.language, }, }) .then(() => {