示例#1
0
  public boolean DDAdd(int memberid, String te_username) {
    boolean result = false;
    String status = "";
    JSONObject response, post;

    String api = API1 + te_username + API2;
    // String api = "http://192.168.2.132:5000";

    String url = api + CREATEDDACCT;

    post = new JSONObject();
    try {
      post.put("userid", memberid);
      post.put("session", this.session_token);
    } catch (JSONException e) {
      e.printStackTrace();
      return result;
    }

    response = this.postJSON(url, post);

    if (response == null) {
      errormsg = "Server not responding.";
      errorcode = JSONError.NORESPONSE.getKey();
      return result;
    }

    try {
      status = response.getString("result");
    } catch (JSONException e) {
      status = "failure";
      errormsg = "Server not responding";
      errorcode = JSONError.NORESPONSE.getKey();
    }

    if (status.compareTo("failure") == 0) {
      try {
        errormsg = response.getString("message");
        if (errormsg.contains("There is already a customer")) result = true;
      } catch (JSONException e) {
        errormsg = "No Response";
      }
      errorcode = JSONError.INVALIDINPUT.getKey();
    } else {
      try {
        this.session_token = response.getString("session");
        result = true;
      } catch (JSONException e) {
        errormsg = "Missing Session";
        errorcode = JSONError.INTERNALCON.getKey();
      }
    }
    if (result) {
      result = DDdetails(memberid, te_username);
    }

    return result;
  }
示例#2
0
  public boolean resetPassword(String email) {
    errorcode = -1;
    errormsg = null;
    String status = "";

    JSONObject response;
    String url = HOST + "/resetpassword?email=" + email;
    response = getJSON(url);

    if (response == null) {
      errormsg = "Server not responding.";
      errorcode = JSONError.NORESPONSE.getKey();
      return false;
    }
    try {
      status = response.getString("status");
    } catch (JSONException e) {
      status = "error";
      errormsg = "Server not responding";
      errorcode = JSONError.NORESPONSE.getKey();
    }

    if (status.compareTo("error") == 0) {
      if (errormsg == null) {
        try {
          errormsg = response.getString("error");
          errorcode = response.getInt("errorcode");
        } catch (JSONException e) {
          errormsg = "Server not responding";
          errorcode = JSONError.NORESPONSE.getKey();
        }
      }
    } else {
      String password = null;

      try {
        password = response.getString("result");
      } catch (JSONException e) {
        errormsg =
            "please refer to the email that was sent, in order to retrieve your new password.";
        errorcode = JSONError.BADRETRIEVE.getKey();
      }

      if (password != null && errorcode < 0) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(ctx);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString("password", password);

        editor.commit();
      }
      return (errorcode < 0);
    }

    return (errorcode < 0);
  }
示例#3
0
  public boolean DDcheckStatus(int memberid, String te_username, String session) {
    boolean result = false;
    String status = "";
    JSONObject response, post;

    String api = API1 + te_username + API2;
    // String api = "http://192.168.2.132:5000";
    String url = api + CHECKDDSTATUS;

    post = new JSONObject();
    try {
      post.put("userid", memberid);
      session = (session == null) ? this.session_token : session;
      post.put("session", session);
    } catch (JSONException e) {
      e.printStackTrace();
      return result;
    }

    response = this.postJSON(url, post);

    if (response == null) {
      errormsg = "Server not responding.";
      errorcode = JSONError.NORESPONSE.getKey();
      return result;
    }

    try {
      status = response.getString("ddstatus");
    } catch (JSONException e) {
      status = "bad";
      errormsg = "Server not responding";
      errorcode = JSONError.NORESPONSE.getKey();
    }

    if (status.compareTo("bad") == 0) {
      try {
        errormsg = response.getString("message");
      } catch (JSONException e) {
        errormsg = "No Response";
      }
      errorcode = JSONError.INVALIDINPUT.getKey();
    } else {
      try {
        result = true;
        this.session_token = response.getString("session");
      } catch (JSONException e) {
        /*probably doesn't matter.*/
      }
    }

    return result;
  }
