/** 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);
    }
  }