Invalidate auth token when removing account

pull/898/head
Alex Baker 6 years ago
parent 1000a3ebb8
commit 5d60e452d4

@ -349,7 +349,7 @@ public abstract class BaseCaldavAccountSettingsActivity extends ThemedInjectingA
}
}
private void removeAccount() {
private void removeAccountPrompt() {
if (requestInProgress()) {
return;
}
@ -357,18 +357,18 @@ public abstract class BaseCaldavAccountSettingsActivity extends ThemedInjectingA
dialogBuilder
.newDialog()
.setMessage(R.string.logout_warning, caldavAccount.getName())
.setPositiveButton(
R.string.remove,
(dialog, which) -> {
taskDeleter.delete(caldavAccount);
tracker.reportEvent(Events.CALDAV_ACCOUNT_REMOVED);
setResult(RESULT_OK);
finish();
})
.setPositiveButton(R.string.remove, (dialog, which) -> removeAccount())
.setNegativeButton(android.R.string.cancel, null)
.show();
}
protected void removeAccount() {
taskDeleter.delete(caldavAccount);
tracker.reportEvent(Events.CALDAV_ACCOUNT_REMOVED);
setResult(RESULT_OK);
finish();
}
private void discard() {
if (requestInProgress()) {
return;
@ -392,7 +392,7 @@ public abstract class BaseCaldavAccountSettingsActivity extends ThemedInjectingA
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://tasks.org/caldav")));
break;
case R.id.remove:
removeAccount();
removeAccountPrompt();
break;
}
return onOptionsItemSelected(item);

@ -10,6 +10,8 @@ import androidx.lifecycle.ViewModelProviders;
import butterknife.OnFocusChange;
import butterknife.OnTextChanged;
import com.todoroo.astrid.helper.UUIDHelper;
import io.reactivex.Completable;
import io.reactivex.schedulers.Schedulers;
import javax.inject.Inject;
import org.tasks.R;
import org.tasks.activities.AddEteSyncAccountViewModel;
@ -123,4 +125,14 @@ public class EteSyncAccountSettingsActivity extends BaseCaldavAccountSettingsAct
void onEncryptionPasswordFocused(boolean hasFocus) {
changePasswordFocus(binding.encryptionPassword, hasFocus);
}
@Override
protected void removeAccount() {
if (caldavAccount != null) {
Completable.fromAction(() -> eteSyncClient.forAccount(caldavAccount).invalidateToken())
.subscribeOn(Schedulers.io())
.subscribe();
}
super.removeAccount();
}
}

@ -57,6 +57,7 @@ public class EteSyncClient {
private final Preferences preferences;
private final DebugNetworkInterceptor interceptor;
private final String username;
private final String token;
private final String encryptionPassword;
private final OkHttpClient httpClient;
private final HttpUrl httpUrl;
@ -75,6 +76,7 @@ public class EteSyncClient {
this.preferences = preferences;
this.interceptor = interceptor;
username = null;
token = null;
encryptionPassword = null;
httpClient = null;
httpUrl = null;
@ -98,6 +100,7 @@ public class EteSyncClient {
this.interceptor = interceptor;
this.username = username;
this.encryptionPassword = encryptionPassword;
this.token = token;
CustomCertManager customCertManager = new CustomCertManager(context);
customCertManager.setAppInForeground(foreground);
@ -188,7 +191,8 @@ public class EteSyncClient {
return result;
}
void getSyncEntries(Journal journal, CaldavCalendar calendar, Callback<List<Pair<Entry, SyncEntry>>> callback)
void getSyncEntries(
Journal journal, CaldavCalendar calendar, Callback<List<Pair<Entry, SyncEntry>>> callback)
throws IntegrityException, Exceptions.HttpException, VersionTooNewException {
JournalEntryManager journalEntryManager =
new JournalEntryManager(httpClient, httpUrl, journal.getUid());
@ -196,7 +200,8 @@ public class EteSyncClient {
List<Entry> journalEntries;
do {
journalEntries = journalEntryManager.list(crypto, calendar.getCtag(), MAX_FETCH);
callback.call(transform(journalEntries, e -> Pair.create(e, SyncEntry.fromJournalEntry(crypto, e))));
callback.call(
transform(journalEntries, e -> Pair.create(e, SyncEntry.fromJournalEntry(crypto, e))));
} while (journalEntries.size() >= MAX_FETCH);
}
@ -213,4 +218,12 @@ public class EteSyncClient {
foreground = true;
return this;
}
void invalidateToken() {
try {
new JournalAuthenticator(httpClient, httpUrl).invalidateAuthToken(token);
} catch (Exception e) {
Timber.e(e);
}
}
}

Loading…
Cancel
Save