/**
   * Logs the currently logged in user out by deleting it from SharedPreferences, making the logout
   * API call to delete the auth token, and * resetting mUser.
   */
  public void logout(Activity activity) {
    // Check if the user is null because we're paranoid.
    if (mUser != null && activity != null) {
      // Perform the API call to delete the user's authToken.
      APIService.call(activity, APIService.getLogoutAPICall(mUser));
    }

    shallowLogout();

    getBus().post(new LoginEvent.Logout());
  }
  /** Call when the user has cancelled login. */
  public void cancelLogin() {
    // Clear the pending api call if one exists.
    APIService.getAndRemovePendingApiCall(this);
    setIsLoggingIn(false);

    getBus().post(new LoginEvent.Cancel());
  }
  /** Logs the given user in by writing it to SharedPreferences and setting mUser. */
  public void login(User user) {
    final SharedPreferences prefs = getSharedPreferences(PREFERENCE_FILE, Context.MODE_PRIVATE);
    Editor editor = prefs.edit();
    editor.putString(mSite.mName + AUTH_TOKEN_KEY, user.getAuthToken());
    editor.putString(mSite.mName + USERNAME_KEY, user.getUsername());
    editor.putInt(mSite.mName + USERID_KEY, user.getUserid());
    editor.commit();
    mUser = user;

    getBus().post(new LoginEvent.Login(mUser));

    setIsLoggingIn(false);

    /** Execute pending API call if one exists. */
    Intent pendingApiCall = APIService.getAndRemovePendingApiCall(this);
    if (pendingApiCall != null) {
      startService(pendingApiCall);
    }
  }