예제 #1
0
        /// <summary>
        /// 执行登录函数
        /// </summary>
        private void load()
        {
            login_class.type = "2";                    //打印店的type为2
            List <string> myRem = new List <string>(); //此处可以进行修改和简化

            if (printerAcount.Text.Length == 0 || password.Text.Length == 0)
            {
                if (error.InvokeRequired)
                {
                    my1 = new boxDelegate(boxChange);
                    error.Invoke(my1, new object[] { error, "请输入您的个人信息", true, true });
                    loginbutton.Invoke(my1, new object[] { loginbutton, "登录", true, true });
                    Thread.Sleep(100);
                }
                else
                {
                    error.Text          = "请输入您的个人信息";
                    error.Visible       = true;
                    loginbutton.Enabled = true;
                }
            }
            else
            {
                IAsyncResult result = login_class.login_del.BeginInvoke(printerAcount.Text, password.Text, null, null);
                string       r      = login_class.login_del.EndInvoke(result);
                login_to_show(r);
            }
        }
예제 #2
0
        public void login_to_show(string r)
        {
            List <string> myRem = new List <string>();

            if (r.Contains("sid"))
            {
                JObject toke = JObject.Parse(r);
                location_settings.my.sid    = (string)toke["info"]["sid"];//也能够得到token
                location_settings.my.name   = (string)toke["info"]["printer"]["name"];
                location_settings.my.id     = (string)toke["info"]["printer"]["id"];
                location_settings.my.sch_id = (string)toke["info"]["printer"]["sch_id"];
                API.sid = location_settings.my.sid;
                //判断是否保存用户名
                if (checkbox.Checked)
                {
                    myRem.Add(login_class.password_save);
                    myRem.Add(printerAcount.Text);
                }
                File.WriteAllText(@"pwd.sjc", "");
                remember.WriteListToTextFile(myRem, @"pwd.sjc");
                showdownload();        //传递参数,显示下载控件
                timer_init();
            }
            else
            {
                //登录失败

                if (error.InvokeRequired)
                {
                    my1 = new boxDelegate(boxChange);
                    error.Invoke(my1, new object[] { error, "登陆失败,请重新登录!", true, true });
                    loginbutton.Invoke(my1, new object[] { loginbutton, "登录", true, true });
                    Thread.Sleep(100);
                }
                else
                {
                    error.Text          = "登陆失败,请重新登录!";
                    error.Visible       = true;
                    loginbutton.Enabled = true;
                }
            }
        }
예제 #3
0
파일: Form1.cs 프로젝트: 312223105/printer
        /// <summary>
        /// 执行登录函数
        /// </summary>
        private void load()
        {
            string type = "2";        //打印店的type为2
            List<string> myRem = new List<string>();       //此处可以进行修改和简化
            string strusername = printerAcount.Text;            //用户名
            string strpassword = password.Text;            //密码
            if (myLogin.Count == 2)
            {
                if (myLogin[0].Length != strpassword.Length)
                {
                    byte[] pword = Encoding.Default.GetBytes(strpassword.Trim());       //进行MD5的加密工作
                    System.Security.Cryptography.MD5 md5 = new MD5CryptoServiceProvider();
                    byte[] out1 = md5.ComputeHash(pword);
                    strpassword = BitConverter.ToString(out1).Replace("-", "");
                }
            }
            else
            {
                byte[] pword = Encoding.Default.GetBytes(strpassword.Trim());       //进行MD5的加密工作
                System.Security.Cryptography.MD5 md5 = new MD5CryptoServiceProvider();
                byte[] out1 = md5.ComputeHash(pword);
                strpassword = BitConverter.ToString(out1).Replace("-", "");
            }
            if (strusername.Length == 0 || strpassword.Length == 0)
            {
                if (error.InvokeRequired)
                {
                    my1 = new boxDelegate(boxChange);
                    error.Invoke(my1, new object[]
                        {error,"请输入您的个人信息",true,true
                        });
                    loginbutton.Invoke(my1, new object[] { loginbutton, "登录", true, true });
                    Thread.Sleep(100);
                }
                else  //这里并没有看出有什么区别
                {
                    error.Text = "请输入您的个人信息";
                    error.Visible = true;
                    loginbutton.Enabled = true;
                }
            }
            else
            {
                //获取token
                strpassword = strpassword.ToLower();
                string js = "type=" + type + "&account=" + strusername +
                "&pwd=" + strpassword;

                //POST得到要数据//登陆得到token
                string r = API.PostMethod("/Token", js, new UTF8Encoding());
                //从post得到的数据中得到token
                Console.WriteLine(r);
                JObject toke = JObject.Parse(r);
                ToMyToken my = new ToMyToken();
                bool loginOk = r.Contains("token");
                if (loginOk == true)
                {
                    my.token = (string)toke["token"];//也能够得到token
                    my.name = (string)toke["name"];
                    my.id = (string)toke["id"];
                    my.version = (float)toke["version"];
                    //判断是否保存用户名
                    if (checkbox.Checked)
                    {
                        myRem.Add(strpassword);
                        //myRem.Add(password.Text);
                        myRem.Add(printerAcount.Text);

                    }
                    File.WriteAllText(@"pwd.sjc", "");
                    remember.WriteListToTextFile(myRem, @"pwd.sjc");
                    Console.WriteLine(my.token);
                    Console.WriteLine(my.name);
                    Console.WriteLine(my.id);
                    showdownload(my);        //传递参数,显示下载控件
                    autorefresh.Enabled = true;   //登录成功后启动计时器
                }
                else
                {
                    //登录失败
                    my1 = new boxDelegate(boxChange);
                    if (error.InvokeRequired)
                    {
                        my1 = new boxDelegate(boxChange);
                        error.Invoke(my1, new object[] { error, "登陆失败,请重新登录!", true, true });
                        loginbutton.Invoke(my1, new object[] { loginbutton, "登录", true, true });
                        Thread.Sleep(100);
                    }
                    else
                    {
                        error.Text = "登陆失败,请重新登录!";
                        error.Visible = true;
                        loginbutton.Enabled = true;
                    }
                }
            }
        }