Merge branch 'master' into 804-elopage-registration

This commit is contained in:
elweyn 2021-10-12 16:25:23 +02:00
commit 74ac8b7fcc
11 changed files with 118 additions and 2 deletions

View File

@ -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
}

View File

@ -242,4 +242,13 @@ export class UserResolver {
}
return new CheckEmailResponse(result.data)
}
@Query(() => Boolean)
async hasElopage(@Ctx() context: any): Promise<boolean> {
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
}
}

View File

@ -67,6 +67,7 @@ In case of success returns:
"username": ""
},
"session_id": -127182,
"hasElopage": true,
"clientIP":"123.123.123.123"
}
```
@ -86,6 +87,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
@ -593,3 +595,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"
}
```

View File

@ -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<model::table::ElopageBuy>(new model::table::ElopageBuy);
result = stateSuccess();
result->set("hasElopage", elopage_buy->isExistInDB("email", mSession->getNewUser()->getModel()->getEmail()));
return result;
}

View File

@ -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_

View File

@ -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;
}

View File

@ -8,6 +8,8 @@
#include "../lib/DataTypeConverter.h"
#include "../model/table/ElopageBuy.h"
Poco::JSON::Object* JsonUnsecureLogin::handle(Poco::Dynamic::Var params)
{
@ -105,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<model::table::UserHasElopageTask> 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;
@ -140,7 +146,9 @@ Poco::JSON::Object* JsonUnsecureLogin::handle(Poco::Dynamic::Var params)
session->setClientIp(mClientIP);
if(infos.size() > 0) {
result->set("info", infos);
}
}
AWAIT(hasElopageTask)
result->set("hasElopage", hasElopageTask->hasElopage());
return result;
default:
result->set("state", "error");

View File

@ -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)
{
@ -103,6 +108,14 @@ namespace model {
return select;
}
// --------------------------- Tasks --------------------------------------------
int UserHasElopageTask::run()
{
auto elopage_buy = Poco::AutoPtr<model::table::ElopageBuy>(new model::table::ElopageBuy);
bool hasElopage = elopage_buy->isExistInDB("payer_email", mEmail);
return 0;
}
}
}

View File

@ -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"; }
@ -51,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;
};
}
}

View File

@ -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;
}
}

View File

@ -68,5 +68,7 @@ namespace UniLib {
}
}
#define AWAIT(task) while (!hasElopageTask->isTaskFinished()) { Poco::Thread::sleep(10); }
#endif //__DR_UNIVERSUM_LIB_CONTROLLER_CPU_TASK_H__