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,
[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,

View file

@ -61,6 +61,10 @@ private:
QSharedPointer<SafeConnection<RegisterPage, AccountManager>> mAccountManagerConnection;
std::shared_ptr<AccountManager> 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
};

View file

@ -132,7 +132,8 @@ bool AccountManager::login(QString username,
void AccountManager::registerNewAccount(const QString &username,
const QString &password,
RegisterType type,
const QString &registerAddress) {
const QString &registerAddress,
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,
}
}
});
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,

View file

@ -49,7 +49,8 @@ public:
void registerNewAccount(const QString &username,
const QString &password,
RegisterType type,
const QString &registerAddress);
const QString &registerAddress,
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 &registerAddress);
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);

View file

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

View file

@ -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,7 +146,12 @@ LoginLayout {
}
}
}
ColumnLayout {
spacing: 0
Layout.preferredHeight: rowlayout.height
clip: false
RowLayout {
id: rowlayout
spacing: 16 * DefaultStyle.dp
ColumnLayout {
spacing: 5 * DefaultStyle.dp
@ -174,6 +183,12 @@ LoginLayout {
}
}
}
ErrorText {
id: otherErrorText
Layout.fillWidth: true
Layout.topMargin: 5 * DefaultStyle.dp
}
}
}
// ColumnLayout {
// spacing: 18 * DefaultStyle.dp
@ -194,6 +209,7 @@ LoginLayout {
// }
// }
// }
RowLayout {
spacing: 10 * DefaultStyle.dp
CheckBox {