register: fix token verification part if error in account creation

This commit is contained in:
Gaelle Braud 2024-09-04 17:43:17 +02:00
parent 77fad7ba86
commit 7970cd49f0
6 changed files with 147 additions and 103 deletions

View file

@ -65,8 +65,11 @@ void RegisterPage::registerNewAccount(const QString &username,
}); });
connect(accountManager, &AccountManager::registerNewAccountFailed, this, connect(accountManager, &AccountManager::registerNewAccountFailed, this,
[this, accountManager](const QString &errorMessage) mutable { [this, accountManager](const QString &errorMessage) mutable {
App::postCoreAsync( App::postCoreAsync([this, errorMessage]() {
[this, errorMessage, accountManager]() { emit registerNewAccountFailed(errorMessage); }); mLastRegisterAddress.clear();
mLastConvertedToken.clear();
emit registerNewAccountFailed(errorMessage);
});
if (accountManager) { if (accountManager) {
accountManager->deleteLater(); accountManager->deleteLater();
accountManager = nullptr; accountManager = nullptr;
@ -81,8 +84,16 @@ void RegisterPage::registerNewAccount(const QString &username,
} }
}); });
connect(accountManager, &AccountManager::tokenConversionSucceed, this, connect(accountManager, &AccountManager::tokenConversionSucceed, this,
[this, accountManager]() { App::postCoreAsync([this]() { emit tokenConversionSucceed(); }); }); [this, accountManager, address](QString convertedToken) {
accountManager->registerNewAccount(username, password, registerType, address); 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([=]() { App::postModelAsync([=]() {
auto accountManager = new AccountManager(); auto accountManager = new AccountManager();
connect(accountManager, &AccountManager::linkingNewAccountWithCodeSucceed, this, [this, accountManager]() { connect(accountManager, &AccountManager::linkingNewAccountWithCodeSucceed, this, [this, accountManager]() {
App::postCoreAsync([this]() { emit linkingNewAccountWithCodeSucceed(); }); App::postCoreAsync([this]() {
mLastRegisterAddress.clear();
mLastConvertedToken.clear();
emit linkingNewAccountWithCodeSucceed();
});
accountManager->deleteLater(); accountManager->deleteLater();
}); });
connect(accountManager, &AccountManager::linkingNewAccountWithCodeFailed, this, connect(accountManager, &AccountManager::linkingNewAccountWithCodeFailed, this,

View file

@ -61,6 +61,10 @@ private:
QSharedPointer<SafeConnection<RegisterPage, AccountManager>> mAccountManagerConnection; QSharedPointer<SafeConnection<RegisterPage, AccountManager>> mAccountManagerConnection;
std::shared_ptr<AccountManager> mAccountManager; std::shared_ptr<AccountManager> mAccountManager;
QString mErrorMessage; QString mErrorMessage;
// Usefull to skip token verification part if the account
// creation failed for an existing username
QString mLastRegisterAddress;
QString mLastConvertedToken;
DECLARE_ABSTRACT_OBJECT DECLARE_ABSTRACT_OBJECT
}; };

View file

@ -132,7 +132,8 @@ bool AccountManager::login(QString username,
void AccountManager::registerNewAccount(const QString &username, void AccountManager::registerNewAccount(const QString &username,
const QString &password, const QString &password,
RegisterType type, RegisterType type,
const QString &registerAddress) { const QString &registerAddress,
QString lastToken) {
mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); mustBeInLinphoneThread(log().arg(Q_FUNC_INFO));
if (!mAccountManagerServicesModel) { if (!mAccountManagerServicesModel) {
auto core = CoreModel::getInstance()->getCore(); auto core = CoreModel::getInstance()->getCore();
@ -163,7 +164,7 @@ void AccountManager::registerNewAccount(const QString &username,
} else if (request->getType() == linphone::AccountManagerServicesRequest::Type:: } else if (request->getType() == linphone::AccountManagerServicesRequest::Type::
AccountCreationTokenFromAccountCreationRequestToken) { AccountCreationTokenFromAccountCreationRequestToken) {
qDebug() << "[AccountManager] request token conversion succeed" << data; qDebug() << "[AccountManager] request token conversion succeed" << data;
emit tokenConversionSucceed(); emit tokenConversionSucceed(Utils::coreStringToAppString(data));
timer.stop(); timer.stop();
mAccountManagerServicesModel->createAccountUsingToken(Utils::appStringToCoreString(username), mAccountManagerServicesModel->createAccountUsingToken(Utils::appStringToCoreString(username),
Utils::appStringToCoreString(password), data); Utils::appStringToCoreString(password), data);
@ -253,7 +254,14 @@ void AccountManager::registerNewAccount(const QString &username,
} }
} }
}); });
if (lastToken.isEmpty()) {
mAccountManagerServicesModel->requestToken(); mAccountManagerServicesModel->requestToken();
} else {
emit tokenConversionSucceed(lastToken);
mAccountManagerServicesModel->createAccountUsingToken(Utils::appStringToCoreString(username),
Utils::appStringToCoreString(password),
Utils::appStringToCoreString(lastToken));
}
} }
void AccountManager::linkNewAccountUsingCode(const QString &code, void AccountManager::linkNewAccountUsingCode(const QString &code,

View file

@ -49,7 +49,8 @@ public:
void registerNewAccount(const QString &username, void registerNewAccount(const QString &username,
const QString &password, const QString &password,
RegisterType type, RegisterType type,
const QString &registerAddress); const QString &registerAddress,
QString lastToken = QString());
void linkNewAccountUsingCode(const QString &code, RegisterType registerType, const QString &sipAddress); void linkNewAccountUsingCode(const QString &code, RegisterType registerType, const QString &sipAddress);
@ -61,7 +62,7 @@ signals:
void registrationStateChanged(linphone::RegistrationState state); void registrationStateChanged(linphone::RegistrationState state);
void newAccountCreationSucceed(QString sipAddress, RegisterType registerType, const QString &registerAddress); void newAccountCreationSucceed(QString sipAddress, RegisterType registerType, const QString &registerAddress);
void registerNewAccountFailed(const QString &error); void registerNewAccountFailed(const QString &error);
void tokenConversionSucceed(); void tokenConversionSucceed(QString convertedToken);
void errorInField(const QString &field, const QString &error); void errorInField(const QString &field, const QString &error);
void linkingNewAccountWithCodeSucceed(); void linkingNewAccountWithCodeSucceed();
void linkingNewAccountWithCodeFailed(const QString &error); void linkingNewAccountWithCodeFailed(const QString &error);

View file

@ -13,7 +13,7 @@ Text {
} }
Timer { Timer {
id: autoHideErrorMessage id: autoHideErrorMessage
interval: 2500 interval: 5000
onTriggered: mainItem.text = "" onTriggered: mainItem.text = ""
} }

View file

@ -20,6 +20,10 @@ LoginLayout {
else if (field == "password") pwdItem.errorMessage = errorMessage else if (field == "password") pwdItem.errorMessage = errorMessage
else if (field == "phone") phoneNumberInput.errorMessage = errorMessage else if (field == "phone") phoneNumberInput.errorMessage = errorMessage
else if (field == "email") emailItem.errorMessage = errorMessage else if (field == "email") emailItem.errorMessage = errorMessage
else otherErrorText.text = errorMessage
}
function onRegisterNewAccountFailed(errorMessage) {
otherErrorText.text = errorMessage
} }
} }
@ -142,7 +146,12 @@ LoginLayout {
} }
} }
} }
ColumnLayout {
spacing: 0
Layout.preferredHeight: rowlayout.height
clip: false
RowLayout { RowLayout {
id: rowlayout
spacing: 16 * DefaultStyle.dp spacing: 16 * DefaultStyle.dp
ColumnLayout { ColumnLayout {
spacing: 5 * DefaultStyle.dp spacing: 5 * DefaultStyle.dp
@ -174,6 +183,12 @@ LoginLayout {
} }
} }
} }
ErrorText {
id: otherErrorText
Layout.fillWidth: true
Layout.topMargin: 5 * DefaultStyle.dp
}
}
} }
// ColumnLayout { // ColumnLayout {
// spacing: 18 * DefaultStyle.dp // spacing: 18 * DefaultStyle.dp
@ -194,6 +209,7 @@ LoginLayout {
// } // }
// } // }
// } // }
RowLayout { RowLayout {
spacing: 10 * DefaultStyle.dp spacing: 10 * DefaultStyle.dp
CheckBox { CheckBox {