diff --git a/Linphone/core/register/RegisterPage.cpp b/Linphone/core/register/RegisterPage.cpp index 8ce457a44..fd957ac31 100644 --- a/Linphone/core/register/RegisterPage.cpp +++ b/Linphone/core/register/RegisterPage.cpp @@ -65,8 +65,11 @@ void RegisterPage::registerNewAccount(const QString &username, }); connect(accountManager, &AccountManager::registerNewAccountFailed, this, [this, accountManager](const QString &errorMessage) mutable { - App::postCoreAsync( - [this, errorMessage, accountManager]() { emit registerNewAccountFailed(errorMessage); }); + App::postCoreAsync([this, errorMessage]() { + mLastRegisterAddress.clear(); + mLastConvertedToken.clear(); + emit registerNewAccountFailed(errorMessage); + }); if (accountManager) { accountManager->deleteLater(); accountManager = nullptr; @@ -81,8 +84,16 @@ void RegisterPage::registerNewAccount(const QString &username, } }); connect(accountManager, &AccountManager::tokenConversionSucceed, this, - [this, accountManager]() { App::postCoreAsync([this]() { emit tokenConversionSucceed(); }); }); - accountManager->registerNewAccount(username, password, registerType, address); + [this, accountManager, address](QString convertedToken) { + App::postCoreAsync([this, convertedToken, address]() { + mLastRegisterAddress = address; + mLastConvertedToken = convertedToken; + emit tokenConversionSucceed(); + }); + }); + accountManager->registerNewAccount(username, password, registerType, address, + QString::compare(mLastRegisterAddress, address) ? QString() + : mLastConvertedToken); }); } @@ -92,7 +103,11 @@ void RegisterPage::linkNewAccountUsingCode(const QString &code, App::postModelAsync([=]() { auto accountManager = new AccountManager(); connect(accountManager, &AccountManager::linkingNewAccountWithCodeSucceed, this, [this, accountManager]() { - App::postCoreAsync([this]() { emit linkingNewAccountWithCodeSucceed(); }); + App::postCoreAsync([this]() { + mLastRegisterAddress.clear(); + mLastConvertedToken.clear(); + emit linkingNewAccountWithCodeSucceed(); + }); accountManager->deleteLater(); }); connect(accountManager, &AccountManager::linkingNewAccountWithCodeFailed, this, diff --git a/Linphone/core/register/RegisterPage.hpp b/Linphone/core/register/RegisterPage.hpp index 8543fbe9b..e8f6b34c6 100644 --- a/Linphone/core/register/RegisterPage.hpp +++ b/Linphone/core/register/RegisterPage.hpp @@ -61,6 +61,10 @@ private: QSharedPointer> mAccountManagerConnection; std::shared_ptr mAccountManager; QString mErrorMessage; + // Usefull to skip token verification part if the account + // creation failed for an existing username + QString mLastRegisterAddress; + QString mLastConvertedToken; DECLARE_ABSTRACT_OBJECT }; diff --git a/Linphone/model/account/AccountManager.cpp b/Linphone/model/account/AccountManager.cpp index 004e8819f..174951355 100644 --- a/Linphone/model/account/AccountManager.cpp +++ b/Linphone/model/account/AccountManager.cpp @@ -132,7 +132,8 @@ bool AccountManager::login(QString username, void AccountManager::registerNewAccount(const QString &username, const QString &password, RegisterType type, - const QString ®isterAddress) { + const QString ®isterAddress, + QString lastToken) { mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); if (!mAccountManagerServicesModel) { auto core = CoreModel::getInstance()->getCore(); @@ -163,7 +164,7 @@ void AccountManager::registerNewAccount(const QString &username, } else if (request->getType() == linphone::AccountManagerServicesRequest::Type:: AccountCreationTokenFromAccountCreationRequestToken) { qDebug() << "[AccountManager] request token conversion succeed" << data; - emit tokenConversionSucceed(); + emit tokenConversionSucceed(Utils::coreStringToAppString(data)); timer.stop(); mAccountManagerServicesModel->createAccountUsingToken(Utils::appStringToCoreString(username), Utils::appStringToCoreString(password), data); @@ -253,7 +254,14 @@ void AccountManager::registerNewAccount(const QString &username, } } }); - mAccountManagerServicesModel->requestToken(); + if (lastToken.isEmpty()) { + mAccountManagerServicesModel->requestToken(); + } else { + emit tokenConversionSucceed(lastToken); + mAccountManagerServicesModel->createAccountUsingToken(Utils::appStringToCoreString(username), + Utils::appStringToCoreString(password), + Utils::appStringToCoreString(lastToken)); + } } void AccountManager::linkNewAccountUsingCode(const QString &code, diff --git a/Linphone/model/account/AccountManager.hpp b/Linphone/model/account/AccountManager.hpp index d59f4dc72..741318f9a 100644 --- a/Linphone/model/account/AccountManager.hpp +++ b/Linphone/model/account/AccountManager.hpp @@ -49,7 +49,8 @@ public: void registerNewAccount(const QString &username, const QString &password, RegisterType type, - const QString ®isterAddress); + const QString ®isterAddress, + QString lastToken = QString()); void linkNewAccountUsingCode(const QString &code, RegisterType registerType, const QString &sipAddress); @@ -61,7 +62,7 @@ signals: void registrationStateChanged(linphone::RegistrationState state); void newAccountCreationSucceed(QString sipAddress, RegisterType registerType, const QString ®isterAddress); void registerNewAccountFailed(const QString &error); - void tokenConversionSucceed(); + void tokenConversionSucceed(QString convertedToken); void errorInField(const QString &field, const QString &error); void linkingNewAccountWithCodeSucceed(); void linkingNewAccountWithCodeFailed(const QString &error); diff --git a/Linphone/view/Item/ErrorText.qml b/Linphone/view/Item/ErrorText.qml index 5b5841788..7f0a2267a 100644 --- a/Linphone/view/Item/ErrorText.qml +++ b/Linphone/view/Item/ErrorText.qml @@ -13,7 +13,7 @@ Text { } Timer { id: autoHideErrorMessage - interval: 2500 + interval: 5000 onTriggered: mainItem.text = "" } diff --git a/Linphone/view/Page/Login/RegisterPage.qml b/Linphone/view/Page/Login/RegisterPage.qml index 40ee4f181..cc673e7c8 100644 --- a/Linphone/view/Page/Login/RegisterPage.qml +++ b/Linphone/view/Page/Login/RegisterPage.qml @@ -20,6 +20,10 @@ LoginLayout { else if (field == "password") pwdItem.errorMessage = errorMessage else if (field == "phone") phoneNumberInput.errorMessage = errorMessage else if (field == "email") emailItem.errorMessage = errorMessage + else otherErrorText.text = errorMessage + } + function onRegisterNewAccountFailed(errorMessage) { + otherErrorText.text = errorMessage } } @@ -142,36 +146,47 @@ LoginLayout { } } } - RowLayout { - spacing: 16 * DefaultStyle.dp - ColumnLayout { - spacing: 5 * DefaultStyle.dp - FormItemLayout { - id: passwordItem - label: qsTr("Mot de passe") - mandatory: true - enableErrorText: true - contentItem: TextField { - id: pwdInput - hidden: true - Layout.preferredWidth: 346 * DefaultStyle.dp - backgroundBorderColor: passwordItem.errorMessage.length > 0 ? DefaultStyle.danger_500main : DefaultStyle.grey_200 + ColumnLayout { + spacing: 0 + Layout.preferredHeight: rowlayout.height + clip: false + RowLayout { + id: rowlayout + spacing: 16 * DefaultStyle.dp + ColumnLayout { + spacing: 5 * DefaultStyle.dp + FormItemLayout { + id: passwordItem + label: qsTr("Mot de passe") + mandatory: true + enableErrorText: true + contentItem: TextField { + id: pwdInput + hidden: true + Layout.preferredWidth: 346 * DefaultStyle.dp + backgroundBorderColor: passwordItem.errorMessage.length > 0 ? DefaultStyle.danger_500main : DefaultStyle.grey_200 + } + } + } + ColumnLayout { + spacing: 5 * DefaultStyle.dp + FormItemLayout { + label: qsTr("Confirmation mot de passe") + mandatory: true + enableErrorText: true + contentItem: TextField { + id: confirmPwdInput + hidden: true + Layout.preferredWidth: 346 * DefaultStyle.dp + backgroundBorderColor: passwordItem.errorMessage.length > 0 ? DefaultStyle.danger_500main : DefaultStyle.grey_200 + } } } } - ColumnLayout { - spacing: 5 * DefaultStyle.dp - FormItemLayout { - label: qsTr("Confirmation mot de passe") - mandatory: true - enableErrorText: true - contentItem: TextField { - id: confirmPwdInput - hidden: true - Layout.preferredWidth: 346 * DefaultStyle.dp - backgroundBorderColor: passwordItem.errorMessage.length > 0 ? DefaultStyle.danger_500main : DefaultStyle.grey_200 - } - } + ErrorText { + id: otherErrorText + Layout.fillWidth: true + Layout.topMargin: 5 * DefaultStyle.dp } } } @@ -194,80 +209,81 @@ LoginLayout { // } // } // } - RowLayout { - spacing: 10 * DefaultStyle.dp - CheckBox { - id: termsCheckBox - } + RowLayout { - spacing: 0 - Layout.fillWidth: true - Text { - text: qsTr("J'accepte les ") - font { - pixelSize: 14 * DefaultStyle.dp - weight: 400 * DefaultStyle.dp - } - MouseArea { - anchors.fill: parent - onClicked: termsCheckBox.toggle() - } + spacing: 10 * DefaultStyle.dp + CheckBox { + id: termsCheckBox } - Text { - activeFocusOnTab: true - font { - underline: true - pixelSize: 14 * DefaultStyle.dp - weight: 400 * DefaultStyle.dp - bold: activeFocus - } - text: qsTr("conditions d’utilisation") - Keys.onPressed: (event)=> { - if (event.key == Qt.Key_Space || event.key == Qt.Key_Enter || event.key == Qt.Key_Return) { - cguMouseArea.clicked(undefined) - event.accepted = true; + RowLayout { + spacing: 0 + Layout.fillWidth: true + Text { + text: qsTr("J'accepte les ") + font { + pixelSize: 14 * DefaultStyle.dp + weight: 400 * DefaultStyle.dp + } + MouseArea { + anchors.fill: parent + onClicked: termsCheckBox.toggle() } } - MouseArea { - id: cguMouseArea - anchors.fill: parent - hoverEnabled: true - cursorShape: containsMouse ? Qt.PointingHandCursor : Qt.ArrowCursor - onClicked: Qt.openUrlExternally(ConstantsCpp.CguUrl) - } - } - Text { - text: qsTr(" et la ") - font { - pixelSize: 14 * DefaultStyle.dp - weight: 400 * DefaultStyle.dp - } - } - Text { - activeFocusOnTab: true - font { - underline: true - pixelSize: 14 * DefaultStyle.dp - weight: 400 * DefaultStyle.dp - bold: activeFocus - } - text: qsTr("politique de confidentialité.") - Keys.onPressed: (event)=> { - if (event.key == Qt.Key_Space || event.key == Qt.Key_Enter || event.key == Qt.Key_Return) { - privateMouseArea.clicked(undefined) - event.accepted = true; + Text { + activeFocusOnTab: true + font { + underline: true + pixelSize: 14 * DefaultStyle.dp + weight: 400 * DefaultStyle.dp + bold: activeFocus + } + text: qsTr("conditions d’utilisation") + Keys.onPressed: (event)=> { + if (event.key == Qt.Key_Space || event.key == Qt.Key_Enter || event.key == Qt.Key_Return) { + cguMouseArea.clicked(undefined) + event.accepted = true; + } + } + MouseArea { + id: cguMouseArea + anchors.fill: parent + hoverEnabled: true + cursorShape: containsMouse ? Qt.PointingHandCursor : Qt.ArrowCursor + onClicked: Qt.openUrlExternally(ConstantsCpp.CguUrl) } } - MouseArea { - id: privateMouseArea - anchors.fill: parent - hoverEnabled: true - cursorShape: containsMouse ? Qt.PointingHandCursor : Qt.ArrowCursor - onClicked: Qt.openUrlExternally(ConstantsCpp.PrivatePolicyUrl) + Text { + text: qsTr(" et la ") + font { + pixelSize: 14 * DefaultStyle.dp + weight: 400 * DefaultStyle.dp + } + } + Text { + activeFocusOnTab: true + font { + underline: true + pixelSize: 14 * DefaultStyle.dp + weight: 400 * DefaultStyle.dp + bold: activeFocus + } + text: qsTr("politique de confidentialité.") + Keys.onPressed: (event)=> { + if (event.key == Qt.Key_Space || event.key == Qt.Key_Enter || event.key == Qt.Key_Return) { + privateMouseArea.clicked(undefined) + event.accepted = true; + } + } + MouseArea { + id: privateMouseArea + anchors.fill: parent + hoverEnabled: true + cursorShape: containsMouse ? Qt.PointingHandCursor : Qt.ArrowCursor + onClicked: Qt.openUrlExternally(ConstantsCpp.PrivatePolicyUrl) + } } } } - } // } Button { enabled: termsCheckBox.checked