示例#1
0
 protected ParseUser getParseUser(String number) {
   ParseUser parseUser = new ParseUser();
   parseUser.setUsername("parse4j-user" + number);
   parseUser.setPassword("parse4j-password");
   parseUser.setEmail("parse4j-email" + number + "@gmail.com");
   parseUser.put("dob", new Date());
   parseUser.put("city", "westbury");
   parseUser.put("state", "ny");
   return parseUser;
 }
示例#2
0
  /** Checks to see if any fields are empty and/or if two password fields are equal */
  public void checkFields(View v) {

    EditText name_field = (EditText) findViewById(R.id.nameField);
    EditText addr_field = (EditText) findViewById(R.id.addressField);
    EditText dob_field = (EditText) findViewById(R.id.dateOfBirthField);
    EditText email_field = (EditText) findViewById(R.id.emailField);
    EditText pass1 = (EditText) findViewById(R.id.passwordField);
    EditText pass2 = (EditText) findViewById(R.id.passwordConfirmField);

    String name = name_field.getText().toString().trim();
    String address = addr_field.getText().toString().trim();
    String dob = dob_field.getText().toString().trim();
    String email = email_field.getText().toString().trim();
    String password = pass1.getText().toString().trim();
    String passwordRetry = pass2.getText().toString().trim();

    if (TextUtils.isEmpty(name)) {
      name_field.setError("You must enter a username");
    }

    if (TextUtils.isEmpty(address)) {
      name_field.setError("You must enter an address");
    }

    if (TextUtils.isEmpty(dob)) {
      name_field.setError("You must enter a date of birth");
    }

    if (TextUtils.isEmpty(email)) {
      email_field.setError("You must enter an email");
    }

    if (TextUtils.isEmpty(password)) {
      pass1.setError("You must enter a password");
    }

    if (TextUtils.isEmpty(passwordRetry)) {
      pass2.setError("You must enter a password");
    }

    if (password.equals(passwordRetry)) {

      String android_id =
          Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
      Log.d("ANDROID ID", android_id);

      ParseUser user = new ParseUser();
      user.setUsername(name);
      user.setPassword(password);
      user.setEmail(email);
      user.put("address", address);
      user.put("dateOfBirth", dob);
      user.put("androidID", android_id);

      user.signUpInBackground(
          new SignUpCallback() {
            public void done(ParseException e) {
              if (e == null) {
                // success
              } else {
                // Sign up didn't succeed. Look at the ParseException
                // to figure out what went wrong
                Log.d("Error", e.toString());
              }
            }
          });

      // These two lines automatically take the user back to the home page after a successful
      // registration
      Intent goHome = new Intent(Register.this, HomePage.class);
      startActivity(goHome);

    } else {
      // Displays dialog to inform the user the passwords were unequal and they must try again
      AlertDialog.Builder builder = new AlertDialog.Builder(Register.this);
      builder.setMessage(R.string.unequalPasswords).setTitle(R.string.passwordDialogTitle);
      builder.setCancelable(true);
      builder.setPositiveButton(
          "Ok",
          new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
              dialog.cancel();
            }
          });
      AlertDialog alert = builder.create();
      alert.show();
    }
  }