Closes #102: Android: Clear all auth tokens on logout

This commit is contained in:
jendib 2016-05-10 20:00:14 +02:00
parent 394f667ab0
commit 575ad75a0a
No known key found for this signature in database
GPG Key ID: 06EE7F699579166F
3 changed files with 13 additions and 1 deletions

View File

@ -3,7 +3,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0-beta1'
classpath 'com.android.tools.build:gradle:2.1.0'
}
}
apply plugin: 'com.android.application'

View File

@ -158,6 +158,7 @@ public class MainActivity extends AppCompatActivity {
@Override
public void onFinish() {
// Force logout in all cases, so the user is not stuck in case of network error
PreferenceUtil.clearAuthToken(MainActivity.this);
ApplicationContext.getInstance().setUserInfo(getApplicationContext(), null);
startActivity(new Intent(MainActivity.this, LoginActivity.class));
finish();

View File

@ -126,6 +126,7 @@ public class PreferenceUtil {
/**
* Returns auth token cookie from shared preferences.
*
* @param context Context
* @return Auth token
*/
public static String getAuthToken(Context context) {
@ -140,6 +141,16 @@ public class PreferenceUtil {
return null;
}
/**
* Clear all auth tokens.
*
* @param context Context
*/
public static void clearAuthToken(Context context) {
PersistentCookieStore cookieStore = new PersistentCookieStore(context);
cookieStore.removeAll();
}
/**
* Returns cleaned server URL.
*