Ejemplo n.º 1
0
 private System.ValueTuple <string, string, string, CookieContainer> Authenticate(string user_id, string pwd)
 {
     if (this.role.Contains("SMU"))
     {
         user_id = this.role + user_id;
         HtmlWeb      auth_web = new HtmlWeb();
         HtmlDocument auth_doc = null;
         try
         {
             auth_doc = auth_web.Load("https://login.libproxy.smu.edu.sg/login?auth=shibboleth&url=https://www.lawnet.sg/lawnet/web/lawnet/ip-access");
         }
         catch (Exception)
         {
             System.ValueTuple <string, string, string, CookieContainer> result = new System.ValueTuple <string, string, string, CookieContainer>("FAIL", "", "INTERNET CONNECTION ERROR", null);
             return(result);
         }
         if (auth_doc.DocumentNode.SelectSingleNode("//input[@name='SAMLRequest']") == null)
         {
             return(new System.ValueTuple <string, string, string, CookieContainer>("AUTHENTICATED", "", "ALREADY AUTHENTICATATED", null));
         }
         string      SAMLRequest  = auth_doc.DocumentNode.SelectSingleNode("//input[@name='SAMLRequest']").GetAttributeValue("value", "");
         string      RelayState   = auth_doc.DocumentNode.SelectSingleNode("//input[@name='RelayState']").GetAttributeValue("value", "");
         RestClient  arg_11D_0    = new RestClient("https://login.smu.edu.sg/adfs/ls/");
         RestRequest auth_request = new RestRequest(Method.POST);
         auth_request.AddParameter("SAMLRequest", SAMLRequest);
         auth_request.AddParameter("RelayState", RelayState);
         auth_request.AddParameter("UserName", user_id);
         auth_request.AddParameter("Password", pwd);
         auth_request.AddParameter("AuthMethod", "FormsAuthentication");
         IRestResponse auth_response     = arg_11D_0.Execute(auth_request);
         HtmlDocument  SAMLResponse_html = new HtmlDocument();
         SAMLResponse_html.LoadHtml(auth_response.Content);
         if (SAMLResponse_html.DocumentNode.SelectSingleNode("//input[@name='SAMLResponse']") == null)
         {
             return(new System.ValueTuple <string, string, string, CookieContainer>("FAIL", "", "CREDENTIAL ERROR", null));
         }
         string     SAMLResponse   = SAMLResponse_html.DocumentNode.SelectSingleNode("//input[@name='SAMLResponse']").GetAttributeValue("value", "");
         string     RelayStatePost = SAMLResponse_html.DocumentNode.SelectSingleNode("//input[@name='RelayState']").GetAttributeValue("value", "");
         RestClient cookie_client  = new RestClient("https://login.libproxy.smu.edu.sg/Shibboleth.sso/SAML2/POST")
         {
             CookieContainer = new CookieContainer()
         };
         RestRequest cookie_request = new RestRequest(Method.POST);
         cookie_request.AddParameter("SAMLResponse", SAMLResponse);
         cookie_request.AddParameter("RelayState", RelayStatePost);
         IRestResponse cookie_response = cookie_client.Execute(cookie_request);
         if (cookie_response.ResponseUri.ToString() == "https://www-lawnet-sg.libproxy.smu.edu.sg/lawnet/group/lawnet/legal-research/basic-search")
         {
             return(new System.ValueTuple <string, string, string, CookieContainer>("SUCCESS", cookie_response.Cookies.First <RestResponseCookie>().Name, cookie_response.Cookies.First <RestResponseCookie>().Value, cookie_client.CookieContainer));
         }
         return(new System.ValueTuple <string, string, string, CookieContainer>("FAIL", "", "LAWNET UNDER MAINTENANCE", null));
     }
     return(new System.ValueTuple <string, string, string, CookieContainer>("FAIL", "", "INVALID SMU ROLE", null));
 }
