Ejemplo n.º 1
0
        public async Task <bool> Register(string username, string password)
        {
            try
            {
                HttpEngine httpRequest = new HttpEngine();
                string     result      = await httpRequest.PostAsync("http://api.sellmoe.com/reg?hash=" + new Random().Next(), "u=" + username + "&p=" + password);

                JObject json = JObject.Parse(result);
                ErrorProcessor(json);
                key = (string)json["data"]["key"];
                return(true);
            }
            catch
            {
                throw;
            }
        }
Ejemplo n.º 2
0
        //登陆,成功后初始化session
        public static async Task <bool> Login(string name, string password)
        {
            JObject staff = new JObject();

            staff.Add(new JProperty("action", "login"));
            staff.Add(new JProperty("username", Uri.EscapeDataString(name)));
            staff.Add(new JProperty("password", password));
            string LoginContext = staff.ToString();

            Stream response = await _httphelper.PostAsync(BuSetting.URL + "bu_logging.php", LoginContext);

            if (response == null || response.Length == 0)
            {
                return(false);
            }

            StreamReader reader  = new StreamReader(response);
            string       strret  = reader.ReadToEnd();
            JObject      jsonobj = JObject.Parse(strret);

            if (jsonobj["result"].ToString() != "success")
            {
                MessageBox.Show("用户名或密码错误,请重新输入");
                return(false);
            }


            _session = jsonobj["session"].ToString();
            if (_session == null)
            {
                return(false);
            }

            //保存账户名及密码,用于登出
            _name     = name;
            _password = password;

            return(true);
        }