/**
   * 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(User.AuthenticationType authenticationType) {
    if (mAuthTask != null) {
      return;
    }

    // Reset errors.
    mEmailView.setError(null);
    mPasswordView.setError(null);

    // Store values at the time of the login attempt.
    String email = mEmailView.getText().toString();
    String phoneNumber = mPhoneNumberView.getText().toString();
    String userId = mUserIdView.getText().toString();
    String password = mPasswordView.getText().toString();

    boolean cancel = false;
    View focusView = null;

    // Check for a valid password, if the user entered one.
    if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) {
      mPasswordView.setError(getString(R.string.error_invalid_password));
      focusView = mPasswordView;
      cancel = true;
    }

    // Check for a valid email address.
    if (TextUtils.isEmpty(email)) {
      /*mEmailView.setError(getString(R.string.error_field_required));
      focusView = mEmailView;
      cancel = true;*/
    } else if (!isEmailValid(email)) {
      mEmailView.setError(getString(R.string.error_invalid_email));
      focusView = mEmailView;
      cancel = true;
    }

    if (cancel) {
      // There was an error; don't attempt login and focus the first
      // form field with an error.
      focusView.requestFocus();
    } else {
      // Show a progress spinner, and kick off a background task to
      // perform the user login attempt.
      showProgress(true);

      // callback for login process
      UserLoginTask.TaskListener listener =
          new UserLoginTask.TaskListener() {

            @Override
            public void onSuccess(RegistrationResponse registrationResponse, Context context) {
              mAuthTask = null;
              showProgress(false);

              // Start GCM registration....
              GCMRegistrationUtils gcmRegistrationUtils =
                  new GCMRegistrationUtils(LoginActivity.this);
              gcmRegistrationUtils.setUpGcmNotification();

              // starting main MainActivity
              Intent intent = new Intent(context, MainActivity.class);
              startActivity(intent);
              finish();
            }

            @Override
            public void onFailure(RegistrationResponse registrationResponse, Exception exception) {
              mAuthTask = null;
              showProgress(false);

              mEmailSignInButton.setVisibility(View.VISIBLE);
              AlertDialog alertDialog = new AlertDialog.Builder(LoginActivity.this).create();
              alertDialog.setTitle(getString(R.string.text_alert));
              alertDialog.setMessage(exception.toString());
              alertDialog.setButton(
                  AlertDialog.BUTTON_NEUTRAL,
                  getString(android.R.string.ok),
                  new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                      dialog.dismiss();
                    }
                  });
              alertDialog.show();
            }
          };

      User user = new User();
      user.setUserId(userId);
      user.setEmailId(email);
      user.setPassword(password);
      user.setContactNumber(phoneNumber);
      user.setAuthenticationTypeId(authenticationType.getValue());

      mAuthTask = new UserLoginTask(user, listener, this);
      mEmailSignInButton.setVisibility(View.INVISIBLE);
      mSpinnerView.setVisibility(View.INVISIBLE);
      loginButton.setVisibility(View.INVISIBLE);
      mAuthTask.execute((Void) null);
    }
  }