Ejemplo n.º 1
0
  public void onSubmitLoginClick(View view) {
    try {
      EditText emailText = (EditText) this.findViewById(R.id.editTextLoginEmail);
      EditText passwordText = (EditText) this.findViewById(R.id.editTextLoginPassword);
      EditText confirmText = (EditText) this.findViewById(R.id.editTextConfirm);

      String email = emailText.getText().toString();
      String password = passwordText.getText().toString();
      String confirm = confirmText.getText().toString();
      if (m_IsCreateUser) {
        if (!email.equals("")
            && !password.equals("")
            && !confirm.equals("")
            && password.equals(confirm)) {
          m_UserData = new UserData(email, password, -1, null);
          CreateUserTask createUserTask = new CreateUserTask();
          createUserTask.execute(m_UserData);
        } else setStatus("Invalid Entries");
      } else {
        if (!email.equals("") && !password.equals("")) {
          m_UserData = new UserData(email, password, -1, null);
          LoginTask loginTask = new LoginTask();
          loginTask.execute(m_UserData);
        } else {
          setStatus("Enter a username and password.");
        }
      }
    } catch (Exception ex) {
      setStatus("Login Failed.");
    }
  }
Ejemplo n.º 2
0
  /**
   * 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 attemptCreate() {
    // Store values at the time of the login attempt.
    String name = edit_nome.getText().toString();
    String email = edit_email.getText().toString();
    String password = edit_password.getText().toString();

    boolean cancel = false;
    View focusView = null;

    ValidateUserInfo validate = new ValidateUserInfo();

    // Check for a valid email address.
    if (TextUtils.isEmpty(name)) {
      edit_nome.setError(getString(R.string.error_field_required));
      focusView = edit_nome;
      cancel = true;
    } else if (TextUtils.isEmpty(email)) {
      edit_email.setError(getString(R.string.error_field_required));
      focusView = edit_email;
      cancel = true;
    } else if (!validate.isEmailValid(email)) {
      edit_email.setError(getString(R.string.error_invalid_email));
      focusView = edit_email;
      cancel = true;
    } else if (TextUtils.isEmpty(password)) {
      edit_password.setError(getString(R.string.error_field_required));
      focusView = edit_password;
      cancel = true;
    } else if (!validate.isPasswordValid(password)) {
      edit_password.setError(getString(R.string.error_invalid_password));
      focusView = edit_password;
      cancel = true;
    }

    if (cancel) {
      // There was an error; don't attempt login and focus the first
      // form field with an error.
      focusView.requestFocus();
    } else {
      // TODO Create account logic
      // Show a progress spinner, and kick off a background task to
      // perform the user registration attempt.
      mCreateTask = new CreateUserTask(name, email, password);
      mCreateTask.execute((Void) null);
    }
  }