Ejemplo n.º 2
0
 private System.ValueTuple <string, string, string, CookieContainer> Authenticate(string user_id, string pwd)
 {
     if (this.role.Contains("NUS"))
     {
         HtmlWeb      auth_web = new HtmlWeb();
         HtmlDocument auth_doc = null;
         try
         {
             auth_doc = auth_web.Load("https://www-lawnet-sg.lawproxy1.nus.edu.sg/lawnet/group/lawnet/legal-research/basic-search");
         }
         catch (Exception)
         {
             System.ValueTuple <string, string, string, CookieContainer> result = new System.ValueTuple <string, string, string, CookieContainer>("FAIL", "", "INTERNET CONNECTION ERROR", null);
             return(result);
         }
         if (auth_doc.DocumentNode.SelectSingleNode("//div[@class='resourcesAccordion']") != null)
         {
             return(new System.ValueTuple <string, string, string, CookieContainer>("AUTHENTICATED", "", "ALREADY AUTHENTICATATED", null));
         }
         RestClient  arg_BE_0     = new RestClient("https://proxylogin.nus.edu.sg/lawproxy1/public/login_form.asp");
         RestRequest auth_request = new RestRequest(Method.POST);
         auth_request.AddParameter("domain", this.role);
         auth_request.AddParameter("user", user_id);
         auth_request.AddParameter("pass", pwd);
         auth_request.AddParameter("url", "http://www.lawnet.sg/lawnet/ip-access");
         IRestResponse auth_response = arg_BE_0.Execute(auth_request);
         HtmlDocument  expr_CA       = new HtmlDocument();
         expr_CA.LoadHtml(auth_response.Content);
         HtmlNode Response_check = expr_CA.DocumentNode.SelectSingleNode("//form[@action]");
         if (Response_check == null)
         {
             return(new System.ValueTuple <string, string, string, CookieContainer>("FAIL", "", "CREDENTIAL ERROR", null));
         }
         HtmlAttribute expr_113      = Response_check.Attributes["action"];
         RestClient    cookie_client = new RestClient((expr_113 != null) ? expr_113.Value : null)
         {
             CookieContainer = new CookieContainer()
         };
         RestRequest   cookie_request  = new RestRequest(Method.POST);
         IRestResponse cookie_response = cookie_client.Execute(cookie_request);
         if (cookie_response.ResponseUri.ToString() == "https://www-lawnet-sg.lawproxy1.nus.edu.sg/lawnet/group/lawnet/legal-research/basic-search")
         {
             return(new System.ValueTuple <string, string, string, CookieContainer>("SUCCESS", cookie_response.Cookies.First <RestResponseCookie>().Name, cookie_response.Cookies.First <RestResponseCookie>().Value, cookie_client.CookieContainer));
         }
         return(new System.ValueTuple <string, string, string, CookieContainer>("FAIL", "", "LAWNET UNDER MAINTENANCE", null));
     }
     return(new System.ValueTuple <string, string, string, CookieContainer>("FAIL", "", "INVALID NUS ROLE", null));
 }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Program   pg     = new Program();
            IntResult result = pg.ParseInteger("10");

            Console.WriteLine(result.Parsed);
            Console.WriteLine(result.Number);

            dynamic result2 = pg.ParseInteger2("20");

            Console.WriteLine(result2.Parsed);
            Console.WriteLine(result2.Number);

            Tuple <bool, int> result3 = pg.ParseInteger3("40");

            Console.WriteLine(result3.Item1);
            Console.WriteLine(result3.Item2);

            (bool, int)result4 = pg.ParseInteger4("50");
            Console.WriteLine(result4.Item1);
            Console.WriteLine(result4.Item2);

            (bool success, int n)result5 = pg.ParseInteger4("60");
            Console.WriteLine(result5.success);
            Console.WriteLine(result5.n);

            (var r1, var r2) = pg.ParseInteger4("60");
            Console.WriteLine(r1);
            Console.WriteLine(r2);

            (var _, var _) = pg.ParseInteger4("70");
            (var _, var n) = pg.ParseInteger4("70");
            Console.WriteLine(n);

            System.ValueTuple <bool, int> result6 = pg.ParseInteger4("80");
            Console.WriteLine(result6.Item1);
            Console.WriteLine(result6.Item2);

            var result7 = pg.ParseInteger5("90");

            Console.WriteLine(result7.Parsed);
            Console.WriteLine(result7.Number);


            {
                List <Person> people = new List <Person>
                {
                    new Person {
                        Name = "Tom", Age = 63, Address = "Korea"
                    },
                    new Person {
                        Name = "Winnie", Age = 40, Address = "Tibet"
                    },
                    new Person {
                        Name = "Anders", Age = 47, Address = "Sudan"
                    },
                    new Person {
                        Name = "Hans", Age = 25, Address = "Tibet"
                    },
                    new Person {
                        Name = "Eureka", Age = 32, Address = "Sudan"
                    },
                    new Person {
                        Name = "Hawk", Age = 15, Address = "Korea"
                    },
                };

                var dateList = from person in people
                               select(person.Name, DateTime.Now.AddYears(-person.Age).Year);

                foreach (var item in dateList)
                {
                    Console.WriteLine(string.Format("{0} - {1}", item.Item1, item.Item2));
                }

                var dateList2 = from person in people
                                select(Name : person.Name, Year : DateTime.Now.AddYears(-person.Age).Year);

                foreach (var item in dateList2)
                {
                    Console.WriteLine(string.Format("{0} - {1}", item.Name, item.Year));
                }
            }
        }
