예제 #1
0
        private async void loginBtn_Click(object sender, RoutedEventArgs e)
        {
            //Check not null
            if (username.Text == "" || password.Password == "")
            {
                //Notify
                NotifyPopup notifyPopup = new NotifyPopup("账号或密码不能为空!");
                notifyPopup.Show();
                return;
            }
            //Get usr and pwd
            string stunum = username.Text,
                passwd = password.Password;
            localSettings.Values["muser"] = stunum;
            localSettings.Values["passwd"] = passwd;
            /*
            //base64 for pwd
            byte[] bytes = Encoding.UTF8.GetBytes(passwd);
            passwd = Convert.ToBase64String(bytes);
            LogInVerification(stunum,passwd);
            */
            bool loginCheck;
            toggleLoginState();
            loginCheck = await MockJwch.MockLogin();
            toggleLoginState();
            if (!loginCheck)
            {
                return;
            }
            await MockJwch.MockGetCurrentUser();
            //get week and term
            try
            {
                await MockJwch.MockGetCurrentCalendar();
            }
            catch
            {

            }
            
            if (loginCheck)
            {
                Frame.Navigate(typeof(AppShell));
            }
            else
            {
                NotifyPopup notifyPopup = new NotifyPopup("网络错误");
                notifyPopup.Show();
            }
        }
예제 #2
0
 private bool ShowResult(bool IsNextPage)
 {
     if (!IsNextPage)
     {
         bookSearchResult.ItemsSource = null;
         try
         {
             b = JsonConvert.DeserializeObject<BookSearchResult>(jsonData);
         }
         catch
         {
             return false;
         }
     }
     if(b.errMsg == "图书馆请求信息失败")
     {
         NotifyPopup notifyPopup = new NotifyPopup(b.errMsg);
         notifyPopup.Show();
         return false;
     }
     bookSearchResult.ItemsSource = b.data;
     page++;
     return true;
 }
예제 #3
0
        private async Task MockGet(bool IsRefresh)
        {
            if (IsRefresh)
            {
                bool status = await MockJwch.MockGetScore();
                if (!status)
                {
                    NotifyPopup notifyPopup = new NotifyPopup("获取成绩失败");
                    notifyPopup.Show();
                    return;
                }
                try
                {
                    //Get data from storage
                    StorageFolder fzuhelperDataFolder = await ApplicationData.Current.LocalFolder.GetFolderAsync("FzuhelperData");
                    StorageFile score = await fzuhelperDataFolder.GetFileAsync("score.dat");
                    htmlStr = await FileIO.ReadTextAsync(score);
                }
                catch
                {

                }
            }
            else
            {
                try
                {
                    //Get data from storage
                    StorageFolder fzuhelperDataFolder = await ApplicationData.Current.LocalFolder.GetFolderAsync("FzuhelperData");
                    StorageFile score = await fzuhelperDataFolder.GetFileAsync("score.dat");
                    htmlStr = await FileIO.ReadTextAsync(score);
                }
                catch
                {
                    bool status = await MockJwch.MockGetScore();
                    if (!status)
                    {
                        NotifyPopup notifyPopup = new NotifyPopup("获取成绩失败");
                        notifyPopup.Show();
                    }
                    else
                    {
                        await MockGet(false);
                    }
                }
            }
        }