示例#4
0
  public boolean DDLogin(String te_username, String te_password) {
    boolean result = false;
    String status = "";
    this.signup_url = "api.gymmaster.co.nz/notavailable";
    JSONObject response, post;
    String api = API1 + te_username + API2;
    // String api = "http://192.168.2.132:5000";

    String url = api + GYMLOGIN;
    post = new JSONObject();
    try {
      post.put("username", te_username);
      post.put("password", te_password);
    } catch (JSONException e) {
      e.printStackTrace();
      return result;
    }

    response = postJSON(url, post);

    if (response == null) {
      errormsg = "Server not responding.";
      errorcode = JSONError.NORESPONSE.getKey();
      return result;
    }

    try {
      status = response.getString("validlogin");
    } catch (JSONException e) {
      status = "false";
      errormsg = "Server not responding";
      errorcode = JSONError.NORESPONSE.getKey();
    }

    if (status.compareTo("false") == 0) {
      errormsg =
          "Bad Login credentials."; // TODO: we'll need to resync the te_username & te_password
      errorcode = JSONError.BADRETRIEVE.getKey();
    } else {
      try {
        this.session_token = response.getString("session");
        result = true;
      } catch (JSONException e) {
        errormsg = "Could not retrieve Session, please try again later.";
        errorcode = JSONError.BADRETRIEVE.getKey();
      }
    }

    return result;
  }
示例#5
0
  public boolean setPassword(String username, String password) {
    errorcode = -1;
    errormsg = null;
    String status = "";

    JSONObject response;
    String url = HOST + "/setpassword?suername=" + username;
    response = getJSON(url);

    if (response == null) {
      errormsg = "Server not responding.";
      errorcode = JSONError.NORESPONSE.getKey();
      return false;
    }

    return false;
  }
示例#6
0
  private boolean DDdetails(int memberid, String te_username) {
    boolean result = false;
    JSONObject response, post;
    String api = API1 + te_username + API2;
    // String api = "http://192.168.2.132:5000";
    String url = api + EDITDDACCOUNT;

    post = new JSONObject();
    try {
      post.put("userid", memberid);
      post.put("session", this.session_token);
    } catch (JSONException e) {
      e.printStackTrace();
      return result;
    }

    response = this.postJSON(url, post);

    if (response == null) {
      errormsg = "Server not responding.";
      errorcode = JSONError.NORESPONSE.getKey();
      return result;
    }

    try {
      this.signup_url = response.getString("editurl");
      this.session_token = response.getString("session");
      result = true;
    } catch (JSONException e) {
      e.printStackTrace();
      errormsg = "Could not get response";
      errorcode = JSONError.BADRETRIEVE.getKey();
    }

    return result;
  }
示例#7
0
  public boolean AddUser(String email, String organisation) {
    String url = HOST + "/signup?email=" + email + "&organisation=" + organisation;
    JSONObject result;
    String status;
    errorcode = -1;
    errormsg = null;
    // 2a780e78620070e1c37f321065bb6a845fd1371cd5ed3d457cf2c83bb4b9a0c0 	//ZLuImr
    // 16b1392fa1c881843097531a35388b68e30058b76e17c5920798da3ce8da348f 	//ZfqmRe
    // 7C6D5B646F8F6D5D8E89076210880CEF 									//VsM2GO
    // String encrypt_string = "c3ab8ab87d7907aae91f6bcc9dbc4321";
    /*byte[] encrypt, decrypt;
    encrypt = Services.hexStringToByteArray(encrypt_string);
    Log.e(TAG, Arrays.toString(encrypt));
    iv = Arrays.copyOfRange(encrypt, 0, 16);
    Log.e(TAG, "IV:"+Services.bytesToHex(iv));
    byte [] encrypt_password = Arrays.copyOfRange(encrypt, 16, encrypt.length);
    decrypt = decrypt(encrypt_password, iv);
    try {
    Log.e(TAG, "DECRYPT_PASSWORD: "******"UTF-8")+"\n UNCRYPT_PASSWORD: '******'");
    } catch (Exception e) {e.printStackTrace();};

    if (encrypt != null) {
    	return false;
    }

    byte[] encrypt, decrypt;
    encrypt = this.encrypt("VsM2GO");
    Log.w(TAG, "ENCRYPT:"+Services.bytesToHex(encrypt));
    decrypt = this.decrypt(encrypt);
    try {
    Log.w(TAG, new String(decrypt, "UTF-8")); } catch (Exception e) {};

    encrypt = Services.hexStringToByteArray(encrypt_string);
    Log.e(TAG, Arrays.toString(encrypt));
    decrypt = decrypt(encrypt);
    try {
    Log.e(TAG, "DECRYPT_PASSWORD: "******"UTF-8")+"\n UNCRYPT_PASSWORD: '******'");
    } catch (Exception e) {};

    if (encrypt != null) {
    	return false;
    }*/

    result = getJSON(url);
    if (result == null) {
      errormsg = "Server not responding.";
      errorcode = JSONError.NORESPONSE.getKey();
      return false;
    }
    try {
      status = result.getString("status");
    } catch (JSONException e) {
      status = "error";
      errormsg = "Server not responding.";
      errorcode = JSONError.NORESPONSE.getKey();
    }

    if (status.compareTo("error") == 0) {
      if (errormsg == null) {
        try {
          errormsg = result.getString("error");
          errorcode = result.getInt("errorcode");
        } catch (JSONException e) {
          errormsg = "Server not responding";
          errorcode = JSONError.NORESPONSE.getKey();
        }
      }
    }

    // errorcodes 8 = email exists but isn't setup, < 0 is success.
    return (errorcode <= 0 || errorcode == JSONError.USERNOTSETUP.getKey());
  }
