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

@ -10,6 +10,8 @@ import androidx.lifecycle.ViewModelProviders;
import butterknife.OnFocusChange; import butterknife.OnFocusChange;
import butterknife.OnTextChanged; import butterknife.OnTextChanged;
import com.todoroo.astrid.helper.UUIDHelper; import com.todoroo.astrid.helper.UUIDHelper;
import io.reactivex.Completable;
import io.reactivex.schedulers.Schedulers;
import javax.inject.Inject; import javax.inject.Inject;
import org.tasks.R; import org.tasks.R;
import org.tasks.activities.AddEteSyncAccountViewModel; import org.tasks.activities.AddEteSyncAccountViewModel;
@ -123,4 +125,14 @@ public class EteSyncAccountSettingsActivity extends BaseCaldavAccountSettingsAct
void onEncryptionPasswordFocused(boolean hasFocus) { void onEncryptionPasswordFocused(boolean hasFocus) {
changePasswordFocus(binding.encryptionPassword, 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 Preferences preferences;
private final DebugNetworkInterceptor interceptor; private final DebugNetworkInterceptor interceptor;
private final String username; private final String username;
private final String token;
private final String encryptionPassword; private final String encryptionPassword;
private final OkHttpClient httpClient; private final OkHttpClient httpClient;
private final HttpUrl httpUrl; private final HttpUrl httpUrl;
@ -75,6 +76,7 @@ public class EteSyncClient {
this.preferences = preferences; this.preferences = preferences;
this.interceptor = interceptor; this.interceptor = interceptor;
username = null; username = null;
token = null;
encryptionPassword = null; encryptionPassword = null;
httpClient = null; httpClient = null;
httpUrl = null; httpUrl = null;
@ -98,6 +100,7 @@ public class EteSyncClient {
this.interceptor = interceptor; this.interceptor = interceptor;
this.username = username; this.username = username;
this.encryptionPassword = encryptionPassword; this.encryptionPassword = encryptionPassword;
this.token = token;
CustomCertManager customCertManager = new CustomCertManager(context); CustomCertManager customCertManager = new CustomCertManager(context);
customCertManager.setAppInForeground(foreground); customCertManager.setAppInForeground(foreground);
@ -188,7 +191,8 @@ public class EteSyncClient {
return result; 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 { throws IntegrityException, Exceptions.HttpException, VersionTooNewException {
JournalEntryManager journalEntryManager = JournalEntryManager journalEntryManager =
new JournalEntryManager(httpClient, httpUrl, journal.getUid()); new JournalEntryManager(httpClient, httpUrl, journal.getUid());
@ -196,7 +200,8 @@ public class EteSyncClient {
List<Entry> journalEntries; List<Entry> journalEntries;
do { do {
journalEntries = journalEntryManager.list(crypto, calendar.getCtag(), MAX_FETCH); 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); } while (journalEntries.size() >= MAX_FETCH);
} }
@ -213,4 +218,12 @@ public class EteSyncClient {
foreground = true; foreground = true;
return this; return this;
} }
void invalidateToken() {
try {
new JournalAuthenticator(httpClient, httpUrl).invalidateAuthToken(token);
} catch (Exception e) {
Timber.e(e);
}
}
} }

Loading…
Cancel
Save