From cc8a4fcd5b1e76c6a9b840488b61ec37f9dd2ae5 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Thu, 7 Oct 2021 16:08:14 +0200 Subject: [PATCH 001/113] add api call to check is user has an elopage account to login-server and to apollo-server --- backend/src/graphql/resolver/UserResolver.ts | 14 +++++++++++++- .../src/cpp/JSONInterface/JsonHasElopage.cpp | 16 ++++++++++++++++ .../src/cpp/JSONInterface/JsonHasElopage.h | 15 +++++++++++++++ .../JSONInterface/JsonRequestHandlerFactory.cpp | 4 ++++ login_server/src/cpp/model/table/ModelBase.h | 2 +- 5 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 login_server/src/cpp/JSONInterface/JsonHasElopage.cpp create mode 100644 login_server/src/cpp/JSONInterface/JsonHasElopage.h diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 820e493c6..a48b44f48 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -242,4 +242,16 @@ export class UserResolver { } return new CheckEmailResponse(result.data) } -} + + @Query(() => Boolean) + async hasElopage(@Ctx() context: any): Promise { + const result = await apiGet( + CONFIG.LOGIN_API_URL + 'hasElopage?session_id=' + context.sessionId, + ) + if (!result.success) { + throw new Error(result.data) + } + return result.data.hasElopage + } + +} \ No newline at end of file diff --git a/login_server/src/cpp/JSONInterface/JsonHasElopage.cpp b/login_server/src/cpp/JSONInterface/JsonHasElopage.cpp new file mode 100644 index 000000000..e040b436f --- /dev/null +++ b/login_server/src/cpp/JSONInterface/JsonHasElopage.cpp @@ -0,0 +1,16 @@ +#include "JsonHasElopage.h" +#include "../model/table/ElopageBuy.h" + +Poco::JSON::Object* JsonHasElopage::handle(Poco::Dynamic::Var params) +{ + auto result = checkAndLoadSession(params); + if (result) { + return result; + } + auto elopage_buy = Poco::AutoPtr(); + + result = stateSuccess(); + result->set("hasElopage", elopage_buy->isExistInDB("email", mSession->getNewUser()->getModel()->getEmail())); + + return result; +} \ No newline at end of file diff --git a/login_server/src/cpp/JSONInterface/JsonHasElopage.h b/login_server/src/cpp/JSONInterface/JsonHasElopage.h new file mode 100644 index 000000000..4fc291d5b --- /dev/null +++ b/login_server/src/cpp/JSONInterface/JsonHasElopage.h @@ -0,0 +1,15 @@ +#ifndef __JSON_INTERFACE_JSON_HAS_ELOPAGE_ +#define __JSON_INTERFACE_JSON_HAS_ELOPAGE_ + +#include "JsonRequestHandler.h" + +class JsonHasElopage : public JsonRequestHandler +{ +public: + Poco::JSON::Object* handle(Poco::Dynamic::Var params); + +protected: + +}; + +#endif // __JSON_INTERFACE_JSON_HAS_ELOPAGE_ \ No newline at end of file diff --git a/login_server/src/cpp/JSONInterface/JsonRequestHandlerFactory.cpp b/login_server/src/cpp/JSONInterface/JsonRequestHandlerFactory.cpp index 744ac710e..e1998ddd0 100644 --- a/login_server/src/cpp/JSONInterface/JsonRequestHandlerFactory.cpp +++ b/login_server/src/cpp/JSONInterface/JsonRequestHandlerFactory.cpp @@ -16,6 +16,7 @@ #include "JsonUnknown.h" #include "JsonGetRunningUserTasks.h" #include "JsonGetUsers.h" +#include "JsonHasElopage.h" #include "JsonLoginViaEmailVerificationCode.h" #include "JsonLogout.h" #include "JsonNetworkInfos.h" @@ -140,6 +141,9 @@ Poco::Net::HTTPRequestHandler* JsonRequestHandlerFactory::createRequestHandler(c else if (url_first_part == "/logout") { return new JsonLogout(client_host); } + else if (url_first_part == "/hasElopage") { + return new JsonHasElopage; + } return new JsonUnknown; } diff --git a/login_server/src/cpp/model/table/ModelBase.h b/login_server/src/cpp/model/table/ModelBase.h index 95856087f..98b640178 100644 --- a/login_server/src/cpp/model/table/ModelBase.h +++ b/login_server/src/cpp/model/table/ModelBase.h @@ -171,7 +171,7 @@ namespace model { << " WHERE " << fieldName << " = ?" , Poco::Data::Keywords::into(id), Poco::Data::Keywords::useRef(fieldValue); try { - if (select.execute() == 1) { + if (select.execute() >= 1) { return true; } } From 348ece411a020047f1d9bbdb61ce86c4aa927df1 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Thu, 7 Oct 2021 16:11:18 +0200 Subject: [PATCH 002/113] update doc --- docu/login_server.api.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/docu/login_server.api.md b/docu/login_server.api.md index 20317c66f..60ed74f02 100644 --- a/docu/login_server.api.md +++ b/docu/login_server.api.md @@ -593,3 +593,29 @@ or: "msg": "session not found" } ``` + +## Check if User has an Elopage Account +Check if logged in user has already an elopage account + +### Request +`GET http://localhost/login_api/hasElopage?session_id=-127182` + +### Response +In case of success returns: + +```json +{ + "state":"success", + "hasElopage": true +} +``` + +or: + +```json +{ + "state":"not found", + "msg": "session not found" +} +``` + From 8ddd47f15342ad0454dbe5118ab75e5e3cc845f1 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Thu, 7 Oct 2021 16:16:32 +0200 Subject: [PATCH 003/113] feat: Improve Test of Navigation Guard of Vue Router --- frontend/src/routes/guards.test.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/frontend/src/routes/guards.test.js b/frontend/src/routes/guards.test.js index a016ca111..cf366eac8 100644 --- a/frontend/src/routes/guards.test.js +++ b/frontend/src/routes/guards.test.js @@ -18,21 +18,30 @@ describe('navigation guards', () => { }) describe('publisher ID', () => { - it('commits the pid to the store when present', () => { - router.push({ path: 'login', query: { pid: 42 } }) + it('commits the pid to the store when present', async () => { + await router.push({ path: 'register', query: { pid: 42 } }) expect(storeCommitMock).toBeCalledWith('publisherId', '42') }) - it('does not commit the pid when not present', () => { - router.push({ path: 'register' }) + it('does not commit the pid when not present', async () => { + await router.push({ path: 'password' }) expect(storeCommitMock).not.toBeCalled() }) }) describe('authorization', () => { - it.skip('redirects to login when not authorized', async () => { - router.push({ path: 'overview' }) - expect(router.history.current.path).toBe('/login') + const navGuard = router.beforeHooks[0] + const next = jest.fn() + + it('redirects to login when not authorized', () => { + navGuard({ meta: { requiresAuth: true }, query: {} }, {}, next) + expect(next).toBeCalledWith({ path: '/login' }) + }) + + it('does not redirect to login when authorized', () => { + store.state.token = 'valid token' + navGuard({ meta: { requiresAuth: true }, query: {} }, {}, next) + expect(next).toBeCalledWith() }) }) }) From b3b603b59e78bd4fd64149d442150d1ec959c4b8 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Thu, 7 Oct 2021 16:29:28 +0200 Subject: [PATCH 004/113] bring alive --- login_server/src/cpp/JSONInterface/JsonHasElopage.cpp | 2 +- login_server/src/cpp/model/table/ElopageBuy.cpp | 5 +++++ login_server/src/cpp/model/table/ElopageBuy.h | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/login_server/src/cpp/JSONInterface/JsonHasElopage.cpp b/login_server/src/cpp/JSONInterface/JsonHasElopage.cpp index e040b436f..ee66255be 100644 --- a/login_server/src/cpp/JSONInterface/JsonHasElopage.cpp +++ b/login_server/src/cpp/JSONInterface/JsonHasElopage.cpp @@ -7,7 +7,7 @@ Poco::JSON::Object* JsonHasElopage::handle(Poco::Dynamic::Var params) if (result) { return result; } - auto elopage_buy = Poco::AutoPtr(); + auto elopage_buy = Poco::AutoPtr(new model::table::ElopageBuy); result = stateSuccess(); result->set("hasElopage", elopage_buy->isExistInDB("email", mSession->getNewUser()->getModel()->getEmail())); diff --git a/login_server/src/cpp/model/table/ElopageBuy.cpp b/login_server/src/cpp/model/table/ElopageBuy.cpp index 05e799a4a..c056ecdc9 100644 --- a/login_server/src/cpp/model/table/ElopageBuy.cpp +++ b/login_server/src/cpp/model/table/ElopageBuy.cpp @@ -9,6 +9,11 @@ namespace model { "product[affiliate_program_id]", "publisher[id]", "order_id", "product_id", "product[price]", "payer[email]", "publisher[email]", "payment_state", "success_date", "event" }; + ElopageBuy::ElopageBuy() + { + + } + ElopageBuy::ElopageBuy(const Poco::Net::NameValueCollection& elopage_webhook_requestData) : mPayed(false) { diff --git a/login_server/src/cpp/model/table/ElopageBuy.h b/login_server/src/cpp/model/table/ElopageBuy.h index dec4727a3..83b2b477b 100644 --- a/login_server/src/cpp/model/table/ElopageBuy.h +++ b/login_server/src/cpp/model/table/ElopageBuy.h @@ -31,6 +31,7 @@ namespace model { { public: ElopageBuy(const Poco::Net::NameValueCollection& elopage_webhook_requestData); + ElopageBuy(); // generic db operations const char* getTableName() const { return "elopage_buys"; } From e6c8fbed59f360155f560fdd77f0c00a27683821 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Thu, 7 Oct 2021 16:32:17 +0200 Subject: [PATCH 005/113] fix linting --- backend/src/graphql/resolver/UserResolver.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index a48b44f48..bbb609d40 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -244,14 +244,11 @@ export class UserResolver { } @Query(() => Boolean) - async hasElopage(@Ctx() context: any): Promise { - const result = await apiGet( - CONFIG.LOGIN_API_URL + 'hasElopage?session_id=' + context.sessionId, - ) + async hasElopage(@Ctx() context: any): Promise { + const result = await apiGet(CONFIG.LOGIN_API_URL + 'hasElopage?session_id=' + context.sessionId) if (!result.success) { throw new Error(result.data) } return result.data.hasElopage } - -} \ No newline at end of file +} From 93532004d501d22d8e0bc0026174014cd7eb19d1 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Fri, 8 Oct 2021 10:26:09 +0200 Subject: [PATCH 006/113] add option in login call to check also for elopage account --- backend/src/graphql/arg/UnsecureLoginArgs.ts | 3 +++ backend/src/graphql/model/User.ts | 4 ++++ backend/src/graphql/resolver/UserResolver.ts | 11 +++++++++-- docu/login_server.api.md | 4 ++++ .../src/cpp/JSONInterface/JsonUnsecureLogin.cpp | 12 ++++++++++++ 5 files changed, 32 insertions(+), 2 deletions(-) diff --git a/backend/src/graphql/arg/UnsecureLoginArgs.ts b/backend/src/graphql/arg/UnsecureLoginArgs.ts index 9e9cde0d9..925cde8a4 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(() => Boolean) + hasElopage?: boolean } diff --git a/backend/src/graphql/model/User.ts b/backend/src/graphql/model/User.ts index 21bf1b464..ebdf0aad2 100644 --- a/backend/src/graphql/model/User.ts +++ b/backend/src/graphql/model/User.ts @@ -19,6 +19,7 @@ export class User { this.pubkey = json.public_hex this.language = json.language this.publisherId = json.publisher_id + if (json.hasElopage) this.hasElopage = json.hasElopage } @Field(() => String) @@ -74,4 +75,7 @@ export class User { @Field(() => KlickTipp) klickTipp: KlickTipp + + @Field(() => Boolean) + hasElopage?: boolean } diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index bbb609d40..a6b7ae724 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -31,9 +31,16 @@ 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, hasElopage }: UnsecureLoginArgs, + @Ctx() context: any, + ): Promise { email = email.trim().toLowerCase() - const result = await apiPost(CONFIG.LOGIN_API_URL + 'unsecureLogin', { email, password }) + const result = await apiPost(CONFIG.LOGIN_API_URL + 'unsecureLogin', { + email, + password, + hasElopage, + }) // if there is no user, throw an authentication error if (!result.success) { diff --git a/docu/login_server.api.md b/docu/login_server.api.md index 60ed74f02..90bdedf3d 100644 --- a/docu/login_server.api.md +++ b/docu/login_server.api.md @@ -40,10 +40,12 @@ with: "email": "max.musterman@gmail.de", "username": "Maxilein", "password": "123abcDE&" + "hasElopage": true } ``` `username` or `email` must be present! If booth present, `email` will be used. +`hasElopage`: optional, if set to true login will also check if user has an elopage account ### Response In case of success returns: @@ -67,6 +69,7 @@ In case of success returns: "username": "" }, "session_id": -127182, + "hasElopage": tr "clientIP":"123.123.123.123" } ``` @@ -86,6 +89,7 @@ In case of success returns: - `role`: role of user currently only "none" or "admin" - `username`: not used yet - `clientIP`: should be the same as where the js-client is running, else maybe a man-in-the-middle attacks is happening or +- `hasElopage`: only present if hasElopage was set to true in request, true if user has an elopage account nginx was wrong configured. - `session_id`: can be also negative diff --git a/login_server/src/cpp/JSONInterface/JsonUnsecureLogin.cpp b/login_server/src/cpp/JSONInterface/JsonUnsecureLogin.cpp index 5d337df41..9cd6e2d1a 100644 --- a/login_server/src/cpp/JSONInterface/JsonUnsecureLogin.cpp +++ b/login_server/src/cpp/JSONInterface/JsonUnsecureLogin.cpp @@ -8,6 +8,8 @@ #include "../lib/DataTypeConverter.h" +#include "../model/table/ElopageBuy.h" + Poco::JSON::Object* JsonUnsecureLogin::handle(Poco::Dynamic::Var params) { @@ -23,6 +25,7 @@ Poco::JSON::Object* JsonUnsecureLogin::handle(Poco::Dynamic::Var params) std::string email; std::string username; std::string password; + bool hasElopage = false; // if is json object if (params.type() == typeid(Poco::JSON::Object::Ptr)) { @@ -38,6 +41,11 @@ Poco::JSON::Object* JsonUnsecureLogin::handle(Poco::Dynamic::Var params) auto email_obj = paramJsonObject->get("email"); auto username_obj = paramJsonObject->get("username"); + auto hasElopage_obj = paramJsonObject->get("hasElopage"); + if (!hasElopage_obj.isEmpty()) { + hasElopage_obj.convert(hasElopage); + } + if (!email_obj.isEmpty()) { email_obj.convert(email); } @@ -141,6 +149,10 @@ Poco::JSON::Object* JsonUnsecureLogin::handle(Poco::Dynamic::Var params) if(infos.size() > 0) { result->set("info", infos); } + if (hasElopage) { + auto elopage_buy = Poco::AutoPtr(new model::table::ElopageBuy); + result->set("hasElopage", elopage_buy->isExistInDB("email", mSession->getNewUser()->getModel()->getEmail())); + } return result; default: result->set("state", "error"); From e226a10b4b511a581ac32539af6a00047981396e Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Fri, 8 Oct 2021 10:27:25 +0200 Subject: [PATCH 007/113] fix typo in docu --- docu/login_server.api.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docu/login_server.api.md b/docu/login_server.api.md index 90bdedf3d..b56852010 100644 --- a/docu/login_server.api.md +++ b/docu/login_server.api.md @@ -69,7 +69,7 @@ In case of success returns: "username": "" }, "session_id": -127182, - "hasElopage": tr + "hasElopage": true, "clientIP":"123.123.123.123" } ``` From 17907b23ade870a07a7e8918f9a348711acf4203 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Fri, 8 Oct 2021 10:28:46 +0200 Subject: [PATCH 008/113] fix bug --- login_server/src/cpp/JSONInterface/JsonUnsecureLogin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/login_server/src/cpp/JSONInterface/JsonUnsecureLogin.cpp b/login_server/src/cpp/JSONInterface/JsonUnsecureLogin.cpp index 9cd6e2d1a..7950fb441 100644 --- a/login_server/src/cpp/JSONInterface/JsonUnsecureLogin.cpp +++ b/login_server/src/cpp/JSONInterface/JsonUnsecureLogin.cpp @@ -151,7 +151,7 @@ Poco::JSON::Object* JsonUnsecureLogin::handle(Poco::Dynamic::Var params) } if (hasElopage) { auto elopage_buy = Poco::AutoPtr(new model::table::ElopageBuy); - result->set("hasElopage", elopage_buy->isExistInDB("email", mSession->getNewUser()->getModel()->getEmail())); + result->set("hasElopage", elopage_buy->isExistInDB("email", user_model->getEmail())); } return result; default: From 546d371139a05f5574914bb31c549e54460c2d6b Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Sun, 10 Oct 2021 15:25:01 +0200 Subject: [PATCH 009/113] check always for hasElopage - put check into async task to let it run at the same time as the password check --- backend/src/graphql/arg/UnsecureLoginArgs.ts | 3 --- backend/src/graphql/resolver/UserResolver.ts | 3 +-- .../cpp/JSONInterface/JsonUnsecureLogin.cpp | 18 +++++++----------- .../src/cpp/model/table/ElopageBuy.cpp | 8 ++++++++ login_server/src/cpp/model/table/ElopageBuy.h | 16 ++++++++++++++++ login_server/src/cpp/tasks/CPUTask.h | 2 ++ 6 files changed, 34 insertions(+), 16 deletions(-) diff --git a/backend/src/graphql/arg/UnsecureLoginArgs.ts b/backend/src/graphql/arg/UnsecureLoginArgs.ts index 925cde8a4..9e9cde0d9 100644 --- a/backend/src/graphql/arg/UnsecureLoginArgs.ts +++ b/backend/src/graphql/arg/UnsecureLoginArgs.ts @@ -7,7 +7,4 @@ export default class UnsecureLoginArgs { @Field(() => String) password: string - - @Field(() => Boolean) - hasElopage?: boolean } diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index a6b7ae724..a7e7e39b5 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -32,14 +32,13 @@ export class UserResolver { @Query(() => User) @UseMiddleware(klicktippNewsletterStateMiddleware) async login( - @Args() { email, password, hasElopage }: UnsecureLoginArgs, + @Args() { email, password }: UnsecureLoginArgs, @Ctx() context: any, ): Promise { email = email.trim().toLowerCase() const result = await apiPost(CONFIG.LOGIN_API_URL + 'unsecureLogin', { email, password, - hasElopage, }) // if there is no user, throw an authentication error diff --git a/login_server/src/cpp/JSONInterface/JsonUnsecureLogin.cpp b/login_server/src/cpp/JSONInterface/JsonUnsecureLogin.cpp index 7950fb441..5c06e27b8 100644 --- a/login_server/src/cpp/JSONInterface/JsonUnsecureLogin.cpp +++ b/login_server/src/cpp/JSONInterface/JsonUnsecureLogin.cpp @@ -25,7 +25,6 @@ Poco::JSON::Object* JsonUnsecureLogin::handle(Poco::Dynamic::Var params) std::string email; std::string username; std::string password; - bool hasElopage = false; // if is json object if (params.type() == typeid(Poco::JSON::Object::Ptr)) { @@ -41,11 +40,6 @@ Poco::JSON::Object* JsonUnsecureLogin::handle(Poco::Dynamic::Var params) auto email_obj = paramJsonObject->get("email"); auto username_obj = paramJsonObject->get("username"); - auto hasElopage_obj = paramJsonObject->get("hasElopage"); - if (!hasElopage_obj.isEmpty()) { - hasElopage_obj.convert(hasElopage); - } - if (!email_obj.isEmpty()) { email_obj.convert(email); } @@ -113,6 +107,10 @@ Poco::JSON::Object* JsonUnsecureLogin::handle(Poco::Dynamic::Var params) USER_COMPLETE, USER_DISABLED */ + // run query for checking if user has already an account async + Poco::AutoPtr hasElopageTask = new model::table::UserHasElopageTask(email); + hasElopageTask->scheduleTask(hasElopageTask); + auto user_state = session->loadUser(email, password); auto user_model = session->getNewUser()->getModel(); Poco::JSON::Array infos; @@ -148,11 +146,9 @@ Poco::JSON::Object* JsonUnsecureLogin::handle(Poco::Dynamic::Var params) session->setClientIp(mClientIP); if(infos.size() > 0) { result->set("info", infos); - } - if (hasElopage) { - auto elopage_buy = Poco::AutoPtr(new model::table::ElopageBuy); - result->set("hasElopage", elopage_buy->isExistInDB("email", user_model->getEmail())); - } + } + AWAIT(hasElopageTask) + result->set("hasElopage", hasElopageTask->hasElopage()); return result; default: result->set("state", "error"); diff --git a/login_server/src/cpp/model/table/ElopageBuy.cpp b/login_server/src/cpp/model/table/ElopageBuy.cpp index c056ecdc9..6ee23d2ee 100644 --- a/login_server/src/cpp/model/table/ElopageBuy.cpp +++ b/login_server/src/cpp/model/table/ElopageBuy.cpp @@ -108,6 +108,14 @@ namespace model { return select; } + + // --------------------------- Tasks -------------------------------------------- + int UserHasElopageTask::run() + { + auto elopage_buy = Poco::AutoPtr(new model::table::ElopageBuy); + bool hasElopage = elopage_buy->isExistInDB("email", mEmail); + return 0; + } } } diff --git a/login_server/src/cpp/model/table/ElopageBuy.h b/login_server/src/cpp/model/table/ElopageBuy.h index 83b2b477b..008a11a52 100644 --- a/login_server/src/cpp/model/table/ElopageBuy.h +++ b/login_server/src/cpp/model/table/ElopageBuy.h @@ -52,6 +52,22 @@ namespace model { Poco::DateTime mSuccessDate; std::string mEvent; }; + + + // check for user existing + class UserHasElopageTask : public UniLib::controller::CPUTask + { + public: + UserHasElopageTask(std::string email) : mEmail(email), mHasElopage(false) {} + + int run(); + const char* getResourceType() const { return "UserHasElopageTask"; }; + bool hasElopage() const { return mHasElopage; } + + protected: + std::string mEmail; + bool mHasElopage; + }; } } diff --git a/login_server/src/cpp/tasks/CPUTask.h b/login_server/src/cpp/tasks/CPUTask.h index e1c1d5cc0..f96e5d9ec 100644 --- a/login_server/src/cpp/tasks/CPUTask.h +++ b/login_server/src/cpp/tasks/CPUTask.h @@ -68,5 +68,7 @@ namespace UniLib { } } +#define AWAIT(task) while (!hasElopageTask->isTaskFinished()) { Poco::Thread::sleep(10); } + #endif //__DR_UNIVERSUM_LIB_CONTROLLER_CPU_TASK_H__ \ No newline at end of file From 7699700b933c58bc55c5cc2004dd6163ad551bb3 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Sun, 10 Oct 2021 15:29:44 +0200 Subject: [PATCH 010/113] fix lint --- backend/src/graphql/resolver/UserResolver.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index a7e7e39b5..24e2c2c64 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -31,10 +31,7 @@ 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 }: UnsecureLoginArgs, @Ctx() context: any): Promise { email = email.trim().toLowerCase() const result = await apiPost(CONFIG.LOGIN_API_URL + 'unsecureLogin', { email, From 909c7e3a9a79c6eca81e8e7d69cded08b31eba30 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Sun, 10 Oct 2021 15:29:44 +0200 Subject: [PATCH 011/113] fix lint --- backend/src/graphql/resolver/UserResolver.ts | 10 ++-------- docu/login_server.api.md | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index a7e7e39b5..bbb609d40 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -31,15 +31,9 @@ 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 }: UnsecureLoginArgs, @Ctx() context: any): Promise { email = email.trim().toLowerCase() - const result = await apiPost(CONFIG.LOGIN_API_URL + 'unsecureLogin', { - email, - password, - }) + const result = await apiPost(CONFIG.LOGIN_API_URL + 'unsecureLogin', { email, password }) // if there is no user, throw an authentication error if (!result.success) { diff --git a/docu/login_server.api.md b/docu/login_server.api.md index b56852010..c220dd427 100644 --- a/docu/login_server.api.md +++ b/docu/login_server.api.md @@ -39,7 +39,7 @@ with: { "email": "max.musterman@gmail.de", "username": "Maxilein", - "password": "123abcDE&" + "password": "123abcDE&", "hasElopage": true } ``` From 2c90bbe314d3158ce20ed9973e378c266023df9a Mon Sep 17 00:00:00 2001 From: Einhornimmond Date: Sun, 10 Oct 2021 16:37:07 +0200 Subject: [PATCH 012/113] add check for empty user list --- backend/src/typeorm/repository/User.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/src/typeorm/repository/User.ts b/backend/src/typeorm/repository/User.ts index 2a2299a4c..86f7119c4 100644 --- a/backend/src/typeorm/repository/User.ts +++ b/backend/src/typeorm/repository/User.ts @@ -10,6 +10,7 @@ export class UserRepository extends Repository { } async getUsersIndiced(userIds: number[]): Promise { + if (!userIds.length) return [] const users = await this.createQueryBuilder('user') .select(['user.id', 'user.firstName', 'user.lastName', 'user.email']) .where('user.id IN (:...users)', { users: userIds }) From 660e1e4b68f040f44fddf494966a0b1fc64e09ca Mon Sep 17 00:00:00 2001 From: Einhornimmond Date: Sun, 10 Oct 2021 17:27:42 +0200 Subject: [PATCH 013/113] add call for checkpid on gdt server --- backend/src/graphql/resolver/GdtResolver.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/GdtResolver.ts b/backend/src/graphql/resolver/GdtResolver.ts index 9ca9421f6..c99c7e6c7 100644 --- a/backend/src/graphql/resolver/GdtResolver.ts +++ b/backend/src/graphql/resolver/GdtResolver.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ -import { Resolver, Query, Args, Ctx, Authorized } from 'type-graphql' +import { Resolver, Query, Args, Ctx, Authorized, Arg } from 'type-graphql' import { getCustomRepository } from 'typeorm' import CONFIG from '../../config' import { GdtEntryList } from '../model/GdtEntryList' @@ -32,4 +32,16 @@ export class GdtResolver { } return new GdtEntryList(resultGDT.data) } + + @Authorized() + @Query(() => Number) + // eslint-disable-next-line @typescript-eslint/no-explicit-any + async checkPid(@Arg('pid') id: number): Promise { + // load user + const resultPID = await apiGet(`${CONFIG.GDT_API_URL}/publishers/checkPidApi/${id}`) + if (!resultPID.success) { + throw new Error(resultPID.data) + } + return resultPID + } } From 3a5aa25fec6108608aeb4fb645a37cd5559761b4 Mon Sep 17 00:00:00 2001 From: Einhornimmond Date: Mon, 11 Oct 2021 13:11:50 +0200 Subject: [PATCH 014/113] update variable names --- backend/src/graphql/resolver/GdtResolver.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/graphql/resolver/GdtResolver.ts b/backend/src/graphql/resolver/GdtResolver.ts index c99c7e6c7..7ffc47e95 100644 --- a/backend/src/graphql/resolver/GdtResolver.ts +++ b/backend/src/graphql/resolver/GdtResolver.ts @@ -36,12 +36,12 @@ export class GdtResolver { @Authorized() @Query(() => Number) // eslint-disable-next-line @typescript-eslint/no-explicit-any - async checkPid(@Arg('pid') id: number): Promise { + async checkPid(@Arg('pid') pid: number): Promise { // load user - const resultPID = await apiGet(`${CONFIG.GDT_API_URL}/publishers/checkPidApi/${id}`) + const resultPID = await apiGet(`${CONFIG.GDT_API_URL}/publishers/checkPidApi/${pid}`) if (!resultPID.success) { throw new Error(resultPID.data) } - return resultPID + return resultPID.data.pid } } From cceca9d517462baa5791575efe675d52b159d465 Mon Sep 17 00:00:00 2001 From: Einhornimmond Date: Mon, 11 Oct 2021 13:12:26 +0200 Subject: [PATCH 015/113] change query name --- backend/src/graphql/resolver/GdtResolver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/GdtResolver.ts b/backend/src/graphql/resolver/GdtResolver.ts index 7ffc47e95..b4f9a512b 100644 --- a/backend/src/graphql/resolver/GdtResolver.ts +++ b/backend/src/graphql/resolver/GdtResolver.ts @@ -36,7 +36,7 @@ export class GdtResolver { @Authorized() @Query(() => Number) // eslint-disable-next-line @typescript-eslint/no-explicit-any - async checkPid(@Arg('pid') pid: number): Promise { + async existPid(@Arg('pid') pid: number): Promise { // load user const resultPID = await apiGet(`${CONFIG.GDT_API_URL}/publishers/checkPidApi/${pid}`) if (!resultPID.success) { From 67ea9738458274e39b9faa46db718ebfdab32d65 Mon Sep 17 00:00:00 2001 From: elweyn Date: Tue, 12 Oct 2021 11:40:37 +0200 Subject: [PATCH 016/113] Adding a hasEloage flag to the store. --- frontend/src/store/store.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/frontend/src/store/store.js b/frontend/src/store/store.js index 03e1915ca..cb2c7b42a 100644 --- a/frontend/src/store/store.js +++ b/frontend/src/store/store.js @@ -38,6 +38,9 @@ export const mutations = { coinanimation: (state, coinanimation) => { state.coinanimation = coinanimation }, + hasElopage: (state, hasElopage) => { + state.hasElopage = hasElopage + }, } export const actions = { @@ -50,6 +53,7 @@ export const actions = { commit('description', data.description) commit('coinanimation', data.coinanimation) commit('newsletterState', data.klickTipp.newsletterState) + commit('hasElopage', data.hasElopage) }, logout: ({ commit, state }) => { commit('token', null) @@ -60,6 +64,7 @@ export const actions = { commit('description', '') commit('coinanimation', true) commit('newsletterState', null) + commit('hasElopage', false) localStorage.clear() }, } @@ -81,6 +86,7 @@ export const store = new Vuex.Store({ coinanimation: true, newsletterState: null, community: null, + hasElopage: false, }, getters: {}, // Syncronous mutation of the state From fb93b39a194d33562bdcc030811a9a5b3accb33d Mon Sep 17 00:00:00 2001 From: elweyn Date: Tue, 12 Oct 2021 12:31:37 +0200 Subject: [PATCH 017/113] Changed the logic behind the link to elopage, when user has an account it sends to the login page, else it sends to the registration process of elopage --- frontend/src/components/SidebarPlugin/SideBar.vue | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/frontend/src/components/SidebarPlugin/SideBar.vue b/frontend/src/components/SidebarPlugin/SideBar.vue index 519a4f0b1..312be6b8a 100755 --- a/frontend/src/components/SidebarPlugin/SideBar.vue +++ b/frontend/src/components/SidebarPlugin/SideBar.vue @@ -47,12 +47,9 @@
@@ -114,6 +111,11 @@ export default { logout() { this.$emit('logout') }, + getElopageLink() { + return this.$store.state.hasElopage + ? `https://elopage.com/s/gradido/sign_in?locale=${this.$i18n.locale}&email=${this.$store.state.email}` + : `https://elopage.com/s/gradido/basic-de/payment?locale=de&prid=111&pid=${this.$store.state.publisherId}&firstName=${this.$store.state.firstName}&lastName=${this.$store.state.lastName}&email=${this.$store.state.email}` + }, }, } From f7d696eaca39be818b853a816e64aa8f9e0c376a Mon Sep 17 00:00:00 2001 From: elweyn Date: Tue, 12 Oct 2021 12:46:57 +0200 Subject: [PATCH 018/113] Tests that the hasElopage flag is changed. --- frontend/src/store/store.test.js | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/frontend/src/store/store.test.js b/frontend/src/store/store.test.js index 19937eed4..ecdfb9f11 100644 --- a/frontend/src/store/store.test.js +++ b/frontend/src/store/store.test.js @@ -12,6 +12,7 @@ const { newsletterState, publisherId, community, + hasElopage, } = mutations const { login, logout } = actions @@ -114,6 +115,14 @@ describe('Vuex store', () => { }) }) }) + + describe('hasElopage', () => { + it('sets the state of hasElopage', () => { + const state = { hasElopage: false } + hasElopage(state, true) + expect(state.hasElopage).toBeTruthy() + }) + }) }) describe('actions', () => { @@ -131,11 +140,12 @@ describe('Vuex store', () => { klickTipp: { newsletterState: true, }, + hasElopage: false, } - it('calls eight commits', () => { + it('calls nine commits', () => { login({ commit, state }, commitedData) - expect(commit).toHaveBeenCalledTimes(8) + expect(commit).toHaveBeenCalledTimes(9) }) it('commits email', () => { @@ -177,15 +187,20 @@ describe('Vuex store', () => { login({ commit, state }, commitedData) expect(commit).toHaveBeenNthCalledWith(8, 'newsletterState', true) }) + + it('commits hasElopage', () => { + login({ commit, state }, commitedData) + expect(commit).toHaveBeenNthCalledWith(9, 'hasElopage', false) + }) }) describe('logout', () => { const commit = jest.fn() const state = {} - it('calls eight commits', () => { + it('calls nine commits', () => { logout({ commit, state }) - expect(commit).toHaveBeenCalledTimes(8) + expect(commit).toHaveBeenCalledTimes(9) }) it('commits token', () => { @@ -228,6 +243,11 @@ describe('Vuex store', () => { expect(commit).toHaveBeenNthCalledWith(8, 'newsletterState', null) }) + it('commits hasElopage', () => { + logout({ commit, state }) + expect(commit).toHaveBeenNthCalledWith(9, 'hasElopage', false) + }) + // how to get this working? it.skip('calls localStorage.clear()', () => { const clearStorageMock = jest.fn() From 61896c421fd1c480d89c48af046ee6b3825efb05 Mon Sep 17 00:00:00 2001 From: elweyn Date: Tue, 12 Oct 2021 13:15:35 +0200 Subject: [PATCH 019/113] Tested the new functionality, and fixed the links. --- .../components/SidebarPlugin/SideBar.spec.js | 32 ++++++++++++++++--- .../src/components/SidebarPlugin/SideBar.vue | 4 +-- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/frontend/src/components/SidebarPlugin/SideBar.spec.js b/frontend/src/components/SidebarPlugin/SideBar.spec.js index 9f182ca93..385c2bbef 100644 --- a/frontend/src/components/SidebarPlugin/SideBar.spec.js +++ b/frontend/src/components/SidebarPlugin/SideBar.spec.js @@ -18,6 +18,10 @@ describe('SideBar', () => { $store: { state: { email: 'test@example.org', + publisherId: 123, + firstName: 'test', + lastName: 'example', + hasElopage: false, }, commit: jest.fn(), }, @@ -80,12 +84,16 @@ describe('SideBar', () => { describe('static menu items', () => { describe("member's area", () => { it('has a link to the elopage', () => { - expect(wrapper.findAll('li').at(0).text()).toBe('members_area') + expect(wrapper.findAll('li').at(0).text()).toContain('members_area') }) - it('links to the elopage', () => { + it('has a badge', () => { + expect(wrapper.findAll('li').at(0).text()).toContain('!') + }) + + it('links to the elopage registration', () => { expect(wrapper.findAll('li').at(0).find('a').attributes('href')).toBe( - 'https://elopage.com/s/gradido/sign_in?locale=en', + 'https://elopage.com/s/gradido/basic-de/payment?locale=en&prid=111&pid=123&firstName=test&lastName=example&email=test@example.org', ) }) @@ -94,11 +102,27 @@ describe('SideBar', () => { mocks.$i18n.locale = 'de' }) - it('links to the German elopage when locale is set to de', () => { + it('links to the German elopage registration when locale is set to de', () => { + expect(wrapper.findAll('li').at(0).find('a').attributes('href')).toBe( + 'https://elopage.com/s/gradido/basic-de/payment?locale=de&prid=111&pid=123&firstName=test&lastName=example&email=test@example.org', + ) + }) + }) + + describe('with hasElopage is true', () => { + beforeEach(() => { + mocks.$store.state.hasElopage = true + }) + + it('links to the elopage member area', () => { expect(wrapper.findAll('li').at(0).find('a').attributes('href')).toBe( 'https://elopage.com/s/gradido/sign_in?locale=de', ) }) + + it('has no badge', () => { + expect(wrapper.findAll('li').at(0).text()).not.toContain('!') + }) }) }) diff --git a/frontend/src/components/SidebarPlugin/SideBar.vue b/frontend/src/components/SidebarPlugin/SideBar.vue index 312be6b8a..9dc0a2765 100755 --- a/frontend/src/components/SidebarPlugin/SideBar.vue +++ b/frontend/src/components/SidebarPlugin/SideBar.vue @@ -113,8 +113,8 @@ export default { }, getElopageLink() { return this.$store.state.hasElopage - ? `https://elopage.com/s/gradido/sign_in?locale=${this.$i18n.locale}&email=${this.$store.state.email}` - : `https://elopage.com/s/gradido/basic-de/payment?locale=de&prid=111&pid=${this.$store.state.publisherId}&firstName=${this.$store.state.firstName}&lastName=${this.$store.state.lastName}&email=${this.$store.state.email}` + ? `https://elopage.com/s/gradido/sign_in?locale=${this.$i18n.locale}` + : `https://elopage.com/s/gradido/basic-de/payment?locale=${this.$i18n.locale}&prid=111&pid=${this.$store.state.publisherId}&firstName=${this.$store.state.firstName}&lastName=${this.$store.state.lastName}&email=${this.$store.state.email}` }, }, } From 3247dad58698f440369b8d415c6164cd2f982a4a Mon Sep 17 00:00:00 2001 From: einhorn_b Date: Tue, 12 Oct 2021 14:22:19 +0200 Subject: [PATCH 020/113] update doc --- docu/login_server.api.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docu/login_server.api.md b/docu/login_server.api.md index c220dd427..aeac22549 100644 --- a/docu/login_server.api.md +++ b/docu/login_server.api.md @@ -39,13 +39,11 @@ with: { "email": "max.musterman@gmail.de", "username": "Maxilein", - "password": "123abcDE&", - "hasElopage": true + "password": "123abcDE&" } ``` `username` or `email` must be present! If booth present, `email` will be used. -`hasElopage`: optional, if set to true login will also check if user has an elopage account ### Response In case of success returns: From 1486476571a89915142e316002f0feab09a6da90 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Tue, 12 Oct 2021 15:24:14 +0200 Subject: [PATCH 021/113] add auto correct keys to apollo, copy also disabled field of user --- backend/src/graphql/model/User.ts | 3 +-- backend/src/graphql/resolver/UserResolver.ts | 17 ++++++++++++++++- login_server/src/cpp/Crypto/Passphrase.cpp | 1 + .../cpp/JSONInterface/JsonRequestHandler.cpp | 16 ++++++++++++---- .../src/cpp/JSONInterface/JsonUnsecureLogin.cpp | 8 ++++++++ login_server/src/cpp/model/Session.cpp | 2 +- 6 files changed, 39 insertions(+), 8 deletions(-) diff --git a/backend/src/graphql/model/User.ts b/backend/src/graphql/model/User.ts index 21bf1b464..03a0908b1 100644 --- a/backend/src/graphql/model/User.ts +++ b/backend/src/graphql/model/User.ts @@ -19,6 +19,7 @@ export class User { this.pubkey = json.public_hex this.language = json.language this.publisherId = json.publisher_id + this.disabled = json.disabled } @Field(() => String) @@ -56,10 +57,8 @@ export class User { @Field(() => String) language: string - /* @Field(() => Boolean) disabled: boolean - */ /* I suggest to have a group as type here @Field(() => ID) diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 820e493c6..f5638692e 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -47,7 +47,21 @@ export class UserResolver { const user = new User(result.data.user) // read additional settings from settings table const userRepository = getCustomRepository(UserRepository) - const userEntity = await userRepository.findByPubkeyHex(user.pubkey) + let userEntity: void | DbUser = await userRepository.findByPubkeyHex(user.pubkey).catch(() => {}) + if(!userEntity) { + // create user if it don't exist with this pubkey + userEntity = new DbUser + userEntity.firstName = user.firstName + userEntity.lastName = user.lastName + userEntity.username = user.username + userEntity.email = user.email + userEntity.pubkey = Buffer.from(fromHex(user.pubkey)) + userEntity.disabled = user.disabled + + userEntity.save().catch(() => { + throw new Error('error by save userEntity') + }) + } const userSettingRepository = getCustomRepository(UserSettingRepository) const coinanimation = await userSettingRepository @@ -111,6 +125,7 @@ export class UserResolver { dbuser.firstName = user.firstName dbuser.lastName = user.lastName dbuser.username = user.username + dbuser.disabled = user.disabled dbuser.save().catch(() => { throw new Error('error saving user') diff --git a/login_server/src/cpp/Crypto/Passphrase.cpp b/login_server/src/cpp/Crypto/Passphrase.cpp index 6b3df0c5d..0b733777d 100644 --- a/login_server/src/cpp/Crypto/Passphrase.cpp +++ b/login_server/src/cpp/Crypto/Passphrase.cpp @@ -328,6 +328,7 @@ const Poco::UInt16* Passphrase::getWordIndices() const bool Passphrase::checkIfValid() { + if (!mWordSource) return false; std::istringstream iss(mPassphraseString); std::vector results(std::istream_iterator{iss}, std::istream_iterator()); diff --git a/login_server/src/cpp/JSONInterface/JsonRequestHandler.cpp b/login_server/src/cpp/JSONInterface/JsonRequestHandler.cpp index feab7043b..15846913b 100644 --- a/login_server/src/cpp/JSONInterface/JsonRequestHandler.cpp +++ b/login_server/src/cpp/JSONInterface/JsonRequestHandler.cpp @@ -81,22 +81,30 @@ void JsonRequestHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Po } if (json_result) { + NotificationList errors; if (!json_result->isNull("session_id")) { int session_id = 0; try { json_result->get("session_id").convert(session_id); } catch (Poco::Exception& e) { - NotificationList erros; - erros.addError(new Error("json request", "invalid session_id")); - erros.sendErrorsAsEmail(); + errors.addError(new Error("json request", "invalid session_id")); } if (session_id) { auto session = SessionManager::getInstance()->getSession(session_id); response.addCookie(session->getLoginCookie()); } } - json_result->stringify(responseStream); + try { + json_result->stringify(responseStream); + } + catch (Poco::Exception& e) { + errors.addError(new ParamError("json request", "error on stringify from json result:", e.message())); + errors.addError(new ParamError("json request", "caller url", request.getURI())); + } + if (errors.errorCount()) { + errors.sendErrorsAsEmail(); + } delete json_result; } diff --git a/login_server/src/cpp/JSONInterface/JsonUnsecureLogin.cpp b/login_server/src/cpp/JSONInterface/JsonUnsecureLogin.cpp index 5d337df41..0335448aa 100644 --- a/login_server/src/cpp/JSONInterface/JsonUnsecureLogin.cpp +++ b/login_server/src/cpp/JSONInterface/JsonUnsecureLogin.cpp @@ -108,6 +108,14 @@ Poco::JSON::Object* JsonUnsecureLogin::handle(Poco::Dynamic::Var params) auto user_state = session->loadUser(email, password); auto user_model = session->getNewUser()->getModel(); Poco::JSON::Array infos; + + // AUTOMATIC ERROR CORRECTION + // if something went wrong by initial key generation for user, generate keys again + if (user_state >= USER_LOADED_FROM_DB && !user_model->getPublicKey()) { + if (mSession->generateKeys(true, true)) { + user_state = session->getNewUser()->getUserState(); + } + } switch (user_state) { case USER_EMPTY: diff --git a/login_server/src/cpp/model/Session.cpp b/login_server/src/cpp/model/Session.cpp index cf380929d..2fdd9ff2f 100644 --- a/login_server/src/cpp/model/Session.cpp +++ b/login_server/src/cpp/model/Session.cpp @@ -746,7 +746,7 @@ void Session::detectSessionState() bool cryptedPassphrase = userBackups.size() > 0; for (auto it = userBackups.begin(); it != userBackups.end(); it++) { auto passphrase = (*it)->getModel()->getPassphrase(); - Mnemonic* wordSource = nullptr; + const Mnemonic* wordSource = Passphrase::detectMnemonic(passphrase); auto passphrase_obj = Passphrase::create(passphrase, wordSource); if (!passphrase_obj.isNull() && passphrase_obj->checkIfValid()) { auto key_pair = KeyPairEd25519::create(passphrase_obj); From 86efd0de80cedb571c6fe781df4e1aa60aa723ae Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Tue, 12 Oct 2021 15:34:50 +0200 Subject: [PATCH 022/113] fix bug --- login_server/src/cpp/JSONInterface/JsonUnsecureLogin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/login_server/src/cpp/JSONInterface/JsonUnsecureLogin.cpp b/login_server/src/cpp/JSONInterface/JsonUnsecureLogin.cpp index 0335448aa..25cda34ca 100644 --- a/login_server/src/cpp/JSONInterface/JsonUnsecureLogin.cpp +++ b/login_server/src/cpp/JSONInterface/JsonUnsecureLogin.cpp @@ -112,7 +112,7 @@ Poco::JSON::Object* JsonUnsecureLogin::handle(Poco::Dynamic::Var params) // AUTOMATIC ERROR CORRECTION // if something went wrong by initial key generation for user, generate keys again if (user_state >= USER_LOADED_FROM_DB && !user_model->getPublicKey()) { - if (mSession->generateKeys(true, true)) { + if (session->generateKeys(true, true)) { user_state = session->getNewUser()->getUserState(); } } From 0640eb24d57b7f5215611731e15f2c9825851f88 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Tue, 12 Oct 2021 15:42:48 +0200 Subject: [PATCH 023/113] remove copy user disabled field --- backend/src/graphql/model/User.ts | 3 ++- backend/src/graphql/resolver/UserResolver.ts | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/graphql/model/User.ts b/backend/src/graphql/model/User.ts index 03a0908b1..21bf1b464 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.disabled = json.disabled } @Field(() => String) @@ -57,8 +56,10 @@ export class User { @Field(() => String) language: string + /* @Field(() => Boolean) disabled: boolean + */ /* I suggest to have a group as type here @Field(() => ID) diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index f5638692e..9be7ba3b3 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -56,7 +56,7 @@ export class UserResolver { userEntity.username = user.username userEntity.email = user.email userEntity.pubkey = Buffer.from(fromHex(user.pubkey)) - userEntity.disabled = user.disabled + userEntity.save().catch(() => { throw new Error('error by save userEntity') @@ -125,7 +125,6 @@ export class UserResolver { dbuser.firstName = user.firstName dbuser.lastName = user.lastName dbuser.username = user.username - dbuser.disabled = user.disabled dbuser.save().catch(() => { throw new Error('error saving user') From 3ecf960ab6231e7c5bbc566d5b71c2a7d6e30f8c Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Tue, 12 Oct 2021 15:56:02 +0200 Subject: [PATCH 024/113] fix lint --- backend/src/graphql/resolver/UserResolver.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 9be7ba3b3..8cf059f32 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -47,20 +47,21 @@ export class UserResolver { const user = new User(result.data.user) // read additional settings from settings table const userRepository = getCustomRepository(UserRepository) - let userEntity: void | DbUser = await userRepository.findByPubkeyHex(user.pubkey).catch(() => {}) - if(!userEntity) { - // create user if it don't exist with this pubkey - userEntity = new DbUser + let userEntity: void | DbUser + userEntity = await userRepository.findByPubkeyHex(user.pubkey).catch(() => { + userEntity = new DbUser() userEntity.firstName = user.firstName userEntity.lastName = user.lastName userEntity.username = user.username userEntity.email = user.email userEntity.pubkey = Buffer.from(fromHex(user.pubkey)) - userEntity.save().catch(() => { throw new Error('error by save userEntity') }) + }) + if (!userEntity) { + throw new Error('error with cannot happen') } const userSettingRepository = getCustomRepository(UserSettingRepository) From 3b487ab2cbd358f9d9c4479bdd0a70dff35c4a3a Mon Sep 17 00:00:00 2001 From: einhorn_b Date: Tue, 12 Oct 2021 16:17:19 +0200 Subject: [PATCH 025/113] fix field name --- login_server/src/cpp/model/table/ElopageBuy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/login_server/src/cpp/model/table/ElopageBuy.cpp b/login_server/src/cpp/model/table/ElopageBuy.cpp index 6ee23d2ee..ff79f6a68 100644 --- a/login_server/src/cpp/model/table/ElopageBuy.cpp +++ b/login_server/src/cpp/model/table/ElopageBuy.cpp @@ -113,7 +113,7 @@ namespace model { int UserHasElopageTask::run() { auto elopage_buy = Poco::AutoPtr(new model::table::ElopageBuy); - bool hasElopage = elopage_buy->isExistInDB("email", mEmail); + bool hasElopage = elopage_buy->isExistInDB("payer_email", mEmail); return 0; } } From 36e6a459a4c525119e2809b95f4b24b6d487f757 Mon Sep 17 00:00:00 2001 From: elweyn Date: Tue, 12 Oct 2021 16:49:14 +0200 Subject: [PATCH 026/113] Fixe small error. --- login_server/src/cpp/JSONInterface/JsonHasElopage.cpp | 2 +- login_server/src/cpp/model/table/ElopageBuy.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/login_server/src/cpp/JSONInterface/JsonHasElopage.cpp b/login_server/src/cpp/JSONInterface/JsonHasElopage.cpp index ee66255be..202f45fca 100644 --- a/login_server/src/cpp/JSONInterface/JsonHasElopage.cpp +++ b/login_server/src/cpp/JSONInterface/JsonHasElopage.cpp @@ -10,7 +10,7 @@ Poco::JSON::Object* JsonHasElopage::handle(Poco::Dynamic::Var params) auto elopage_buy = Poco::AutoPtr(new model::table::ElopageBuy); result = stateSuccess(); - result->set("hasElopage", elopage_buy->isExistInDB("email", mSession->getNewUser()->getModel()->getEmail())); + result->set("hasElopage", elopage_buy->isExistInDB("payer_email", mSession->getNewUser()->getModel()->getEmail())); return result; } \ No newline at end of file diff --git a/login_server/src/cpp/model/table/ElopageBuy.cpp b/login_server/src/cpp/model/table/ElopageBuy.cpp index ff79f6a68..9aeaf291f 100644 --- a/login_server/src/cpp/model/table/ElopageBuy.cpp +++ b/login_server/src/cpp/model/table/ElopageBuy.cpp @@ -113,7 +113,7 @@ namespace model { int UserHasElopageTask::run() { auto elopage_buy = Poco::AutoPtr(new model::table::ElopageBuy); - bool hasElopage = elopage_buy->isExistInDB("payer_email", mEmail); + mHasElopage = elopage_buy->isExistInDB("payer_email", mEmail); return 0; } } From d3198b037e4038a61ac41162cd199fff335ced18 Mon Sep 17 00:00:00 2001 From: elweyn Date: Tue, 12 Oct 2021 16:50:07 +0200 Subject: [PATCH 027/113] Fixe model for User and adding hasElopage to User Object. --- backend/src/graphql/model/User.ts | 4 ++-- backend/src/graphql/resolver/UserResolver.ts | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/src/graphql/model/User.ts b/backend/src/graphql/model/User.ts index ebdf0aad2..7d2d4af05 100644 --- a/backend/src/graphql/model/User.ts +++ b/backend/src/graphql/model/User.ts @@ -19,7 +19,7 @@ export class User { this.pubkey = json.public_hex this.language = json.language this.publisherId = json.publisher_id - if (json.hasElopage) this.hasElopage = json.hasElopage + this.hasElopage = json.hasElopage } @Field(() => String) @@ -76,6 +76,6 @@ export class User { @Field(() => KlickTipp) klickTipp: KlickTipp - @Field(() => Boolean) + @Field(() => Boolean, { nullable: true }) hasElopage?: boolean } diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index bbb609d40..fb76daafa 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -45,6 +45,7 @@ export class UserResolver { value: encode(result.data.session_id, result.data.user.public_hex), }) const user = new User(result.data.user) + user.hasElopage = result.data.hasElopage // read additional settings from settings table const userRepository = getCustomRepository(UserRepository) const userEntity = await userRepository.findByPubkeyHex(user.pubkey) From 2d218e86ce194dd288bf21d816b05e0f364d7a76 Mon Sep 17 00:00:00 2001 From: elweyn Date: Tue, 12 Oct 2021 16:50:26 +0200 Subject: [PATCH 028/113] Asking for hasElopage in login. --- frontend/src/graphql/queries.js | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/src/graphql/queries.js b/frontend/src/graphql/queries.js index 3499a3fa1..40cc359cf 100644 --- a/frontend/src/graphql/queries.js +++ b/frontend/src/graphql/queries.js @@ -13,6 +13,7 @@ export const login = gql` klickTipp { newsletterState } + hasElopage } } ` From 8f2289ebf2c3a5d4822a3b2976df4721895e3e5d Mon Sep 17 00:00:00 2001 From: elweyn Date: Tue, 12 Oct 2021 17:07:27 +0200 Subject: [PATCH 029/113] Changed the test for the members area & it's link. --- frontend/src/views/Layout/DashboardLayout_gdd.spec.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/frontend/src/views/Layout/DashboardLayout_gdd.spec.js b/frontend/src/views/Layout/DashboardLayout_gdd.spec.js index 6555d1dda..107ee7f27 100644 --- a/frontend/src/views/Layout/DashboardLayout_gdd.spec.js +++ b/frontend/src/views/Layout/DashboardLayout_gdd.spec.js @@ -45,6 +45,9 @@ describe('DashboardLayoutGdd', () => { $store: { state: { email: 'user@example.org', + publisherId: 123, + firstName: 'User', + lastName: 'Example', }, dispatch: storeDispatchMock, commit: storeCommitMock, @@ -114,9 +117,10 @@ describe('DashboardLayoutGdd', () => { }) it('has a link to the members area', () => { - expect(wrapper.findAll('ul').at(2).text()).toBe('members_area') + expect(wrapper.findAll('ul').at(2).text()).toContain('members_area') + expect(wrapper.findAll('ul').at(2).text()).toContain('!') expect(wrapper.findAll('ul').at(2).find('a').attributes('href')).toBe( - 'https://elopage.com/s/gradido/sign_in?locale=en', + 'https://elopage.com/s/gradido/basic-de/payment?locale=en&prid=111&pid=123&firstName=User&lastName=Example&email=user@example.org', ) }) From f2ec81e2b242afac35301ed261fcc6700e987cdd Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 12 Oct 2021 21:28:29 +0200 Subject: [PATCH 030/113] feat: In Production only Show one Community --- backend/.env.dist | 1 + backend/src/config/index.ts | 1 + .../src/graphql/resolver/CommunityResolver.ts | 17 ++++++++++++----- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/backend/.env.dist b/backend/.env.dist index 3ac50ac9b..359b41d3c 100644 --- a/backend/.env.dist +++ b/backend/.env.dist @@ -1,3 +1,4 @@ +PRODUCTION= PORT=4000 JWT_SECRET=secret123 JWT_EXPIRES_IN=10m diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index 76ba597ad..6142ae3ba 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -11,6 +11,7 @@ const server = { LOGIN_API_URL: process.env.LOGIN_API_URL || 'http://login-server:1201/', COMMUNITY_API_URL: process.env.COMMUNITY_API_URL || 'http://nginx/api/', GDT_API_URL: process.env.GDT_API_URL || 'https://gdt.gradido.net', + PRODUCTION: process.env.PRODUCTION === 'true' || false, } const database = { diff --git a/backend/src/graphql/resolver/CommunityResolver.ts b/backend/src/graphql/resolver/CommunityResolver.ts index 563c73d24..84d252064 100644 --- a/backend/src/graphql/resolver/CommunityResolver.ts +++ b/backend/src/graphql/resolver/CommunityResolver.ts @@ -19,9 +19,17 @@ export class CommunityResolver { @Query(() => [Community]) async communities(): Promise { - const communities: Community[] = [] - - communities.push( + if (CONFIG.PRODUCTION) + return [ + new Community({ + id: 3, + name: 'Gradido-Akademie', + description: 'Freies Institut für Wirtschaftsbionik.', + url: 'https://gradido.net', + registerUrl: 'https://gdd1.gradido.com/vue/register-community', + }), + ] + return [ new Community({ id: 1, name: 'Gradido Entwicklung', @@ -43,7 +51,6 @@ export class CommunityResolver { url: 'https://gradido.net', registerUrl: 'https://gdd1.gradido.com/vue/register-community', }), - ) - return communities + ] } } From efed348a9446a4c5c9aef10a6ba3c65a4efadfa7 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Wed, 13 Oct 2021 05:34:14 +0200 Subject: [PATCH 031/113] Change the Test name so that we see if their is a publisher ID or not Co-authored-by: Moriz Wahl --- frontend/src/components/SidebarPlugin/SideBar.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/components/SidebarPlugin/SideBar.spec.js b/frontend/src/components/SidebarPlugin/SideBar.spec.js index 385c2bbef..2792c16b6 100644 --- a/frontend/src/components/SidebarPlugin/SideBar.spec.js +++ b/frontend/src/components/SidebarPlugin/SideBar.spec.js @@ -82,7 +82,7 @@ describe('SideBar', () => { }) describe('static menu items', () => { - describe("member's area", () => { + describe("member's area without publisher ID", () => { it('has a link to the elopage', () => { expect(wrapper.findAll('li').at(0).text()).toContain('members_area') }) From 2506480a52eef1d1046ef2fc46fc5f62f0dc1339 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Wed, 13 Oct 2021 05:35:06 +0200 Subject: [PATCH 032/113] Update frontend/src/components/SidebarPlugin/SideBar.spec.js Co-authored-by: Moriz Wahl --- frontend/src/components/SidebarPlugin/SideBar.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/components/SidebarPlugin/SideBar.spec.js b/frontend/src/components/SidebarPlugin/SideBar.spec.js index 2792c16b6..993fdf195 100644 --- a/frontend/src/components/SidebarPlugin/SideBar.spec.js +++ b/frontend/src/components/SidebarPlugin/SideBar.spec.js @@ -109,7 +109,7 @@ describe('SideBar', () => { }) }) - describe('with hasElopage is true', () => { + describe('member's area with publisher ID', () => { beforeEach(() => { mocks.$store.state.hasElopage = true }) From 861fc217662b62a7c5270bf2a4288fc63a4510eb Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Wed, 13 Oct 2021 05:35:48 +0200 Subject: [PATCH 033/113] Update frontend/src/components/SidebarPlugin/SideBar.vue Co-authored-by: Moriz Wahl --- frontend/src/components/SidebarPlugin/SideBar.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/components/SidebarPlugin/SideBar.vue b/frontend/src/components/SidebarPlugin/SideBar.vue index 9dc0a2765..5971b7b4e 100755 --- a/frontend/src/components/SidebarPlugin/SideBar.vue +++ b/frontend/src/components/SidebarPlugin/SideBar.vue @@ -114,7 +114,7 @@ export default { getElopageLink() { return this.$store.state.hasElopage ? `https://elopage.com/s/gradido/sign_in?locale=${this.$i18n.locale}` - : `https://elopage.com/s/gradido/basic-de/payment?locale=${this.$i18n.locale}&prid=111&pid=${this.$store.state.publisherId}&firstName=${this.$store.state.firstName}&lastName=${this.$store.state.lastName}&email=${this.$store.state.email}` + : encodeURL(`https://elopage.com/s/gradido/basic-de/payment?locale=${this.$i18n.locale}&prid=111&pid=${this.$store.state.publisherId}&firstName=${this.$store.state.firstName}&lastName=${this.$store.state.lastName}&email=${this.$store.state.email})` }, }, } From a1b54e592e9d213f5ae97fb6e8d6c8319b1d81bd Mon Sep 17 00:00:00 2001 From: elweyn Date: Wed, 13 Oct 2021 11:32:00 +0200 Subject: [PATCH 034/113] Changed the logic to catch error send by Klicktipp. --- backend/src/middleware/klicktippMiddleware.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/src/middleware/klicktippMiddleware.ts b/backend/src/middleware/klicktippMiddleware.ts index ab3a9bd4c..856dd9d75 100644 --- a/backend/src/middleware/klicktippMiddleware.ts +++ b/backend/src/middleware/klicktippMiddleware.ts @@ -24,9 +24,13 @@ export const klicktippNewsletterStateMiddleware: MiddlewareFn = async ( const result = await next() let klickTipp = new KlickTipp({ status: 'Unsubscribed' }) if (CONFIG.KLICKTIPP) { - const klickTippUser = await getKlickTippUser(result.email) - if (klickTippUser) { - klickTipp = new KlickTipp(klickTippUser) + try { + const klickTippUser = await getKlickTippUser(result.email) + if (klickTippUser) { + klickTipp = new KlickTipp(klickTippUser) + } + } catch (err) { + console.log('Something went wrong', err) } } result.klickTipp = klickTipp From 5a14161284c4d4d23cafb6f0ba4e2d7dcd159422 Mon Sep 17 00:00:00 2001 From: elweyn Date: Wed, 13 Oct 2021 12:07:23 +0200 Subject: [PATCH 035/113] 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 From 481bd637941494e0888aa6d89aacfb10522724b5 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 13 Oct 2021 12:08:22 +0200 Subject: [PATCH 036/113] production from NODE_ENV, please test --- backend/.env.dist | 1 - backend/src/config/index.ts | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/.env.dist b/backend/.env.dist index 359b41d3c..3ac50ac9b 100644 --- a/backend/.env.dist +++ b/backend/.env.dist @@ -1,4 +1,3 @@ -PRODUCTION= PORT=4000 JWT_SECRET=secret123 JWT_EXPIRES_IN=10m diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index 6142ae3ba..7de498f85 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -11,7 +11,7 @@ const server = { LOGIN_API_URL: process.env.LOGIN_API_URL || 'http://login-server:1201/', COMMUNITY_API_URL: process.env.COMMUNITY_API_URL || 'http://nginx/api/', GDT_API_URL: process.env.GDT_API_URL || 'https://gdt.gradido.net', - PRODUCTION: process.env.PRODUCTION === 'true' || false, + PRODUCTION: process.env.NODE_ENV === 'production' || false, } const database = { From 58182d73c65d7e50e00a38aed15c5ab6543795bc Mon Sep 17 00:00:00 2001 From: elweyn Date: Wed, 13 Oct 2021 13:26:46 +0200 Subject: [PATCH 037/113] Added the publisherId to the login & createUser calls, adjusted the tests to the new code. --- backend/src/graphql/arg/CreateUserArgs.ts | 5 ++++- backend/src/graphql/arg/UnsecureLoginArgs.ts | 4 ++-- backend/src/graphql/model/User.ts | 6 +++--- backend/src/graphql/resolver/UserResolver.ts | 10 ++++++---- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/backend/src/graphql/arg/CreateUserArgs.ts b/backend/src/graphql/arg/CreateUserArgs.ts index 486cb023b..3d09e56eb 100644 --- a/backend/src/graphql/arg/CreateUserArgs.ts +++ b/backend/src/graphql/arg/CreateUserArgs.ts @@ -1,4 +1,4 @@ -import { ArgsType, Field } from 'type-graphql' +import { ArgsType, Field, Int } from 'type-graphql' @ArgsType() export default class CreateUserArgs { @@ -16,4 +16,7 @@ export default class CreateUserArgs { @Field(() => String) language: string + + @Field(() => Int, { nullable: true }) + publisherId: number } diff --git a/backend/src/graphql/arg/UnsecureLoginArgs.ts b/backend/src/graphql/arg/UnsecureLoginArgs.ts index 42e467eee..ac69e7441 100644 --- a/backend/src/graphql/arg/UnsecureLoginArgs.ts +++ b/backend/src/graphql/arg/UnsecureLoginArgs.ts @@ -1,4 +1,4 @@ -import { ArgsType, Field } from 'type-graphql' +import { ArgsType, Field, Int } from 'type-graphql' @ArgsType() export default class UnsecureLoginArgs { @@ -8,6 +8,6 @@ export default class UnsecureLoginArgs { @Field(() => String) password: string - @Field(() => Number, { nullable: true }) + @Field(() => Int, { nullable: true }) publisherId: number } diff --git a/backend/src/graphql/model/User.ts b/backend/src/graphql/model/User.ts index 890e8bdba..08651ae17 100644 --- a/backend/src/graphql/model/User.ts +++ b/backend/src/graphql/model/User.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ -import { ObjectType, Field } from 'type-graphql' +import { ObjectType, Field, Int } from 'type-graphql' import { KlickTipp } from './KlickTipp' @ObjectType() @@ -66,8 +66,8 @@ export class User { groupId: number */ // what is publisherId? - @Field(() => Number) - publisherId: number + @Field(() => Int, { nullable: true }) + publisherId?: number @Field(() => Boolean) coinanimation: boolean diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 1f5667e8f..2dcffb2d9 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -48,6 +48,9 @@ export class UserResolver { value: encode(result.data.session_id, result.data.user.public_hex), }) const user = new User(result.data.user) + if (user.publisherId === 0) { + user.publisherId = undefined + } user.hasElopage = result.data.hasElopage // read additional settings from settings table const userRepository = getCustomRepository(UserRepository) @@ -68,8 +71,7 @@ export class UserResolver { throw new Error('error with cannot happen') } - if (publisherId) { - // Save it + if (!user.hasElopage && publisherId) { user.publisherId = publisherId await this.updateUserInfos( { publisherId }, @@ -115,7 +117,7 @@ export class UserResolver { @Mutation(() => String) async createUser( - @Args() { email, firstName, lastName, password, language }: CreateUserArgs, + @Args() { email, firstName, lastName, password, language, publisherId }: CreateUserArgs, ): Promise { const payload = { email, @@ -125,7 +127,7 @@ export class UserResolver { emailType: 2, login_after_register: true, language: language, - publisher_id: 0, + publisher_id: publisherId, } const result = await apiPost(CONFIG.LOGIN_API_URL + 'createUser', payload) if (!result.success) { From ad11d482e0f1e5593bbbdef1fa661f9a6964d4b9 Mon Sep 17 00:00:00 2001 From: elweyn Date: Wed, 13 Oct 2021 13:35:58 +0200 Subject: [PATCH 038/113] Missing files.. --- .github/workflows/test.yml | 4 +-- frontend/.env.dist | 1 + .../components/SidebarPlugin/SideBar.spec.js | 2 +- .../src/components/SidebarPlugin/SideBar.vue | 12 ++++++--- frontend/src/config/index.js | 1 + frontend/src/graphql/mutations.js | 2 ++ frontend/src/graphql/queries.js | 5 ++-- frontend/src/store/store.js | 6 ++++- frontend/src/store/store.test.js | 25 ++++++++++++++++--- frontend/src/views/Pages/Login.spec.js | 2 ++ frontend/src/views/Pages/Login.vue | 1 + frontend/src/views/Pages/Register.spec.js | 2 ++ frontend/src/views/Pages/Register.vue | 1 + 13 files changed, 51 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index de9939101..e7578dc11 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -386,7 +386,7 @@ jobs: report_name: Coverage Backend type: lcov result_path: ./coverage/lcov.info - min_coverage: 4 + min_coverage: 3 token: ${{ github.token }} ############################################################################## @@ -541,4 +541,4 @@ jobs: - name: database | up run: docker-compose -f docker-compose.yml run -T database yarn up - name: database | reset - run: docker-compose -f docker-compose.yml run -T database yarn reset \ No newline at end of file + run: docker-compose -f docker-compose.yml run -T database yarn reset diff --git a/frontend/.env.dist b/frontend/.env.dist index a7d67f970..90f968bd0 100644 --- a/frontend/.env.dist +++ b/frontend/.env.dist @@ -1,3 +1,4 @@ ALLOW_REGISTER=true GRAPHQL_URI=http://localhost:4000/graphql +DEFAULT_PUBLISHER_ID=2896 //BUILD_COMMIT=0000000 \ No newline at end of file diff --git a/frontend/src/components/SidebarPlugin/SideBar.spec.js b/frontend/src/components/SidebarPlugin/SideBar.spec.js index 993fdf195..e42369e50 100644 --- a/frontend/src/components/SidebarPlugin/SideBar.spec.js +++ b/frontend/src/components/SidebarPlugin/SideBar.spec.js @@ -109,7 +109,7 @@ describe('SideBar', () => { }) }) - describe('member's area with publisher ID', () => { + describe("member's area with publisher ID", () => { beforeEach(() => { mocks.$store.state.hasElopage = true }) diff --git a/frontend/src/components/SidebarPlugin/SideBar.vue b/frontend/src/components/SidebarPlugin/SideBar.vue index 5971b7b4e..8f153cb11 100755 --- a/frontend/src/components/SidebarPlugin/SideBar.vue +++ b/frontend/src/components/SidebarPlugin/SideBar.vue @@ -68,6 +68,7 @@