diff options
author | Camila San <hello@camila.codes> | 2019-07-24 14:56:21 +0300 |
---|---|---|
committer | Camila San <hello@camila.codes> | 2019-10-17 21:11:31 +0300 |
commit | 19491ff85f3cd02952478d2ee1fb42caf252e9dd (patch) | |
tree | fd9bc6d7ca455e05a8cd8c5fafae4fc0eca2f792 /src/gui/accountstate.cpp | |
parent | 08c7be5350c949b15776ab52a2b7bf637f3e02a4 (diff) |
Once client gets 401/403 from the server, check if remote wipe was requested.
- When the the users logs because of 401 or 403 errors, it checks if the
server requested the remote wipe. If yes, locally deletes account and folders
connected to the account and notify the server. If no, proceeds to ask the
user to login again.
- The app password is restored in the keychain.
- WIP: The change also includes a test class for RemoteWipe.
Signed-off-by: Camila San <hello@camila.codes>
Diffstat (limited to 'src/gui/accountstate.cpp')
-rw-r--r-- | src/gui/accountstate.cpp | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/src/gui/accountstate.cpp b/src/gui/accountstate.cpp index ff2f7d000..7893a7a3b 100644 --- a/src/gui/accountstate.cpp +++ b/src/gui/accountstate.cpp @@ -14,6 +14,7 @@ #include "accountstate.h" #include "accountmanager.h" +#include "remotewipe.h" #include "account.h" #include "creds/abstractcredentials.h" #include "creds/httpcredentials.h" @@ -24,6 +25,11 @@ #include <QTimer> #include <qfontmetrics.h> +#include <QJsonDocument> +#include <QJsonObject> +#include <QNetworkRequest> +#include <QBuffer> + namespace OCC { Q_LOGGING_CATEGORY(lcAccountState, "nextcloud.gui.account.state", QtInfoMsg) @@ -36,11 +42,12 @@ AccountState::AccountState(AccountPtr account) , _waitingForNewCredentials(false) , _notificationsEtagResponseHeader("*") , _maintenanceToConnectedDelay(60000 + (qrand() % (4 * 60000))) // 1-5min delay + , _remoteWipe(new RemoteWipe(_account)) { qRegisterMetaType<AccountState *>("AccountState*"); connect(account.data(), &Account::invalidCredentials, - this, &AccountState::slotInvalidCredentials); + this, &AccountState::slotHandleRemoteWipeCheck); connect(account.data(), &Account::credentialsFetched, this, &AccountState::slotCredentialsFetched); connect(account.data(), &Account::credentialsAsked, @@ -303,7 +310,7 @@ void AccountState::slotConnectionValidatorResult(ConnectionValidator::Status sta break; case ConnectionValidator::CredentialsWrong: case ConnectionValidator::CredentialsNotReady: - slotInvalidCredentials(); + handleInvalidCredentials(); break; case ConnectionValidator::SslError: setState(SignedOut); @@ -322,7 +329,20 @@ void AccountState::slotConnectionValidatorResult(ConnectionValidator::Status sta } } -void AccountState::slotInvalidCredentials() +void AccountState::slotHandleRemoteWipeCheck() +{ + // make sure it changes account state and icons + signOutByUi(); + + qCInfo(lcAccountState) << "Invalid credentials for" << _account->url().toString() + << "checking for remote wipe request"; + + _waitingForNewCredentials = false; + setState(SignedOut); +} + + +void AccountState::handleInvalidCredentials() { if (isSignedOut() || _waitingForNewCredentials) return; @@ -343,6 +363,7 @@ void AccountState::slotInvalidCredentials() account()->credentials()->askFromUser(); } + void AccountState::slotCredentialsFetched(AbstractCredentials *) { // Make a connection attempt, no matter whether the credentials are |