示例#8
0
  public boolean updateUser(
      String email,
      String username,
      String countrycode,
      boolean contactable,
      String contact_name,
      String contact_number) {
    byte[] encrypt, decrypt;
    /*encrypt = encrypt(" ");
    try {
    Log.e(TAG, "TEST STRING ENCRYPTED: "+new String(encrypt, "UTF-8"));
    } catch (Exception e) {e.printStackTrace();};*/

    // if can contact we add the contact details, other wise ignore.
    username = username.replace(" ", "%20");
    String url =
        HOST
            + "/updateuser?email="
            + email
            + "&username="******"&country="
            + countrycode
            + "&contactable="
            + String.valueOf(contactable);

    if (contactable) {
      if (contact_name != null) {
        url = url + "&contactname=" + contact_name;
      }
      if (contact_number != null) {
        url = url + "&contactnumber=" + contact_number;
      }
    }
    JSONObject result;
    String status;
    errorcode = -1;
    errormsg = null;

    result = getJSON(url);
    try {
      status = result.getString("status");
    } catch (JSONException e) {
      status = "error";
      errormsg = "Server not responding";
      errorcode = JSONError.NORESPONSE.getKey();
    }

    if (status.compareTo("error") == 0) {
      if (errormsg == null) {
        try {
          errormsg = result.getString("error");
          errorcode = result.getInt("errorcode");
        } catch (JSONException e) {
          errormsg = "Server not responding";
          errorcode = JSONError.NORESPONSE.getKey();
        }
      }
    } else {
      String server = "-1", dbname = "-1", user = "******", password = "******";
      try {
        server = result.getString("server");
        dbname = result.getString("db_name");
        user = result.getString("username");
        password = result.getString("uncrypt_password");
        // String encrypt_string = result.getString("encrypt_password");
        // encrypt = Services.hexStringToByteArray(encrypt_string);
        // iv = Arrays.copyOfRange(encrypt, 0, 16);
        // Log.e(TAG, "IV:"+Services.bytesToHex(iv));
        // byte [] encrypt_password = Arrays.copyOfRange(encrypt, 16, encrypt.length);

        /*Log.e(TAG, "ENCRYPT_PASSWORD:"******"DECRYPT_PASSWORD: "******"UTF-8")+"\n UNCRYPT_PASSWORD: "******"please refer to the details in the email that was sent to you, in order to finish the setup.";
        errorcode = JSONError.BADRETRIEVE.getKey();
      }
      SharedPreferences preferences =
          PreferenceManager.getDefaultSharedPreferences(ctx.getApplicationContext());
      SharedPreferences.Editor editor = preferences.edit();
      editor.putString("address", server);
      editor.putString("port", "5432");
      editor.putString("username", user);
      editor.putString("database", dbname);
      editor.putString("password", password);

      editor.commit();
    }

    return (errorcode <= 0);
  }