コード例 #1
0
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    Logger.log("result", "onActivityResult");

    if (requestCode == ACTIVITY_ID && resultCode == RESULT_OK) {

      EditText passwordField = (EditText) findViewById(R.id.password);
      Logger.log("new password", data.getStringExtra("password"));
      passwordField.setText(data.getStringExtra("password"));
    }
  }
コード例 #2
0
  public void ignorePassword(View view) {
    password.putExtra("ignore", true);

    databaseHelper.savePassword(password);

    try {
      JSONObject jsonObject = new JSONObject();

      jsonObject.put("inResponseto", sessionID);

      JSONObject message = new JSONObject();
      message.put("action", "ignore");

      jsonObject.put("message", encrypt(message));

      Logger.log("sendPassword", jsonObject.toString());

      JsonObjectRequest request =
          new JsonObjectRequest(
              Request.Method.POST,
              getResources().getString(R.string.rest_generic),
              jsonObject.toString(),
              new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                  Log.w("response", response.toString());
                }
              },
              null);

      requestQueue.add(request);

    } catch (JSONException e) {
      e.printStackTrace();
    }

    finish();
  }
コード例 #3
0
  private void sendPassword(
      final String password, final String username, final String inResponseTo) {

    try {
      JSONObject jsonObject = new JSONObject();

      jsonObject.put("inResponseto", inResponseTo);
      jsonObject.put("closeSession", true);

      JSONObject message = new JSONObject();
      message.put("action", "sendPassword");
      message.put("password", password);
      message.put("username", username);

      jsonObject.put("message", encrypt(message));

      Logger.log("sendPassword", jsonObject.toString());

      JsonObjectRequest request =
          new JsonObjectRequest(
              Request.Method.POST,
              getResources().getString(R.string.rest_generic),
              jsonObject.toString(),
              new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                  Log.w("response", response.toString());
                }
              },
              null);

      requestQueue.add(request);

    } catch (JSONException e) {
      e.printStackTrace();
    }
  }
コード例 #4
0
  private void handleResponse(JSONObject response) throws Exception {

    if ("{}".equals(response.toString())) { // no session is open
      throw new Exception("aasdgasg");
    }

    browserId = Utils.jsonObjectGetString(response, "browser_id");
    sessionID = Utils.jsonObjectGetString(response, "id");

    Browser browser = databaseHelper.getBrowser(browserId);

    // preload public key
    preparePublicKey = new PreparePublicKey();
    preparePublicKey.execute(browser);

    JSONObject encryptedMessage = Utils.jsonObjectGetJSONObject(response, "message");

    if ("{}".equals(encryptedMessage.toString())) {
      throw new Exception("aasdgasg");
    }

    JSONObject message =
        Utils.getJSONObject(Utils.decrypt(encryptedMessage, browser.getMy_private_key()));

    Logger.log("Received", message.toString());

    location = Utils.jsonObjectGetString(message, "location");
    domain = Utils.jsonObjectGetString(message, "domain");
    title = Utils.jsonObjectGetString(message, "title");
    username = Utils.jsonObjectGetString(message, "username");
    passwordString = Utils.jsonObjectGetString(message, "password");
    elementId = Utils.jsonObjectGetString(message, "element_id");
    elementName = Utils.jsonObjectGetString(message, "element_name");

    Logger.log("search by domain", domain);

    password = databaseHelper.getPasswordByDomain(domain);

    setContentView(R.layout.activity_login);

    if (password == null) { // no password is known for the domain

      Logger.log("register", "register");

      TextView loginTitle = (TextView) findViewById(R.id.login_title);
      loginTitle.setText(domain);
      ((Button) findViewById(R.id.button_allow)).setText(R.string.allow_and_save);
      findViewById(R.id.edit).setVisibility(View.VISIBLE);

      updateUsernamePassword(username, passwordString);

      EditText passwordField = (EditText) findViewById(R.id.password);
      passwordField.setOnFocusChangeListener(
          new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
              if (!hasFocus) {
                hideKeyboard(v);
              }
            }
          });

    } else {
      Logger.log("login", "login");

      TextView loginTitle = (TextView) findViewById(R.id.login_title);
      loginTitle.setText(domain);

      updateUsernamePassword(
          password.getValue(Password.KEY_USERNAME), password.getValue(Password.KEY_PASSWORD));
    }
  }