Esempio n. 1
0
    /******************** GET ********************/

    public IEnumerator GetAccount(Cookie cookie, System.Action <Account> callback)
    {
        Debug.Log(cookie.Value);
        string          id  = JWTHelper.DecodePayload(cookie.Value);
        UnityWebRequest uwr = UnityWebRequest.Get(SERVER + "accounts/" + id);

        uwr.SetRequestHeader("Content-Type", "application/json; charset=UTF-8");
        uwr.SetRequestHeader("Authorization", "Bearer " + cookie.Value);

        Debug.Log(uwr.ToString());

        yield return(uwr.SendWebRequest());

        if (uwr.isNetworkError || uwr.isHttpError)
        {
            //Controller.Instance.Error(uwr.error);
            string  text = uwr.downloadHandler.text;
            JObject json = JObject.Parse(text);
            callback(new Account()
            {
                LastName = "Erreur " + uwr.responseCode + ", " + json["message"]
            });
        }
        else
        {
            string text = uwr.downloadHandler.text;
            Debug.Log(uwr.ToString());
            Account account = null;
            yield return(JSONHelper.Instance.ToAccount(text, value => account = value));

            callback(account);
        }
    }
Esempio n. 2
0
    public IEnumerator Start()
    {
        Creator c = new Creator
        {
            Id        = "0@bob",
            Username  = "******",
            Mail      = "*****@*****.**",
            Password  = "******",
            LastName  = "fdibs",
            FirstName = "bob",
            Xp        = 0L,
            Role      = RoleAccount.CREATOR
        };

        CheckPoint cp1 = new CheckPoint
        {
            Picture = "/pic",
            Text    = "Text of checkpoint",
            Choices = { "choix 1", "choix2", "choix3" },
            Answer  = "choix1"
        };
        CheckPoint cp2 = new CheckPoint
        {
            Picture = "/pic",
            Text    = "Text of checkpoint",
            Choices = { "choix 1", "choix2", "choix3" },
            Answer  = "choix2"
        };
        CheckPoint cp3 = new CheckPoint
        {
            Picture = "/pic",
            Text    = "Text of checkpoint",
            Choices = { "choix 1", "choix2", "choix3" },
            Answer  = "choix3"
        };

        Quest q1 = new Quest
        {
            Title           = "quete1",
            Description     = "Super quete cool",
            Geolocalisation = { x = 10, y = 45 },
            Open            = true,
            IdCreator       = c.Id,
            Checkpoints     = { cp1, cp2, cp3 },
        };

        //HTTPHelper.Send(c);
        Cookie auth = null;

        yield return(HTTPHelper.Instance.AuthLogin("*****@*****.**", "pass", value => auth = value));

        Debug.Log(auth.Value);
        string decoded = JWTHelper.DecodePayload(auth.Value);

        Debug.Log(decoded);

        Account pasAccount = null;

        yield return(HTTPHelper.Instance.GetAccount(auth, value => pasAccount = value));


        //HTTPHelper.Persist(c);
        bool result;

        yield return(HTTPHelper.Instance.Persist(q1, auth, value => result = value));

        //tuser.text = JSONHelper.ToJsonString(q1);

        string questJson =
            "{" +
            "\"_idCreator\": \"0@bob\"," +
            "\"geolocalisation\": {" +
            "\"x\": 10.0," +
            "\"y\": 45.0" +
            "}," +
            "\"title\": \"quete1\"," +
            "\"description\": \"Super quête cool\"," +
            "\"checkpoints\": [" +
            "{" +
            "\"text\": \"Text of checkpoint 1\"," +
            "\"choices\": [" +
            "\"choix 1\"," +
            "\"choix 2\"," +
            "\"choix 3\"" +
            "]," +
            "\"answer\": \"choix 1\"," +
            "\"difficulty\": 0" +
            "}," +
            "{" +
            "\"text\": \"Text of checkpoint 2\"," +
            "\"choices\": [" +
            "\"choix 1\"," +
            "\"choix 2\"," +
            "\"choix 3\"" +
            "]," +
            "\"answer\": \"choix 3\"," +
            "\"difficulty\": 0" +
            "}" +
            "]," +
            "\"value\": 0" +   //complètement random
            "}";

        string accountJson = "{" +
                             "\"connection\": {" +
                             "\"email\": \"[email protected]\"," +
                             "\"password\": \"test\"" +
                             "}," +
                             "\"userInformation\": {" +
                             "\"lastname\": \"test\"," +
                             "\"firstname\": \"test\"," +
                             "\"username\": \"test\"," +
                             "\"accountType\": \"CREATOR\"" +
                             "}," +
                             "\"createdAt\": \"2018-04-30T15:52:28\"," +
                             "\"updatedAt\": \"2018-04-30T15:52:28\"," +
                             "\"game\": {" +
                             "\"badges\": [0, 1, 2]," +
                             "\"quests\": [{" +
                             "\"_idQuest\": 0," +
                             "\"state\": \"IN_PROGRESS\"," +
                             "\"stats\": { \"earnedXP\": 42 }" +
                             "}]," +
                             "\"xp\": 42," +
                             "\"elapsedTime\": 42" +
                             "}" +
                             "}";

        string badgeJson = "{" +
                           "\"name\": \"test\"," +
                           "\"description\": \"description du badge\"," +
                           "\"iconPath\": \"path de l'icône\"," +
                           "\"require\": {" +
                           "\"xp\": 42," +
                           "\"totalElapsedTime\": 42" +
                           "}," +
                           "\"earn\": 42" +
                           "}";
    }