From 321b3eeb6d7fcb5568f6a469127ff830ab77556d 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: Mon, 13 Mar 2023 17:58:47 +0800 Subject: Interface for setting new account next page --- interchange/member.hxx | 3 ++- member.cxx | 51 ++++++++++++++++++++++++++++---------------------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/interchange/member.hxx b/interchange/member.hxx index 560cea4..5137071 100644 --- a/interchange/member.hxx +++ b/interchange/member.hxx @@ -81,7 +81,8 @@ namespace QInterchange { void newAccount(QString const& username, QString const& password, QString const& confirm, - QString const& failPage = nullptr); + QString const& nextPage = "", + QString const& failPage = ""); void logIn(QString const& userName, QString const& passWord, QString const& nextPage = "", diff --git a/member.cxx b/member.cxx index a346d74..420f76c 100644 --- a/member.cxx +++ b/member.cxx @@ -98,29 +98,36 @@ namespace QInterchange { void Member::newAccount(QString const& username, QString const& password, QString const& verify, - QString const& failPage) + QString const& nextPage, QString const& failPage) { - auto unData = username.toLatin1().constData(); - unCopy = (char*)malloc(strlen(unData) + 1); - strcpy(unCopy, unData); - auto pwData = password.toLatin1().constData(); - pwCopy = (char*)malloc(strlen(pwData) + 1); - strcpy(pwCopy, pwData); - auto vData = verify.toLatin1().constData(); - vCopy = (char*)malloc(strlen(vData) + 1); - strcpy(vCopy, vData); - auto fpData = failPage.toLatin1().constData(); - fpCopy = (char*)malloc(strlen(fpData) + 1); - strcpy(fpCopy, fpData); - interchange_member_newaccount(unCopy, pwCopy, vCopy, fpCopy, - [](interchange_response* response) { - free(unCopy); - free(pwCopy); - free(vCopy); - free(fpCopy); - member->emitCreation(QString{response->data}); - interchange_free_response(response); - }, nullptr); + unCopy = (char*)malloc(username.size() + 1); + strcpy(unCopy, username.toLatin1().constData()); + pwCopy = (char*)malloc(password.size() + 1); + strcpy(pwCopy, password.toLatin1().constData()); + vCopy = (char*)malloc(verify.size() + 1); + strcpy(vCopy, verify.toLatin1().constData()); + if (nextPage.isEmpty()) + npCopy = nullptr; + else { + npCopy = (char*)malloc(nextPage.size() + 1); + strcpy(npCopy, nextPage.toLatin1().constData()); + } + if (failPage.isEmpty()) + fpCopy = nullptr; + else { + fpCopy = (char*)malloc(failPage.size() + 1); + strcpy(fpCopy, failPage.toLatin1().constData()); + } + interchange_member_newaccount(unCopy, pwCopy, vCopy, npCopy, + fpCopy, [](interchange_response* response) { + free(unCopy); + free(pwCopy); + free(vCopy); + if (npCopy) free(npCopy); + if (fpCopy) free(fpCopy); + member->emitCreation(QString{response->data}); + interchange_free_response(response); + }, nullptr); } void Member::logIn(QString const& username, QString const& password, -- cgit v1.2.3