diff --git a/src/ringdht/ringaccount.cpp b/src/ringdht/ringaccount.cpp index 4c1815745c1bbeec09e1e96db45683ff176566e9..1c20fb65b4a058119d27c0c58ba5b3d3a1910587 100644 --- a/src/ringdht/ringaccount.cpp +++ b/src/ringdht/ringaccount.cpp @@ -1341,21 +1341,11 @@ RingAccount::loadAccount(const std::string& archive_password, const std::string& if (registrationState_ == RegistrationState::INITIALIZING) return; - // load identity immediately so we can access the ringIds of disabled accounts - auto id = loadIdentity(tlsCertificateFile_, tlsPrivateKeyFile_, tlsPassword_); - - if (not isEnabled()) { - if (id.first) { - ringAccountId_ = id.first->getPublicKey().getId().toString(); - username_ = RING_URI_PREFIX + ringAccountId_; - } - return; - } - RING_DBG("[Account %s] loading Ring account", getAccountID().c_str()); try { + auto id = loadIdentity(tlsCertificateFile_, tlsPrivateKeyFile_, tlsPassword_); bool hasArchive = not archivePath_.empty() - and fileutils::isFile(fileutils::getFullPath(idPath_, archivePath_)); + and fileutils::isFile(fileutils::getFullPath(idPath_, archivePath_)); if (useIdentity(id)) { // normal loading path loadKnownDevices(); @@ -1363,37 +1353,49 @@ RingAccount::loadAccount(const std::string& archive_password, const std::string& loadTrustRequests(); if (not hasArchive) RING_WARN("[Account %s] account archive not found, won't be able to add new devices", getAccountID().c_str()); - } else if (hasArchive) { - if (needsMigration(id)) { - RING_WARN("[Account %s] account certificate needs update", getAccountID().c_str()); - migrateAccount(archive_password, id); - } else { - RING_WARN("[Account %s] archive present but no valid receipt: creating new device", getAccountID().c_str()); - try { - initRingDevice(readArchive(archive_password)); - } catch (...) { - Migration::setState(accountID_, Migration::State::INVALID); - return; - } - Migration::setState(accountID_, Migration::State::SUCCESS); + if (not isEnabled()) { setRegistrationState(RegistrationState::UNREGISTERED); } - Manager::instance().saveConfig(); - loadAccount(archive_password); - } else { - // no receipt or archive, creating new account - if (not archive_path.empty()) { - // import account from file - loadAccountFromFile(archive_path, archive_password); - } else if (not archive_pin.empty()) { - // import account from DHT - loadAccountFromDHT(archive_password, archive_pin); - } else { - // create new account - createAccount(archive_password, std::move(id)); + } + else if (isEnabled()) { + if (hasArchive) { + if (needsMigration(id)) { + RING_WARN("[Account %s] account certificate needs update", getAccountID().c_str()); + migrateAccount(archive_password, id); + } + else { + RING_WARN("[Account %s] archive present but no valid receipt: creating new device", getAccountID().c_str()); + try { + initRingDevice(readArchive(archive_password)); + } + catch (...) { + Migration::setState(accountID_, Migration::State::INVALID); + return; + } + Migration::setState(accountID_, Migration::State::SUCCESS); + setRegistrationState(RegistrationState::UNREGISTERED); + } + Manager::instance().saveConfig(); + loadAccount(archive_password); + } + else { + // no receipt or archive, creating new account + if (not archive_path.empty()) { + // import account from file + loadAccountFromFile(archive_path, archive_password); + } + else if (not archive_pin.empty()) { + // import account from DHT + loadAccountFromDHT(archive_password, archive_pin); + } + else { + // create new account + createAccount(archive_password, std::move(id)); + } } } - } catch (const std::exception& e) { + } + catch (const std::exception& e) { RING_WARN("[Account %s] error loading account: %s", getAccountID().c_str(), e.what()); identity_ = dht::crypto::Identity{}; setRegistrationState(RegistrationState::ERROR_GENERIC); @@ -3282,3 +3284,4 @@ RingAccount::registerDhtAddress(IceTransport& ice) } } // namespace ring +