Example #1
0
  /**
   * Helper function to fill a User object's fields from the registration form
   *
   * @param u User object to fill
   */
  private Errors fillUserObject(User u) {
    Errors errors = new Errors();

    // --- Get each EditText's field and store in regUser
    // First name
    errors.append(
        u.setFirst_name(
            ViewHelpers.getViewText(this, R.id.user_create_account_text_firstName_field)));

    // Last name
    errors.append(
        u.setLast_name(
            ViewHelpers.getViewText(this, R.id.user_create_account_text_lastName_field)));

    // Street address
    errors.append(
        u.setAddress(
            ViewHelpers.getViewText(this, R.id.user_create_account_text_streetAddress_field)));

    // City
    errors.append(
        u.setCity(ViewHelpers.getViewText(this, R.id.user_create_account_text_city_field)));

    // State
    errors.append(
        u.setState(ViewHelpers.getViewText(this, R.id.user_create_account_text_state_field)));

    // Zip Code
    errors.append(
        u.setZipcode(ViewHelpers.getViewText(this, R.id.user_create_account_text_zipCode_field)));

    // FIELD_SSN
    errors.append(
        u.setSsn(
            ViewHelpers.getViewText(
                this, R.id.user_create_account_text_socialSecurityNumber_field)));

    // Email
    errors.append(
        u.setEmail(ViewHelpers.getViewText(this, R.id.user_create_account_text_email_field)));

    // Username
    errors.append(
        u.setUsername(
            ViewHelpers.getViewText(this, R.id.user_create_account_text_createUsername_field)));

    // Password
    errors.append(
        u.setPassword(
            ViewHelpers.getViewText(this, R.id.user_create_account_text_createPassword_field)));

    return errors;
  }
Example #2
0
  /**
   * Event handler for the "create account" button
   *
   * @param view the calling view
   */
  public void user_create_account_submitUserAccount(View view) {
    Errors errorsEncountered; // errors object with any errors encountered

    // --- Create a User object with fields filled from registration form
    // Instantiate new User object to fill with registration info
    regUser = User.getUser();

    // Fill regUser's data
    errorsEncountered = fillUserObject(regUser);

    // Check for errors in filling regUser
    if (!errorsEncountered.hasErrors()) {
      // If no errors, create request to register
      Request requester =
          new RegisterRequest(
              regUser,
              new ActivityResponse() {
                public void response(Response resp) {
                  registerResponse(resp);
                  PopUp.stop();
                }
              });

      requester.execute();
      PopUp.start(this);
    } else {
      // else, there were errors
      errorsEncountered.displayErrorFeedback(this);
      boxHighlighting(errorsEncountered);
    }
  }