예제 #4
0
        /*private async void IniList(bool IsRefresh)
        {
            refreshIndicator.IsActive = true;
            if (!IsRefresh)
            {
                try
                {
                    //Get data from storage
                    StorageFolder fzuhelperDataFolder = await ApplicationData.Current.LocalFolder.GetFolderAsync("FzuhelperData");
                    StorageFile score = await fzuhelperDataFolder.GetFileAsync("score.dat");
                    jsonData = await FileIO.ReadTextAsync(score);
                }
                catch
                {
                    if (firstTimeLoad)
                    {
                        IniList(true);
                        firstTimeLoad = false;
                        return;
                    }
                    MainPage.SendToast("获取数据出错,请刷新");
                    refreshIndicator.IsActive = false;
                    return;
                }
            }
            else
            {
                try
                {
                    jsonData = await HttpRequest.GetScore();
                    if (jsonData == "error")
                    {
                        MainPage.SendToast("获取数据出错");
                        refreshIndicator.IsActive = false;
                        return;
                    }
                }
                catch
                {
                    MainPage.SendToast("获取数据出错");
                    refreshIndicator.IsActive = false;
                    return;
                }
            }
            try
            {
                srv = JsonConvert.DeserializeObject<ScoreReturnValue>(jsonData);
                markArr = JsonConvert.DeserializeObject<List<ScoreArr>>(srv.data["markArr"].ToString());
                Groups = CreateGroups();
                cvsGroups.Source = Groups;
                listViewZoomOutView.ItemsSource = cvsGroups.View.CollectionGroups;
                GetAllGradePoint(IsRefresh);
                //Unknown error, just login again
                if (markArr.Count == 0 && getAgain)
                {
                    getAgain = false;
                    await HttpRequest.ReLogin();
                    IniList(true);
                }
            }
            catch
            {
                getAgain = true;
                MainPage.SendToast("获取数据出错,请刷新");
            }
            refreshIndicator.IsActive = false;
        }*/

        private async Task GetAllGradePoint(bool IsRefresh)
        {
            gradePointListView.ItemsSource = null;
            gradePointArr.Clear();
            string year = "", term = "";
            foreach (string item in countTime)
            {
                year = item.Substring(0, 4);
                term = item.Substring(4);
                if (IsRefresh)
                {
                    try
                    {
                        jsonData = await HttpRequest.GetGradePoint(year, term);
                    }
                    catch
                    {
                        return;
                    }
                }
                else
                {
                    try
                    {
                        //from storage
                        StorageFolder fzuhelperDataFolder = await ApplicationData.Current.LocalFolder.GetFolderAsync("FzuhelperData");
                        StorageFile gradePointFile = await fzuhelperDataFolder.GetFileAsync(year + term + ".dat");
                        jsonData = await FileIO.ReadTextAsync(gradePointFile);
                    }
                    catch
                    {
                        jsonData = await HttpRequest.GetGradePoint(year, term);
                    }
                }
                try
                {
                    gprv = JsonConvert.DeserializeObject<GradePointReturnValue>(jsonData);
                    GradePointArr gpArr = new GradePointArr();
                    gpArr.term = item;
                    gpArr.point = gprv.data["point"];
                    gpArr.rank_total = gprv.data["rank"] + "/" + gprv.data["totalStudents"];
                    gradePointArr.Add(gpArr);
                }
                catch
                {
                    if (IsRefresh)
                    {
                        NotifyPopup notifyPopup = new NotifyPopup(year + term + "绩点更新失败");
                        notifyPopup.Show();
                    }
                }
            }
            gradePointListView.ItemsSource = gradePointArr;
        }
예제 #5
0
파일: MockJwch.cs 프로젝트: C2CCC/Fzuhelper
        public static async Task<bool> MockLogin()
        {
            HttpClient request = CreateHttpClient();
            try
            {
                HttpResponseMessage response = new HttpResponseMessage();
                request.DefaultRequestHeaders.Add("Origin", "http://jwch.fzu.edu.cn");
                request.DefaultRequestHeaders.Add("Referer", "http://jwch.fzu.edu.cn/");
                //request.DefaultRequestHeaders.Add("Content-Type", "application/x-www-form-urlencoded");
                //Prepare post data
                string muser = localSettings.Values["muser"].ToString();
                string passwd = localSettings.Values["passwd"].ToString();
                FormUrlEncodedContent content = new FormUrlEncodedContent(new[] {
                    new KeyValuePair<string, string>("muser", muser),
                    new KeyValuePair<string, string>("passwd", passwd),
                    new KeyValuePair<string, string>("x", "0"),
                    new KeyValuePair<string, string>("y", "0"),
                });

                //Get response
                response = await request.PostAsync(mockLoginUri, content);
                string responseStr1 = await response.Content.ReadAsStringAsync();
                if (responseStr1.Contains("alert"))
                {
                    NotifyPopup notifyPopup = new NotifyPopup("账号或密码错误");
                    notifyPopup.Show();
                    request.Dispose();
                    return false;
                }

                //response.Headers.GetValues("Set-Cookie");
                Uri redirectUri = response.Headers.Location;
                request.DefaultRequestHeaders.Remove("Origin");
                response = await request.GetAsync(redirectUri);
                string responseStr2 = await response.Content.ReadAsStringAsync();

                //ASP.NET_SessionId
                try
                {
                    string[] respCookie = (string[])response.Headers.GetValues("Set-Cookie");
                    string aspDotNetSessionCookie = respCookie[0].Split(';')[0];
                    localSettings.Values["AspDotNetSessionCookie"] = aspDotNetSessionCookie;
                }
                catch
                {

                }

                if (responseStr2.Contains("alert"))
                {
                    NotifyPopup notifyPopup = new NotifyPopup("账号或密码错误");
                    notifyPopup.Show();
                    request.Dispose();
                    return false;
                }

                //id
                string queryId = response.Headers.Location.Query.Substring(4);

                localSettings.Values["QueryId"] = queryId;
                localSettings.Values["IsLogedIn"] = true;

                request.Dispose();

                return true;
            }
            catch
            {
                request.Dispose();
                return false;
            }
        }
