private void button3_Click_1(object sender, EventArgs e)
 {
     dashboard d = new dashboard();
     d.Show();
     this.Hide();
 }
 private void button3_Click(object sender, EventArgs e)
 {
     dashboard f3 = new dashboard();
     f3.Show();
     this.Hide();
 }
Beispiel #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                CookieContainer httpWeb = new CookieContainer();

                var httpWebRequest = (HttpWebRequest)WebRequest.Create(GlobalClass.url + "/user_login/");
                httpWebRequest.ContentType = "text/json";
                httpWebRequest.Method = "POST";
                httpWebRequest.CookieContainer = new CookieContainer();
                httpWebRequest.CookieContainer.Add(new Uri(GlobalClass.url+"/user_login/"),new Cookie("sessionid",""));
            
                //.Set(HttpRequestHeader.Cookie.Equals =
                //httpWebRequest = "{\"COOKIES\":\"{\"sessionid\":\"}";
                //httpWebRequest.CookieContainer.Add(new Cookie("COOKIES", "hello"));

                //Uri target = new Uri("http://192.168.1.107:8080/user_login/");

                //httpWeb.Add(new Cookie("HTTP_COOKIE", "{\"sessionid\"=") { Domain = target.Host });


                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    string json = "{\"username\":\"" + log_user.Text + "\"," +
                                   "\"password\":\"" + log_pass.Text + "\"}";
                    streamWriter.Write(json);
                    streamWriter.Flush();
                    streamWriter.Close();
                }
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    var result = streamReader.ReadToEnd();
                    //MessageBox.Show(result);
                    var sesion = httpResponse.Headers.Get("Set-Cookie");
                    //MessageBox.Show(sesion);

                    GlobalClass.session= sesion.Substring(sesion.IndexOf('=')+1, sesion.IndexOf(';')-sesion.IndexOf('=')-1);
                    //MessageBox.Show(GlobalClass.session);
                    JToken response = JToken.Parse(result);
                    //JToken jt= response["status"];
                    //JToken session = response["session"];
                    //MessageBox.Show(Convert.ToString(jt));
                    if (Convert.ToString(response["status"]).Contains("False"))
                    {
                        MessageBox.Show("Invalid Login! Please try again.", "Login Error!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
                        log_user.Clear();
                        log_pass.Clear();
                        log_user.Focus();
                        return;
                    }
                    else
                    {
                        //login l = new login();
                        dashboard f3 = new dashboard();
                        f3.Show();
                        this.Hide();
                    }
                }

            }
            catch
            {
                MessageBox.Show("Unable to connect to Server");         
            }
            
        }