Add forceLogin to case where authentication fails during upload

This commit is contained in:
misaochan 2018-06-07 16:48:32 +10:00
parent baab89c076
commit e7d3584b8d
3 changed files with 13 additions and 1 deletions

View file

@ -6,6 +6,7 @@ import android.accounts.AccountAuthenticatorResponse;
import android.accounts.AccountManager;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
@ -136,6 +137,11 @@ public class LoginActivity extends AccountAuthenticatorActivity {
}
}
public static void startYourself(Context context) {
Intent intent = new Intent(context, LoginActivity.class);
context.startActivity(intent);
}
private void forgotPassword() {
Utils.handleWebUrl(this, Uri.parse(BuildConfig.FORGOT_PASSWORD_URL));
}

View file

@ -81,6 +81,12 @@ public class SessionManager {
return sharedPreferences.getBoolean("isUserLoggedIn", false);
}
public void forceLogin(Context context) {
if (context != null) {
LoginActivity.startYourself(context);
}
}
public Completable clearAllAccounts() {
AccountManager accountManager = AccountManager.get(context);
Account[] allAccounts = accountManager.getAccountsByType(ACCOUNT_TYPE);

View file

@ -239,10 +239,10 @@ public class UploadService extends HandlerService<Contribution> {
Timber.d("Successfully revalidated token!");
} else {
Timber.d("Unable to revalidate :(");
// TODO: Put up a new notification, ask them to re-login
stopForeground(true);
Toast failureToast = Toast.makeText(this, R.string.authentication_failed, Toast.LENGTH_LONG);
failureToast.show();
sessionManager.forceLogin(this);
return;
}
}