From 2e93b769d0e032ed1a5ffbaeafc2d32412fdc5d2 Mon Sep 17 00:00:00 2001 From: Gaelle Braud Date: Fri, 17 Jan 2025 15:40:16 +0100 Subject: [PATCH] fix login --- Linphone/model/account/AccountManager.cpp | 38 +++++++++++++++-------- Linphone/model/account/AccountModel.cpp | 13 ++++++-- Linphone/model/account/AccountModel.hpp | 1 + Linphone/view/Page/Main/Call/CallPage.qml | 2 +- 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/Linphone/model/account/AccountManager.cpp b/Linphone/model/account/AccountManager.cpp index 2509e73f2..246943d56 100644 --- a/Linphone/model/account/AccountManager.cpp +++ b/Linphone/model/account/AccountManager.cpp @@ -70,18 +70,21 @@ bool AccountManager::login(QString username, auto params = account->getParams()->clone(); // Sip address. auto identity = params->getIdentityAddress()->clone(); + username = Utils::getUsername(username); + identity->setUsername(Utils::appStringToCoreString(username)); if (mAccountModel) return false; - auto accounts = core->getAccountList(); - for (auto account : accounts) { - if (account->getParams()->getIdentityAddress()->getUsername() == Utils::appStringToCoreString(username)) { + + auto otherAccounts = core->getAccountList(); + for (auto otherAccount : otherAccounts) { + auto otherParams = otherAccount->getParams(); + if (otherParams->getIdentityAddress()->getUsername() == Utils::appStringToCoreString(username) && + otherParams->getDomain() == Utils::appStringToCoreString(domain)) { *errorMessage = tr("Le compte est déjà connecté"); return false; } } - username = Utils::getUsername(username); - identity->setUsername(Utils::appStringToCoreString(username)); if (!displayName.isEmpty()) identity->setDisplayName(Utils::appStringToCoreString(displayName)); if (!domain.isEmpty()) { identity->setDomain(Utils::appStringToCoreString(domain)); @@ -110,17 +113,26 @@ bool AccountManager::login(QString username, *errorMessage = tr("Impossible de configurer les paramètres du compte."); return false; } - core->addAuthInfo(factory->createAuthInfo(Utils::appStringToCoreString(username), // Username. - "", // User ID. - Utils::appStringToCoreString(password), // Password. - "", // HA1. - "", // Realm. - identity->getDomain() // Domain. - )); + auto authInfo = factory->createAuthInfo(Utils::appStringToCoreString(username), // Username. + "", // User ID. + Utils::appStringToCoreString(password), // Password. + "", // HA1. + "", // Realm. + identity->getDomain() // Domain. + ); + core->addAuthInfo(authInfo); mAccountModel = Utils::makeQObject_ptr(account); mAccountModel->setSelf(mAccountModel); connect(mAccountModel.get(), &AccountModel::registrationStateChanged, this, - &AccountManager::onRegistrationStateChanged); + [this, authInfo](const std::shared_ptr &account, linphone::RegistrationState state, + const std::string &message) { + if (account == mAccountModel->getAccount() && state == linphone::RegistrationState::Failed) { + auto core = CoreModel::getInstance()->getCore(); + core->removeAuthInfo(authInfo); + core->removeAccount(account); + } + emit onRegistrationStateChanged(account, state, message); + }); auto status = core->addAccount(account); if (status == -1) { *errorMessage = tr("Impossible d'ajouter le compte."); diff --git a/Linphone/model/account/AccountModel.cpp b/Linphone/model/account/AccountModel.cpp index 865674459..7127c093f 100644 --- a/Linphone/model/account/AccountModel.cpp +++ b/Linphone/model/account/AccountModel.cpp @@ -107,11 +107,20 @@ void AccountModel::setDefault() { } void AccountModel::removeAccount() { - CoreModel::getInstance()->getCore()->removeAccount(mMonitor); + auto core = CoreModel::getInstance()->getCore(); + auto authInfo = mMonitor->findAuthInfo(); + if (authInfo) { + core->removeAuthInfo(authInfo); + } + core->removeAccount(mMonitor); removeUserData(mMonitor); emit removed(); } +std::shared_ptr AccountModel::getAccount() const { + return mMonitor; +} + void AccountModel::resetMissedCallsCount() { mMonitor->resetMissedCallsCount(); emit unreadNotificationsChanged(0 /*mMonitor->getUnreadChatMessageCount()*/, @@ -189,7 +198,7 @@ void AccountModel::setNotificationsAllowed(bool value) { QString AccountModel::getMwiServerAddress() const { mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); auto mwiAddress = mMonitor->getParams()->getMwiServerAddress(); - return mwiAddress ? Utils::coreStringToAppString(mwiAddress->asString()): ""; + return mwiAddress ? Utils::coreStringToAppString(mwiAddress->asString()) : ""; } void AccountModel::setMwiServerAddress(QString value) { diff --git a/Linphone/model/account/AccountModel.hpp b/Linphone/model/account/AccountModel.hpp index 11e5a467e..13b64f7a5 100644 --- a/Linphone/model/account/AccountModel.hpp +++ b/Linphone/model/account/AccountModel.hpp @@ -44,6 +44,7 @@ public: void setPictureUri(QString uri); void setDefault(); void removeAccount(); + std::shared_ptr getAccount() const; void resetMissedCallsCount(); void refreshUnreadNotifications(); int getMissedCallsCount() const; diff --git a/Linphone/view/Page/Main/Call/CallPage.qml b/Linphone/view/Page/Main/Call/CallPage.qml index 3bcc54108..30235b99f 100644 --- a/Linphone/view/Page/Main/Call/CallPage.qml +++ b/Linphone/view/Page/Main/Call/CallPage.qml @@ -680,7 +680,7 @@ AbstractMainPage { anchors.fill: parent IconLabelButton { Layout.fillWidth: true - text: detailOptions.friendGui ? qsTr("Voir le contact") : qsTr("Ajouter aux contacts") + text: contactDetail.contact ? qsTr("Voir le contact") : qsTr("Ajouter aux contacts") icon.source: AppIcons.plusCircle icon.width: 32 * DefaultStyle.dp icon.height: 32 * DefaultStyle.dp