예제 #6
0
 public static async Task<string> GetFromJwch(string method,string purpose,HttpFormUrlEncodedContent content,bool tokenRequire = false)
 {
     string uri;
     switch (purpose)
     {
         case "Login":
             uri = Login;
             break;
         case "getTimetable":
             uri = getTimetable;
             break;
         case "getScore":
             uri = getScore;
             break;
         case "getExamRoom":
             uri = getExamRoom;
             break;
         case "getBookSearchResult":
             uri = getBookSearchResult;
             break;
         case "getJwchNotice":
             uri = getJwchNotice;
             break;
         case "getGradePoint":
             uri = getGradePoint;
             break;
         case "getEmptyRoom":
             uri = getEmptyRoom;
             break;
         case "getCurrentWeek":
             uri = getCurrentWeek;
             break;
         default:
             uri = "";
             break;
     }
     HttpResponseMessage httpResponse = new HttpResponseMessage();
     string httpResponseBody = "";
     try
     {
         if (method == "post")
         {
             httpResponse = await httpClient.PostAsync(new Uri(uri), content);
         }
         else
         {
             string con = await content.ReadAsStringAsync();
             uri = uri + "?" + con;
             httpResponse = await httpClient.GetAsync(new Uri(uri));
         }
         httpResponse.EnsureSuccessStatusCode();
         httpResponseBody = await httpResponse.Content.ReadAsStringAsync();
         //Check if the return data is correct
         try
         {
             if (tokenRequire)
             {
                 CheckJwch c = JsonConvert.DeserializeObject<CheckJwch>(httpResponseBody);
                 if (c.errMsg != "" && c.errMsg != null)
                 {
                     await ReLogin();
                     return "relogin";
                 }
             }
             return httpResponseBody;
         }
         catch
         {
             return httpResponseBody;
         }
     }
     catch
     {
         NotifyPopup notifyPopup = new NotifyPopup("网络错误");
         notifyPopup.Show();
         return "error";
     }
 }
예제 #7
0
 public static async Task ReLogin()
 {
     try
     {
         //Get accInfo
         StorageFolder fzuhelperDataFolder = await ApplicationData.Current.LocalFolder.GetFolderAsync("FzuhelperData");
         StorageFile accInfo = await fzuhelperDataFolder.GetFileAsync("accInfo.dat");
         String info = await FileIO.ReadTextAsync(accInfo);
         string[] usr = info.Split('\n');
         //Create HttpContent
         HttpFormUrlEncodedContent content = new HttpFormUrlEncodedContent(
         new[]
         {
             new KeyValuePair<string,string>("stunum",usr[0]),
             new KeyValuePair<string,string>("passwd",usr[1]),
         });
         //Login
         string response = "";
         try
         {
             response = await GetFromJwch("post", "Login", content);
             if (response == "error")
             {
                 return;
             }
         }
         catch
         {
             NotifyPopup notifyPopup = new NotifyPopup("网络错误");
             notifyPopup.Show();
             return;
         }
         LogInReturnValue l = JsonConvert.DeserializeObject<LogInReturnValue>(response);
         StorageFile usrInfo = await fzuhelperDataFolder.CreateFileAsync("usrInfo.dat", CreationCollisionOption.ReplaceExisting);
         await FileIO.WriteTextAsync(usrInfo, l.data["stuname"] + "\n" + l.data["token"]);
     }
     catch
     {
         NotifyPopup notifyPopup = new NotifyPopup("身份过期,请重新登录");
         notifyPopup.Show();
         return;
     }
 }