From a7e82434ad76c9a254f81dd116b8efe4c7a7208e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=EA=A6=AB=EA=A6=B6=EA=A6=8F=EA=A7=80=EA=A6=A6?= =?UTF-8?q?=EA=A6=BF=EA=A6=A7=EA=A6=AE=EA=A6=91=EA=A6=A9=EA=A6=AD=EA=A7=80?= Date: Sat, 18 Mar 2023 10:09:12 +0800 Subject: Interface for setting successPage --- admin.cxx | 11 ++++++++--- interchange/admin.hxx | 5 +++-- interchange/member.hxx | 2 ++ member.cxx | 27 ++++++++++++++++++++++----- 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/admin.cxx b/admin.cxx index 4c65c7b..9a49a1f 100644 --- a/admin.cxx +++ b/admin.cxx @@ -4,10 +4,11 @@ namespace QInterchange { - static char *unCopy, *pwCopy, *npCopy, *fpCopy; + static char *unCopy, *pwCopy, *npCopy, *spCopy, *fpCopy; void Admin::logIn(QString const& username, QString const& password, - QString const& nextPage, QString const& failPage) + QString const& nextPage, QString const& successPage, + QString const& failPage) { auto unData = username.toLatin1().constData(); unCopy = (char*)malloc(strlen(unData) + 1); @@ -18,14 +19,18 @@ namespace QInterchange { auto npData = nextPage.toLatin1().constData(); npCopy = (char*)malloc(strlen(npData) + 1); strcpy(npCopy, npData); + auto spData = successPage.toLatin1().constData(); + spCopy = (char*)malloc(strlen(spData) + 1); + strcpy(spCopy, spData); auto fpData = failPage.toLatin1().constData(); fpCopy = (char*)malloc(strlen(fpData) + 1); strcpy(fpCopy, fpData); - interchange_admin_login(unCopy, pwCopy, npCopy, fpCopy, + interchange_admin_login(unCopy, pwCopy, npCopy, spCopy, fpCopy, [](interchange_response* response) { free(unCopy); free(pwCopy); free(npCopy); + free(spCopy); free(fpCopy); interchange_free_response(response); }, nullptr); diff --git a/interchange/admin.hxx b/interchange/admin.hxx index 1f00df4..4642e76 100644 --- a/interchange/admin.hxx +++ b/interchange/admin.hxx @@ -39,8 +39,9 @@ namespace QInterchange { public slots: void logIn(QString const& username, QString const& password, - QString const& nextPage = nullptr, - QString const& failPage = nullptr); + QString const& nextPage = "", + QString const& successPage = "", + QString const& failPage = ""); void newAdmin(QString const& userName, QString const& password, QString const& name, bool super, enum interchange_admin_group group); void newItem(QString const& description, QString const& comment, QString const& price, diff --git a/interchange/member.hxx b/interchange/member.hxx index 5137071..9b54493 100644 --- a/interchange/member.hxx +++ b/interchange/member.hxx @@ -82,10 +82,12 @@ namespace QInterchange { QString const& password, QString const& confirm, QString const& nextPage = "", + QString const& successPage = "", QString const& failPage = ""); void logIn(QString const& userName, QString const& passWord, QString const& nextPage = "", + QString const& successPage = "", QString const& failPage = ""); void account(); void setAccount(QString const& firstName, diff --git a/member.cxx b/member.cxx index 420f76c..c716c83 100644 --- a/member.cxx +++ b/member.cxx @@ -5,7 +5,7 @@ namespace QInterchange { static Member* member; - static char *unCopy, *pwCopy, *vCopy, *npCopy, *fpCopy; + static char *unCopy, *pwCopy, *vCopy, *npCopy, *spCopy, *fpCopy; static interchange_member* mPtr; Member::Member(interchange_member data, QObject* parent) : @@ -98,7 +98,8 @@ namespace QInterchange { void Member::newAccount(QString const& username, QString const& password, QString const& verify, - QString const& nextPage, QString const& failPage) + QString const& nextPage, QString const& successPage, + QString const& failPage) { unCopy = (char*)malloc(username.size() + 1); strcpy(unCopy, username.toLatin1().constData()); @@ -112,6 +113,12 @@ namespace QInterchange { npCopy = (char*)malloc(nextPage.size() + 1); strcpy(npCopy, nextPage.toLatin1().constData()); } + if (successPage.isEmpty()) + spCopy = nullptr; + else { + spCopy = (char*)malloc(successPage.size() + 1); + strcpy(spCopy, successPage.toLatin1().constData()); + } if (failPage.isEmpty()) fpCopy = nullptr; else { @@ -119,11 +126,13 @@ namespace QInterchange { strcpy(fpCopy, failPage.toLatin1().constData()); } interchange_member_newaccount(unCopy, pwCopy, vCopy, npCopy, - fpCopy, [](interchange_response* response) { + spCopy, fpCopy, + [](interchange_response* response) { free(unCopy); free(pwCopy); free(vCopy); if (npCopy) free(npCopy); + if (spCopy) free(spCopy); if (fpCopy) free(fpCopy); member->emitCreation(QString{response->data}); interchange_free_response(response); @@ -131,7 +140,8 @@ namespace QInterchange { } void Member::logIn(QString const& username, QString const& password, - QString const& nextPage, QString const& failPage) + QString const& nextPage, QString const& successPage, + QString const& failPage) { unCopy = (char*)malloc(username.size() + 1); strcpy(unCopy, username.toLatin1().constData()); @@ -143,17 +153,24 @@ namespace QInterchange { npCopy = (char*)malloc(nextPage.size() + 1); strcpy(npCopy, nextPage.toLatin1().constData()); } + if (successPage.isEmpty()) + spCopy = nullptr; + else { + spCopy = (char*)malloc(successPage.size() + 1); + strcpy(spCopy, successPage.toLatin1().constData()); + } if (failPage.isEmpty()) fpCopy = nullptr; else { fpCopy = (char*)malloc(failPage.size() + 1); strcpy(fpCopy, failPage.toLatin1().constData()); } - interchange_member_login(unCopy, pwCopy, npCopy, fpCopy, + interchange_member_login(unCopy, pwCopy, npCopy, spCopy, fpCopy, [](interchange_response* response) { free(unCopy); free(pwCopy); if (npCopy) free(npCopy); + if (spCopy) free(spCopy); if (fpCopy) free(fpCopy); member->emitLogin(QString{response->data}); interchange_free_response(response); -- cgit v1.2.3