Пример #1
0
        private IEnumerator UserLogin(Action <bool, string> Callback)
        {
            Debug.Log(Constantes.urlApi + Constantes.uriGetUserByEmail + email.text);
            ClassRequest getUser = new ClassRequest(Constantes.urlApi + Constantes.uriGetUserByEmail + email.text);

            yield return(getUser.GetRequest(Debug.Log));

            ClassRequest testConn = new ClassRequest(Constantes.urlApi + Constantes.uriConnect, curUser.ToJson());

            yield return(testConn.PostRequest(Debug.Log));

            curUser.password = null;
            Debug.Log(getUser.json);
            curUser       = JsonUtility.FromJson <User>(getUser.json);
            curUser.token = JsonUtility.FromJson <Token>(testConn.json);
            Debug.Log(curUser._id);
            if (curUser.token is null)
            {
                Callback(false, "Identifiants incorrects");
            }
            else
            {
                Callback(true, curUser.ToJson());
            }
        }
Пример #2
0
        public void SubmitForm()
        {
            usage = new Usage(start.date.ToString("yyyy/MM/dd hh:mm"), end.date.ToString("yyyy/MM/dd hh:mm"), vehicle.vehicleSelected, user, purpose.text, description.text);
            Debug.Log(usage.ToJson());
            ClassRequest reqNewUsage = new ClassRequest(Constantes.urlApi + Constantes.uriPostUsage, usage.ToJson());

            if (isNewUsage)
            {
                StartCoroutine(reqNewUsage.PostRequest(GetResult, user.token.token));
            }
            else
            {
                Debug.Log("Send put request");
            }
        }
Пример #3
0
        public void OnClick()
        {
            usage.purpose     = purpose.text;
            usage.description = description.text;

            if (PlayerPrefs.GetInt("isNewUsage") == 1)
            {
                string json = usage.ToJson();
                json = json.Remove(1, 9); // supprime _id
                Debug.Log(usage.ToJson());
                request = new ClassRequest(Constantes.urlApi + Constantes.uriPostUsage, json);

                StartCoroutine(request.PostRequest(Result, PlayerPrefs.GetString("token")));
            }
            else
            {
                request = new ClassRequest(Constantes.urlApi + Constantes.uriPostUsage + "/" + usage._id, usage.ToJson());
                StartCoroutine(request.PutRequest(Result));
            }
            PlayerPrefs.DeleteKey("usage");
            PlayerPrefs.DeleteKey("startUsage");
            PlayerPrefs.DeleteKey("endUsage");
            PlayerPrefs.DeleteKey("isNewUsage");
        }