public void processSignInHASHED( String username, String password) // this is for when we do the auto login cause we getting the hashed prefs { String url = "http://45.33.62.187/api/v1/player/?username_hash=" + username + "&password_hash=" + password + "&format=json"; String getPlayer = apiCall.httpGet(url, httpReturns.size()); System.out.println("trying to sign in hashed with " + username + " " + password); if (getPlayer.equalsIgnoreCase("FAILED") || getPlayer.equalsIgnoreCase("CANCELLED") || getPlayer.equalsIgnoreCase("EMPTY")) { // menuComponents.add(3, new MenuComponent(300, 400, 100, 50, Assets.menuFailedRegion)); System.out.println("login with hash " + getPlayer); Preferences prefs = Gdx.app.getPreferences("LOGIN"); prefs.putString("USERNAME_HASHED", ""); prefs.putString("PASSWORD_HASHED", ""); prefs.flush(); // saves the blank hashes to the prefs file this.signIn(); } else { System.out.println("JSON NOT MEPTY"); JSONObject json = new JSONObject(getPlayer); JSONArray playerArray = json.getJSONArray("objects"); JSONObject player0 = playerArray.getJSONObject(0); int wins = player0.getInt("wins"); int losses = player0.getInt("losses"); String usernameS = player0.getString("username"); String charityURL = player0.getString("charity"); // store players id during this playing session in proofOfConcept (best place I can think of // at the moment) int id = player0.getInt("id"); game.setPlayerID(id); String getCharity = apiCall.httpGet("http://45.33.62.187" + charityURL + "?format=json", httpReturns.size()); if (getCharity.equalsIgnoreCase("FAILED") || getCharity.equalsIgnoreCase("CANCELLED") || getCharity.equalsIgnoreCase("EMPTY")) { // menuComponents.add(new MenuComponent(300, 400, 100, 50, Assets.menuFailedRegion)); // //should be 3 unless 3 is already there, then it will be 4 } else { JSONObject jsonCharity = new JSONObject(getCharity); String charityName = jsonCharity.getString("name"); int charityIcon = jsonCharity.getInt("icon"); int charityID = jsonCharity.getInt("id"); game.setCharityID(charityID); System.out.println("Go to welcome"); this.welcome(usernameS, wins, losses, charityName, charityIcon); } } }
public void processSignUp(String username, String password, String email, String charity) { email = "fakeEmail"; String URL = "http://45.33.62.187/api/v1/player/?format=json"; String Body = "" + "{" + " \"charity\": \"/api/v1/charity/" + charity + "/\"," + " \"email\": \"" + email + "\"," + " \"username\": \"" + username + "\"," + " \"username_hash\": \"" + sha256(username) + "\"," + " \"password_hash\": \"" + sha256(password) + "\"," + " \"wins\": 0," + " \"losses\": 0" + "}"; String results = apiCall.httpPostPutOrPatch( URL, Body, httpReturns.size(), false, false); // makes the first call to insert player to table // below gets the userID from another query, then posts that to the matchmaking table String url = "http://45.33.62.187/api/v1/player/?username_hash=" + sha256(username) + "&password_hash=" + sha256(password) + "&format=json"; String getPlayer = apiCall.httpGet(url, httpReturns.size()); if (getPlayer.equalsIgnoreCase("FAILED") || getPlayer.equalsIgnoreCase("CANCELLED") || getPlayer.equalsIgnoreCase("EMPTY")) { // menuComponents.add(3, new MenuComponent(300, 400, 100, 50, Assets.menuFailedRegion)); } else { JSONObject json = new JSONObject(getPlayer); JSONArray playerArray = json.getJSONArray("objects"); JSONObject player0 = playerArray.getJSONObject(0); int id = player0.getInt("id"); // post to matchmaking URL = "http://45.33.62.187/api/v1/matchmaking/?format=json"; Body = "" + "{" + " \"player\": \"/api/v1/player/" + id + "/\"," + " \"match\": null," + " \"waiting\": false" + "}"; results = apiCall.httpPostPutOrPatch(URL, Body, httpReturns.size(), false, false); // end post to matchmaking } // end get playerID }