Ejemplo n.º 4
0
 public void Caller()
 {
     System.ValueTuple <string, string> name = this.GetName();
     Console.WriteLine(string.Format("{0} {1}", name.Item1, name.Item2));
 }
 public static System.Tuple <T1, T2, T3, T4, T5, T6, T7> ToTuple <T1, T2, T3, T4, T5, T6, T7>(this System.ValueTuple <T1, T2, T3, T4, T5, T6, T7> value)
 {
     throw null;
 }
 public static System.Tuple <T1, T2, T3, T4> ToTuple <T1, T2, T3, T4>(this System.ValueTuple <T1, T2, T3, T4> value)
 {
     throw null;
 }
 public static System.Tuple <T1> ToTuple <T1>(this System.ValueTuple <T1> value)
 {
     throw null;
 }
Ejemplo n.º 8
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.AuthButton.Content = "Authenticating...";
            this.AuthButton.Refresh();
            if (this.role == null)
            {
                MessageBox.Show("Error: ROLE NOT SELECTED");
                this.AuthButton.Content = "Authenticate";
                return;
            }
            if (this.Username.Text == "")
            {
                MessageBox.Show("Error: BLANK USERNAME");
                this.AuthButton.Content = "Authenticate";
                return;
            }
            if (this.Password.Password == "")
            {
                MessageBox.Show("Error: BLANK PASSWORD");
                this.AuthButton.Content = "Authenticate";
                return;
            }
            string user_id = this.Username.Text;
            string pwd     = this.Password.Password;
            Random RND     = new Random();

            System.ValueTuple <string, string, string, CookieContainer> expr_D1 = this.Authenticate(user_id, pwd);
            string          result  = expr_D1.Item1;
            string          value   = expr_D1.Item3;
            CookieContainer cookies = expr_D1.Item4;

            if (result == "FAIL")
            {
                MessageBox.Show("Error: " + value);
                this.AuthButton.Content = "Authenticate";
                return;
            }
            this.Lawnet_Cookies = cookies;
            string session_id = RND.Next(1, 999999999).ToString();

            MessageBox.Show(string.Concat(new string[]
            {
                "Success! Welcome ",
                this.Username.Text,
                "!\n\nCookie ID: ",
                value,
                "\nSession ID: ",
                session_id
            }));
            if (this.NUSRememberMeState())
            {
                Settings.Default.NUSUsername   = ExtensionMethods.Encrypt(this.Username.Text, "");
                Settings.Default.NUSPassword   = ExtensionMethods.Encrypt(this.Password.Password, "");
                Settings.Default.NUSRole       = this.role;
                Settings.Default.NUSRememberMe = true;
                Settings.Default.Save();
            }
            else
            {
                Settings.Default.NUSUsername   = "";
                Settings.Default.NUSPassword   = "";
                Settings.Default.NUSRole       = "";
                Settings.Default.NUSRememberMe = false;
                Settings.Default.Save();
            }
            base.NavigationService.Navigate(new NUSDownloader(this.Lawnet_Cookies, user_id, session_id));
        }