check always for hasElopage

- put check into async task to let it run at the same time as the password check
This commit is contained in:
einhornimmond 2021-10-10 15:25:01 +02:00
parent 17907b23ad
commit 546d371139
6 changed files with 34 additions and 16 deletions

View File

@ -7,7 +7,4 @@ export default class UnsecureLoginArgs {
@Field(() => String)
password: string
@Field(() => Boolean)
hasElopage?: boolean
}

View File

@ -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<User> {
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

View File

@ -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<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;
@ -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<model::table::ElopageBuy>(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");

View File

@ -108,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("email", mEmail);
return 0;
}
}
}

View File

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

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__