/**
   * saves the edited user to elastic search.
   *
   * @param view the view that is going to be used to change the user.
   */
  @SuppressWarnings({"unused", "UnusedParameters"})
  public void editUser(View view) {
    // implements US 03.02.01
    EditText editUserName = (EditText) findViewById(R.id.editUserName);
    EditText editUserEmail = (EditText) findViewById(R.id.editUserEmail);
    EditText editUserAddress1 = (EditText) findViewById(R.id.editUserAddress1);
    EditText editUserAddress2 = (EditText) findViewById(R.id.editUserAddress2);
    EditText editUserCity = (EditText) findViewById(R.id.editUserCity);
    EditText editUserPhone = (EditText) findViewById(R.id.editUserPhone);
    EditText editUserPostalCode = (EditText) findViewById(R.id.editUserPostalCode);
    EditText editUserPassword1 = (EditText) findViewById(R.id.editUserPassword1);
    EditText editUserPassword2 = (EditText) findViewById(R.id.editUserPassword2);
    EditText editUserPassword3 = (EditText) findViewById(R.id.editUserPassword3);

    user.setName(editUserName.getText().toString());
    user.setEmail(editUserEmail.getText().toString());
    user.setAddress1(editUserAddress1.getText().toString());
    user.setAddress2(editUserAddress2.getText().toString());
    user.setCity(editUserCity.getText().toString());
    user.setPhone(editUserPhone.getText().toString());
    user.setPostal(editUserPostalCode.getText().toString());

    String pass1 = editUserPassword1.getText().toString();
    String pass2 = editUserPassword2.getText().toString();
    String pass3 = editUserPassword3.getText().toString();

    if (action != null && action.equals("NEW")) {
      user.setPasshash(Hasher.getHash(pass1));
      ElasticSearcher.sendUser(user);
      CharSequence text = "User account created!";
      int duration = Toast.LENGTH_SHORT;
      Toast toast = Toast.makeText(this, text, duration);
      toast.show();
      finish();
    } else {
      if (pass1.equals("") && pass2.equals("") && pass3.equals("")) {
        ElasticSearcher.sendUser(user);
        CharSequence text = "Saved!";
        int duration = Toast.LENGTH_SHORT;
        Toast toast = Toast.makeText(this, text, duration);
        toast.show();
        return;
      }

      if (!Hasher.getHash(pass1).equals(user.getPasshash())) {
        editUserPassword1.setError("The entered password is incorrect.");
        return;
      }

      if (!Constants.isPasswordValid(pass2)) {
        editUserPassword2.setError("The chosen password is invalid.");
        return;
      }

      if (!pass2.equals(pass3)) {
        editUserPassword3.setError("The new passwords do not match.");
        return;
      }

      user.setPasshash(Hasher.getHash(pass2));
      ElasticSearcher.sendUser(user);
      CharSequence text = "Saved!";
      int duration = Toast.LENGTH_SHORT;
      Toast toast = Toast.makeText(this, text, duration);
      toast.show();
      editUserPassword1.setText("");
      editUserPassword2.setText("");
      editUserPassword3.setText("");
    }
  }
Esempio n. 2
0
 public void testGetHash() throws Exception {
   String passhash = "AVM1KtaDI8oCfzIHasfN";
   String compare = Hasher.getHash("password");
   assertEquals("Password hashes were not equal", passhash, compare);
 }