/// <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); } }); }); }
/// <summary> /// 检执行UI操作,查对服务器的链接。 /// </summary> public void CheckConnection() { SetContent(ContentStatus.Connecting); Task.Run(() => { OptionClass option = OptionClass.Get(); HttpConnect con = new HttpConnect(option.GetURL(""), "GET"); con.Connect(); var code = con.status; Content.Dispatcher.Invoke(() => { if (code == HttpStatusCode.OK) { SetContent(ContentStatus.Login); } else { SetContent(ContentStatus.Disconnect); } }); }); }