void LoginOnClick() { foreach (InputField e in required) { function.RequiredInputOnEndEdit(e); } if (function.InputFieldRequired(required)) { HTTPRequest request = new HTTPRequest(new Uri(data.IP + "/login?account=" + username.text + "&password="******"true") { HTTPRequest request_getUser = new HTTPRequest(new Uri(data.IP + "/getUserByAccount?account=" + username.text), HTTPMethods.Get, (req_user, res_user) => { JsonData json = JsonMapper.ToObject(res_user.DataAsText); Debug.Log((string)json["authorities"][0]["authority"]); if ((string)json["authorities"][0]["authority"] == "ROLE_ADMIN") { SceneManager.LoadScene("admin"); } else { Debug.Log(res_user.DataAsText); data.m_user.setId((long)json["id"]); data.m_user.setUsername((string)json["username"]); data.m_user.setNickname((string)json["nickname"]); data.m_user.setPassword((string)json["password"]); data.m_user.setFirstname((string)json["firstname"]); data.m_user.setLastname((string)json["lastname"]); data.m_user.setPhone((string)json["phone"]); data.m_user.setGender((bool)json["gender"]); data.m_user.setEmail((string)json["email"]); if ((bool)json["enabled"] == true) { HTTPRequest request_getGarden = new HTTPRequest(new Uri(data.IP + "/getGardenByUserId?userId=" + data.m_user.getId()), HTTPMethods.Get, (req_garden, res_garden) => { Debug.Log(res_garden.DataAsText); JArray array = JArray.Parse(res_garden.DataAsText); foreach (var e in array) { m_garden newGarden = new m_garden(); newGarden.setId((long)e["id"]); newGarden.setName((string)e["name"]); newGarden.setLength((int)e["length"]); newGarden.setWidth((int)e["width"]); newGarden.setIdealTemperature((float)e["idealTemperature"]); newGarden.setIdealHumidity((float)e["idealWetness"]); Debug.Log(newGarden.getName()); data.m_user.addGardens(newGarden); } SceneManager.LoadScene("garden"); }).Send(); } } }).Send(); } }).Send(); } }
void SubmitOnClick() { foreach (InputField e in required) { function.RequiredInputOnEndEdit(e); } foreach (Text e in warning) { if (e.IsActive()) { return; } } if (function.InputFieldRequired(required)) { HTTPRequest request = new HTTPRequest(new Uri(data.IP + "/saveGarden"), HTTPMethods.Post, (req, res) => { switch (req.State) { case HTTPRequestStates.Finished: Debug.Log(res.DataAsText); GameObject.Find("Canvas/cover").SetActive(false); GameObject.Find("Canvas/garden_box").SetActive(false); m_garden temp = new m_garden(); temp.setId(long.Parse(res.DataAsText)); temp.setName(garden_name.text); temp.setLength(int.Parse(length.text)); temp.setWidth(int.Parse(width.text)); temp.setIdealTemperature(float.Parse(temperature.text)); temp.setIdealHumidity(float.Parse(humidity.text)); data.m_user.addGardens(temp); Dropdown.OptionData newOption = new Dropdown.OptionData(); newOption.text = garden_name.text; List <Dropdown.OptionData> newOptions = new List <Dropdown.OptionData>(); newOptions.Add(newOption); GameObject.Find("Canvas/gardens").GetComponent <Dropdown>().AddOptions(newOptions); GameObject.Find("Canvas/gardens").GetComponent <Dropdown>().value = GameObject.Find("Canvas/gardens").GetComponent <Dropdown>().options.Count - 1; break; default: Debug.Log("Error!Status code:" + res.StatusCode); break; } }); request.AddHeader("Content-Type", "application/json"); JsonData newGarden = new JsonData(); newGarden["userId"] = data.m_user.getId(); newGarden["width"] = width.text; newGarden["length"] = length.text; newGarden["name"] = garden_name.text; newGarden["idealTemperature"] = temperature.text; newGarden["idealWetness"] = humidity.text; request.RawData = System.Text.Encoding.UTF8.GetBytes(newGarden.ToJson()); request.Send(); } }
public static void GetGardenInfo(m_garden garden) { HTTPRequest request_getGarden = new HTTPRequest(new Uri(data.IP + "/getGardenById?id=" + garden.getId()), HTTPMethods.Get, (req_garden, res_garden) => { JsonData json = JsonMapper.ToObject(res_garden.DataAsText); Debug.Log(res_garden.DataAsText); garden.setName((string)json["name"]); garden.setLength((int)json["length"]); garden.setWidth((int)json["width"]); garden.setIdealTemperature(float.Parse(json["idealTemperature"].ToString())); garden.setIdealHumidity(float.Parse(json["idealWetness"].ToString())); }).Send(); }
public static void FreshGardens(m_garden garden) { data.m_user.clearGardens(); HTTPRequest request_getGarden = new HTTPRequest(new Uri(data.IP + "/getGardenByUserId?userId=" + data.m_user.getId()), HTTPMethods.Get, (req_garden, res_garden) => { Debug.Log(res_garden.DataAsText); JArray array = JArray.Parse(res_garden.DataAsText); foreach (var e in array) { m_garden newGarden = new m_garden(); newGarden.setId((long)e["id"]); newGarden.setName((string)e["name"]); newGarden.setLength((int)e["length"]); newGarden.setWidth((int)e["width"]); newGarden.setIdealTemperature((float)e["idealTemperature"]); newGarden.setIdealHumidity((float)e["idealWetness"]); Debug.Log(newGarden.getName()); data.m_user.addGardens(newGarden); } FreshGarden(garden); }).Send(); }