示例#1
0
        public IEnumerator Connect(KeyValuePair <string, string> account, Action <FileFormat.JSON> onComplete = null, Action <string> onError = null)
        {
            Manager.UpdateLoadingStatus("provider.connecting", "Establishing the connection with [0]", true, Name);

            //Get Token
            var accountRequest = UnityWebRequest.Post("https://api.ecoledirecte.com/v3/login.awp", $"data={{\"identifiant\": \"{account.Key}\", \"motdepasse\": \"{account.Value}\"}}");

            yield return(accountRequest.SendWebRequest());

            var accountInfos = new FileFormat.JSON(accountRequest.downloadHandler.text);

            if (accountRequest.isNetworkError || accountInfos.Value <int>("code") != 200)
            {
                string errorMsg = accountRequest.error;
                if (!accountRequest.isNetworkError)
                {
                    if (accountInfos.jToken.TryGetValue("message", out var v))
                    {
                        errorMsg = v.Value <string>();
                    }
                    else
                    {
                        errorMsg = accountRequest.downloadHandler.text;
                    }
                }
                onError?.Invoke(errorMsg);
                Manager.HideLoadingPanel();
                Debug.LogError(errorMsg);
                yield break;
            }
            token = accountInfos.Value <string>("token");
            onComplete?.Invoke(accountInfos);
        }
示例#2
0
        public IEnumerator GetInfos(Data.Data data, Action <Data.Data> onComplete)
        {
            var accountRequest = UnityWebRequest.Get("https://cambridgekids.sophiacloud.com/console/index.php?page=MyDaily");

            accountRequest.SetRequestHeader("User-Agent", "Mozilla/5.0 Firefox/74.0");
            accountRequest.SetRequestHeader("Cookie", sessionId);
            yield return(accountRequest.SendWebRequest());

            var response = "";

            foreach (var line in accountRequest.downloadHandler.text.Split('\n'))
            {
                if (line.TrimStart('\t').StartsWith("window.page_data = "))
                {
                    response = line.TrimStart('\t').Substring("window.page_data = ".Length);
                    response = response.Remove(response.Length - 2);
                    break;
                }
            }
            if (string.IsNullOrEmpty(response))
            {
                Logging.Log("Un erreur est survenue", LogType.Error); Manager.HideLoadingPanel(); yield break;
            }
            var json   = new FileFormat.JSON(response);
            var userID = json.GetCategory("user_session").GetCategory("settings").Value <string>("user_id");

            accountRequest = UnityWebRequest.Get($"https://cambridgekids.sophiacloud.com/console/sophiacloud/data_mgr.php?s=user&user_id={userID}&verbose=page");
            accountRequest.SetRequestHeader("User-Agent", "Mozilla/5.0 Firefox/74.0");
            accountRequest.SetRequestHeader("Cookie", sessionId);
            yield return(accountRequest.SendWebRequest());

            json = new FileFormat.JSON(accountRequest.downloadHandler.text);
            var accountId = json.jToken.SelectToken("account_user").First.Value <string>("account_id");

            accountRequest = UnityWebRequest.Get($"https://cambridgekids.sophiacloud.com/console/sophiacloud/data_mgr.php?s=account&account_id={accountId}&verbose=page");
            accountRequest.SetRequestHeader("User-Agent", "Mozilla/5.0 Firefox/74.0");
            accountRequest.SetRequestHeader("Cookie", sessionId);
            yield return(accountRequest.SendWebRequest());

            json = new FileFormat.JSON(accountRequest.downloadHandler.text);
            var enfants = json.jToken.SelectToken("account_user").Where(obj => obj.Value <string>("type") == "1").Select(enfant =>
            {
                var name = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase($"{enfant.Value<string>("prenom")}{enfant.Value<string>("nom")}".ToLower());
                return(new Child {
                    name = name, id = enfant.Value <string>("user_id"), modules = new List <string> {
                        "Homeworks"
                    }
                });
            }).ToArray();

            Manager.HideLoadingPanel();
            var label = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(json.Value <string>("account_name").ToLower());

            data.Children = enfants;
            data.Label    = label;
            onComplete?.Invoke(data);
            Manager.HideLoadingPanel();
        }