Example #1
0
        public static OnlineMessage connect(String username, String password)
        {
            String postData = "username="******"&password="******"POST";
            request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";

            try
            {
                Stream       requestStream = request.GetRequestStream();
                StreamWriter streamWriter  = new StreamWriter(requestStream, Encoding.ASCII);
                streamWriter.Write(postData);
                streamWriter.Close();

                HttpWebResponse            response       = (HttpWebResponse)request.GetResponse();
                Stream                     responseStream = response.GetResponseStream();
                DataContractJsonSerializer serializer     = new DataContractJsonSerializer(typeof(ReturnMessage));
                ReturnMessage              returnMessage  = (ReturnMessage)serializer.ReadObject(responseStream);
                responseStream.Close();

                switch (returnMessage.reply_code)
                {
                case LOGIN_SUCCESS:
                case ALREADY_LOGGED_IN:
                    return(OnlineState.getOnlineStateStrict());

                case INVALID_PASSWORD:
                    OnlineMessage onlineMessage = new OnlineMessage();
                    onlineMessage.reply_code = returnMessage.reply_code;
                    onlineMessage.reply_msg  = returnMessage.reply_msg;
                    onlineMessage.userinfo   = null;
                    return(onlineMessage);

                case PROCESSING:
                default:
                    return(null);
                }
            }
            catch
            {
                return(null);
            }
        }
Example #2
0
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            saveOptions();

            if (textBoxUsername.Text.Equals("") || textBoxPassword.Text.Equals(""))
            {
                MessageBox.Show("用户名和密码不能为空!", "Auto p.nju", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (checkBoxAutoLogin.Checked)
            {
                saveUsernameAndPassword();
            }
            else
            {
                clearUsernameAndPassword();
            }
            OnlineMessage ret = null;

            do
            {
                ret = AutoConnect.connect(textBoxUsername.Text, textBoxPassword.Text);
            } while (ret == null);

            if (ret.reply_code == AutoConnect.INVALID_PASSWORD)
            {
                timer.Enabled = false;
                MessageBox.Show(ret.reply_msg, "Oops", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            //else if(ret.reply_code==AutoConnect.PROCESSING)
            //{
            //    timer.Enabled = false;
            //    MessageBox.Show(ret.reply_msg, "Oops", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //}
            else
            {
                Thread.Sleep(1000);
                GlobalFunction.showInfo(OnlineState.getOnlineStateStrict(), this);
            }
        }