/**
   * Attempts to sign in or register the account specified by the login form. If there are form
   * errors (invalid email, missing fields, etc.), the errors are presented and no actual login
   * attempt is made.
   */
  public void attemptLogin() {
    // Reset errors.
    userView.setError(null);
    passwordView.setError(null);
    // Store values at the time of the login attempt.
    Settings.server = serverView.getText().toString();
    Settings.macmContext = macmContextView.getText().toString();
    Settings.macmTenant = macmTenantView.getText().toString();
    Settings.macmLib = macmLibView.getText().toString();
    Settings.user = userView.getText().toString();
    Settings.password = passwordView.getText().toString();

    // Show a progress spinner, and kick off a background task to perform the user login attempt.
    CAASService service =
        new CAASService(
            Settings.server,
            Settings.macmContext,
            Settings.macmTenant,
            Settings.user,
            Settings.password);
    service.setAndroidContext(getApplicationContext());
    service.setAllowUntrustedCertificates(true);
    GenericCache.getInstance().put(Constants.SERVER, service);
    CAASDataCallback<Void> callback =
        new CAASDataCallback<Void>() {
          @Override
          public void onSuccess(CAASRequestResult<Void> requestResult) {
            LoginActivity.this.runOnUiThread(
                new Runnable() {
                  @Override
                  public void run() {
                    showProgress(false);
                  }
                });
            startActivity(new Intent(getApplicationContext(), ContentTypesActivity.class));
          }

          @Override
          public void onError(final CAASErrorResult error) {
            LoginActivity.this.runOnUiThread(
                new Runnable() {
                  @Override
                  public void run() {
                    showProgress(false);
                    String msg = error.getMessage();
                    int code = error.getStatusCode();
                    userView.setError(
                        "connection error"
                            + (msg != null ? ": " + msg : (code > 0 ? ": status code " + code : ""))
                            + " - please try again");
                  }
                });
          }
        };
    showProgress(true);
    service.signIn(Settings.user, Settings.password, callback);
  }