Пример #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
        // Marks
        public IEnumerator GetMarks(Action onComplete)
        {
            FileFormat.JSON        result  = null;
            Func <UnityWebRequest> request = () => UnityWebRequest.Post($"https://api.ecoledirecte.com/v3/eleves/{Manager.Data.activeChild}/notes.awp?verbe=get&", $"data={{\"token\": \"{token}\"}}");

            yield return(TryConnection(request, "marks", (o) => result = o));

            if (result == null)
            {
                yield break;
            }

            Manager.Data.ActiveChild.Trimesters = result.jToken.SelectToken("data.periodes")?.Values <JObject>().Where(obj => !obj.Value <bool>("annuel")).Select(obj => new Trimester
            {
                id    = obj.Value <string>("idPeriode"),
                name  = obj.Value <string>("periode"),
                start = obj.Value <DateTime>("dateDebut"),
                end   = obj.Value <DateTime>("dateFin")
            }).ToList();

            var subjects = Manager.Data.ActiveChild.Subjects ?? new List <Subject>();

            foreach (var obj in result.jToken.SelectToken("data.periodes[0].ensembleMatieres.disciplines").Where(obj => !obj.SelectToken("groupeMatiere").Value <bool>()))
            {
                if (!subjects.Any(s => s.id == obj.Value <string>("codeMatiere")))
                {
                    subjects.Add(new Subject
                    {
                        id       = obj.SelectToken("codeMatiere").Value <string>(),
                        name     = obj.SelectToken("discipline").Value <string>(),
                        coef     = float.TryParse(obj.SelectToken("coef").Value <string>().Replace(",", "."), out var coef) ? coef : 1,
                        teachers = obj.SelectToken("professeurs").Select(o => o.SelectToken("nom").Value <string>()).ToArray()
                    });
Пример #3
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();
        }
Пример #4
0
        public IEnumerator GetHomeworks(Homework.Period period, Action onComplete)
        {
            if (string.IsNullOrEmpty(sessionId))
            {
                yield return(Connect(Modules.Accounts.GetCredential));
            }
            Manager.UpdateLoadingStatus("provider.homeworks", "Getting homeworks");

            var request = UnityWebRequest.Get($"https://cambridgekids.sophiacloud.com/console/sophiacloud/data_mgr.php?s=interactive_worksheet&timestamp=0&service_id={period.id}");

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

            var result = new FileFormat.JSON($"{{\"list\":{request.downloadHandler.text}}}");

            if (Manager.Data.ActiveChild.Subjects == null)
            {
                Manager.Data.ActiveChild.Subjects = new List <Subject>();
            }
            if (Manager.Data.ActiveChild.Homeworks == null)
            {
                Manager.Data.ActiveChild.Homeworks = new List <Homework>();
            }
            Manager.Data.ActiveChild.Homeworks.AddRange(result.jToken.SelectToken("list").SelectMany(obj =>
            {
                var data = obj.SelectToken("page_section");
                var docs = obj.SelectToken("link_file").Select(doc => new Document
                {
                    id   = doc.Value <string>("up_file_id"),
                    name = doc.Value <string>("file_name")
                });
                return(data.Select(d =>
                {
                    if (!Manager.Data.ActiveChild.Subjects.Any(s => s.id == d.Value <string>("page_section_id")))
                    {
                        Manager.Data.ActiveChild.Subjects.Add(new Subject {
                            id = d.Value <string>("page_section_id"), name = d.Value <string>("sec_title"), color = new Color(0.3F, 0.3F, 0.3F)
                        });
                    }
                    return new Homework
                    {
                        periodID = period.id,
                        subjectID = d.Value <string>("page_section_id"),
                        forThe = (double.TryParse(obj.Value <string>("date_evenement"), out var date) ? date : 0).UnixTimeStampToDateTime(),
                        addedBy = data.First.Value <string>("prenom") + " " + data.First.Value <string>("nom"),
                        addedThe = (double.TryParse(obj.Value <string>("date_creation"), out var _d) ? _d : 0).UnixTimeStampToDateTime(),
                        content = Renderer.HTML.ToRichText(d.Value <string>("text")).RemoveEmptyLines(),
                        documents = docs.ToList()
                    };
                }));
            }));

            onComplete?.Invoke();
            Manager.HideLoadingPanel();
        }
Пример #5
0
        public IEnumerator <Homework.Period> DiaryPeriods()
        {
            if (string.IsNullOrEmpty(sessionId))
            {
                bool   done  = false;
                string error = null;
                UnityThread.executeCoroutine(Connect(Modules.Accounts.GetCredential, () => done = true, (e) => error = e));
                while (!done && error == null)
                {
                    yield return(null);
                }
                if (error != null)
                {
                    Logging.Log(error);
                    yield break;
                }
            }

            var request = UnityWebRequest.Get($"https://cambridgekids.sophiacloud.com/console/sophiacloud/data_mgr.php?s=feed&q=service_search&beneficiaire_user_id={Manager.Data.ActiveChild.id}&interactive_worksheet=1&scl_version=v46-697-gb3c6cf80&mode_debutant=1");

            request.SetRequestHeader("User-Agent", "Mozilla/5.0 Firefox/74.0");
            request.SetRequestHeader("Cookie", sessionId);
            request.SendWebRequest();
            while (!request.isDone)
            {
                yield return(null);
            }
            var result  = new FileFormat.JSON(request.downloadHandler.text);
            var periods = result.jToken.SelectToken("service_search").Where(obj => !string.IsNullOrEmpty(obj.Value <string>("date_debut")));

            foreach (var period in periods)
            {
                yield return(new Homework.Period
                {
                    name = period.Value <string>("description"),
                    id = period.Value <string>("service_id")
                });
            }
        }
Пример #6
0
        // Provider
        public IEnumerator GetInfos(Data.Data data, Action <Data.Data> onComplete)
        {
            Manager.UpdateLoadingStatus("provider.connecting", "Establishing the connection with [0]", true, Name);

            FileFormat.JSON accountInfos = null;
            yield return(Connect(Accounts.GetCredential, (j) => accountInfos = j));

            var Account = accountInfos.jToken.SelectToken("data.accounts").FirstOrDefault();
            var childs  = new List <Child>();

            yield return(GetChild(Account, Account.Value <string>("typeCompte") == "E" ? "eleves" : "familles", (c) => childs.Add(c)));

            if (Account.Value <string>("typeCompte") != "E")
            {
                //Get eleves
                var eleves = Account.SelectToken("profile").Value <JArray>("eleves");
                foreach (var eleve in eleves)
                {
                    yield return(GetChild(eleve, "eleves", (c) => childs.Add(c)));
                }
            }
            Manager.HideLoadingPanel();
            data.Label    = childs.First().name;
            data.Children = childs.ToArray();
            onComplete?.Invoke(data);

            IEnumerator GetChild(JToken profile, string type, Action <Child> child)
            {
                //Get picture
                Sprite picture = null;
                var    url     = profile.Value <string>("photo");

                if (!string.IsNullOrWhiteSpace(url))
                {
                    var profileRequest = UnityWebRequestTexture.GetTexture("https:" + url);
                    profileRequest.SetRequestHeader("referer", $"https://www.ecoledirecte.com/Famille");
                    yield return(profileRequest.SendWebRequest());

                    if (!profileRequest.isHttpError)
                    {
                        var tex = DownloadHandlerTexture.GetContent(profileRequest);
                        picture = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f));
                    }
                    else
                    {
                        Logging.Log("Error getting profile picture, server returned " + profileRequest.error + "\n" + profileRequest.url, LogType.Warning);
                    }
                }

                var moduleCores = new Dictionary <string, string[]>
                {
                    { "NOTES", new [] { "Marks" } },
                    { "MESSAGERIE", new [] { "Messanging" } },
                    { "EDT", new [] { "Schedule" } },
                    { "CAHIER_DE_TEXTES", new [] { "Homeworks", "SessionContent", "Books" } },
                    { "CLOUD", new[] { "Documents" } },
                    { "VIE_DE_LA_CLASSE", new[] { "Documents" } },
                    { "DOCUMENTS_ELEVE", new[] { "Documents" } },
                    { "DOCUMENTS", new[] { "Documents" } }
                };

                child?.Invoke(new Child
                {
                    name    = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase($"{profile.Value<string>("prenom")} {profile.Value<string>("nom")}".ToLower()),
                    id      = profile.Value <string>("id"),
                    modules = profile.SelectToken("modules")
                              .Where(m => m.Value <bool>("enable") && moduleCores.ContainsKey(m.Value <string>("code")))
                              .SelectMany(m => moduleCores[m.Value <string>("code")]).Append("Periods").ToList(),
                    sprite    = picture,
                    extraData = new Dictionary <string, string> {
                        { "type", type },
                        { "edModules", Newtonsoft.Json.JsonConvert.SerializeObject(profile.SelectToken("modules").Where(m => m.Value <bool>("enable")).Select(m => m.Value <string>("code")).ToArray()) }
                    }
                });
            }
        }