public MainWindow() { InitializeComponent(); OptionClass.Get().ReadFromConfig(); reference = this; setContent(LoginPage.Get()); }
/// <summary> /// 代为向服务器发起一次从属关系查询。 /// </summary> /// <param name="type"></param> /// <param name="id"></param> /// <returns></returns> public BelongRelation BelongQuery(string type, string id) { var param = new Dictionary <string, string>() { { "type", type }, { "id", id } }; HttpConnect con = new HttpConnect(OptionClass.Get().GetURL("action/belong"), "GET", param: param); con.authentication = authentication; con.Connect(); if (con.status == HttpStatusCode.OK) { JObject jo = JObject.Parse(con.response); if (jo["relation"] != null) { var relation = jo["relation"].ToString(); switch (relation) { case "other": return(BelongRelation.Other); case "self": return(BelongRelation.Self); case "sub": return(BelongRelation.Sub); case "parent": return(BelongRelation.Parent); case "manager": return(BelongRelation.Manager); default: return(BelongRelation.None); } } } return(BelongRelation.None); }
public override void NavigatedToEvent(object sender, IDictionary <string, object> kwargs) { base.NavigatedToEvent(sender, kwargs); option = OptionClass.Get(); RPW.IsChecked = option.RememberPasswd; AL.IsChecked = option.AutoLogin; ServerIP.Text = option.ServerURL; }
/// <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); } }); }); }
public LoginPage() { InitializeComponent(); CheckConnection(); Server.Submit += (s, e) => { OptionClass.Get().ServerURL = e.text; OptionClass.Get().WriteToConfig(); return(e.text); }; RememberPasswd.IsChecked = OptionClass.Get().RememberPasswd; AutoLogin.IsChecked = OptionClass.Get().AutoLogin; UsernameTxt.Text = OptionClass.Get().Username; if (OptionClass.Get().RememberPasswd) { PasswordTxt.Password = OptionClass.Get().Password; } if (OptionClass.Get().AutoLogin) { DoLogin(); } }
public override void NavigatedToEvent(object sender, IDictionary <string, object> kwargs) { HttpConnect con = new HttpConnect(OptionClass.Get().GetURL("action/schedule"), "GET"); con.Connect(); if (con.status == System.Net.HttpStatusCode.OK) { var response = con.response; JObject data = JObject.Parse(response); TimeRange.Text = string.Format("执行时间:{0} - {1}", data["begin"].ToString(), data["end"].ToString()); JArray items = data["items"] as JArray; foreach (var i in items) { Tuple <int, string, string> itemdata = new Tuple <int, string, string>(int.Parse(i["no"].ToString()), i["begin"].ToString(), i["end"].ToString()); var ctrl = new schedule_timeitem(); ctrl.Height = 60; ctrl.content = itemdata; TimeList.Children.Add(ctrl); } } }
/// <summary> /// 更新权限信息。如果无法连接无服务器,则会返回异常状态码。 /// </summary> /// <returns></returns> public HttpStatusCode UpdateAuthority() { HttpConnect con = new HttpConnect(OptionClass.Get().GetURL("action/self-authority"), "GET"); con.authentication = authentication; con.Connect(); if (con.status == HttpStatusCode.OK) { authority.Clear(); JObject jo = JObject.Parse(con.response); if (jo["auth"] != null) { var authnumber = long.Parse((jo["auth"] as JValue).Value.ToString()); foreach (var i in AuthorityItem.getAuthorityArray(authnumber)) { authority.Add(i); } } } return(con.status); }
public static void SetApiConfig(Auth authentication) { api = new RestApi(OptionClass.Get().ServerURL, authentication.username, authentication.password); }