/// <summary>
        /// 登陆指令。
        /// </summary>
        public void DoLogin()
        {
            SetLoginOperate(true);
            var username = UsernameTxt.Text;
            var password = PasswordTxt.Password;

            Task.Run(() => {
                OptionClass option = OptionClass.Get();
                JObject loginjson  = new JObject();
                loginjson.Add("username", new JValue(username));
                loginjson.Add("password", new JValue(password));
                HttpConnect con = new HttpConnect(option.GetURL(""), "POST", username: username, password: password, data: loginjson.ToString());
                con.Connect();
                var code = con.status;
                Content.Dispatcher.Invoke(() => {
                    if (code == HttpStatusCode.OK)
                    {
                        //登陆成功
                        //需要将相关信息写入option。
                        //仅在登陆成功时写入记住密码/自动登录/用户名/密码。
                        option.Username       = username;
                        option.RememberPasswd = RememberPasswd.IsChecked ?? false;
                        if (option.RememberPasswd)
                        {
                            option.AutoLogin = AutoLogin.IsChecked ?? false;
                            option.Password  = password;
                        }
                        option.WriteToConfig();
                        User user           = User.Get();
                        user.authentication = new Auth(con.authentication.username, con.authentication.password);
                        NavigateToMain();
                    }
                    else if (code == HttpStatusCode.Unauthorized)
                    {
                        SetNotice("非法账户或者错误的登录信息");
                        SetLoginOperate(false);
                    }
                    else
                    {
                        SetNotice(con.response);
                        SetLoginOperate(false);
                    }
                });
            });
        }
Beispiel #2
0
 private void RPW_Checked(object sender, RoutedEventArgs e)
 {
     option.RememberPasswd = RPW.IsChecked ?? false;
     option.WriteToConfig();
 }