Esempio n. 1
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                var            username = txtUserName.Text.Trim();
                var            password = txtPassword.Text.Trim(); // ApplicationLibary.Base64Decode("");
                OpenFileDialog open     = new OpenFileDialog();
                if (DialogResult.OK == open.ShowDialog())
                {
                    string  dataFile   = File.ReadAllText(open.FileName);
                    var     encodeData = ApplicationLibary.Base64Decode(dataFile);
                    JObject jObj       = JObject.Parse(encodeData);

                    var data   = jObj["data"].ToString();
                    var offset = jObj["offset"].ToString();

                    var dataLogin   = data.Remove(0, int.Parse(offset));
                    var afterDecode = ApplicationLibary.Base64Decode(dataLogin);

                    JObject jObjLogin = JObject.Parse(afterDecode);
                    username = jObjLogin["username"].ToString();
                    password = jObjLogin["password"].ToString();
                }
                if (username != "" && password != "")
                {
                    execLogin(username, password);
                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Message");
            }
        }
 private void btnIsActive_Click(object sender, EventArgs e)
 {
     //a2V5IG1hIGhvYSBwaGFuIG1lbSB0ZWVjaGlwIHBybw==
     if (txtKey.Text.Trim() == "a2V5IG1hIGhvYSBwaGFuIG1lbSB0ZWVjaGlwIHBybw")
     {
         ApplicationLibary.setActive(true);
         Application.Restart();
     }
     else
     {
         XtraMessageBox.Show("Something's wrong. Please try again!");
     }
 }
Esempio n. 3
0
        private void execLogin(string username, string password)
        {
            frmWait frm = new frmWait();

            frm.SetCaption("Login");
            frm.SetDescription("Connecting...");
            var    urlLogin  = "******";
            var    data2Send = "{\"email\":\"" + username + "\",\"password\":\"" + password + "\"}";
            Thread t         = new Thread(new ThreadStart(() =>
            {
                try
                {
                    var data1 = login(urlLogin, data2Send);
                    var rs    = data1["data"].ToString();
                    if (int.Parse(data1["status"].ToString()) == -1)
                    {
                        var data2Send2 = "{\"email\":\"" + username + "\",\"password\":\"" + ApplicationLibary.Base64Decode(password) + "\"}";
                        var data2      = login(urlLogin, data2Send2);
                        if (int.Parse(data2["status"].ToString()) == -1)
                        {
                            frm.Invoke((MethodInvoker) delegate { frm.Close(); });
                            XtraMessageBox.Show("Sai thông tin tài khoản hoặc mật khẩu\n" + data2["data"], "Thông báo");
                            return;
                        }
                        rs = data2["data"].ToString();
                    }
                    User        = new ApplicationUser();
                    var obj     = JObject.Parse(rs);
                    User.UserID = obj["_id"].ToString();
                    User.Email  = obj["email"].ToString();
                    //User.Code = obj["referralCode"].ToString();
                    User.ApiKey = obj["apiKey"].ToString();
                    //User.ViewOnlyApiKey = obj["viewOnlyApiKey"].ToString();
                    User.GroupID  = obj["groupId"].ToString();
                    User.EntityID = obj["entities"][0]["entityId"].ToString();
                    //User.PayableId = obj["payable"]["payableId"].ToString();
                    User.Authorization   = "Basic " + ApplicationLibary.Base64Encode(":" + User.ApiKey);
                    User.UnAuthorization = "Basic " + ApplicationLibary.Base64Encode("undefined:" + User.ApiKey);
                    User.HasPassword     = ApplicationLibary.Base64Encode(password);


                    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> step2Login = PostDataAPI(logU, data2SendLog);

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

            t.Start();
            frm.ShowDialog();
        }