/// <summary> /// 登录事件 /// </summary> private void picLogin_Click(object sender, EventArgs e) { if (this.TxtUser.Text == "请输入用户名" || this.TxtKey.Text == "请输入密码" || this.TxtUser.Text == "" || this.TxtKey.Text == "")//判断是否为空 { PassValue.MessageInfor = "用户名和密码不能为空"; Messagebox mb = new Messagebox(); mb.ShowDialog(); this.TxtKey.Text = "请输入密码"; this.TxtUser.Text = ""; this.TxtUser.Focus(); } else { PassValue.username = this.TxtUser.Text; //用户名 PassValue.password = this.TxtKey.Text; //密码 string passvalue = PassValue.username + ":" + PassValue.password; WebHeaderCollection headers = new WebHeaderCollection(); headers.Add("Authorization", "Basic " + System.Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(passvalue))); headers.Add("Authed", "true"); LoginID li = null; HttpResult httpResult = httpReq.HttpPost("auth/tokens", null, headers); if ((int)httpResult.StatusCode == 0) { MessageBox.Show(string.Format("{0}{1}", httpResult.StatusDescription, httpResult.OtherDescription), "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } //else if ((int)httpResult.StatusCode == 403) //{ // if (MessageBox.Show("用户已在其他地方登陆 是否强制登陆?", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) == DialogResult.OK) // { // headers.Add("Authed", "true"); // httpResult = httpReq.HttpPost("auth/tokens", null, headers); // } // else // { // return; // } //} if ((int)httpResult.StatusCode >= 200 && (int)httpResult.StatusCode < 300) { li = httpReq.ScriptDeserialize <LoginID>(httpResult.Html); PassValue.token = "Token " + Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(li.id));//ID加密 PassValue.tokenid = li.id; PassValue.Code = li.principal.code; if (needRemPassword) { Global.GetConfig().SetConfigString("system", "LoginUserName", this.TxtUser.Text.Trim()); Global.GetConfig().SetConfigString("system", "LoginUserPSW", this.TxtKey.Text.Trim()); } //获取楼层信息 Layout floorLayout = httpReq.HttpGet <Layout>("layout"); if (floorLayout != null) { foreach (Floor floor in floorLayout.floors) { PassValue.tablesstatuslist.Add(floor.number); } PassValue.tablesstatuslist.Sort(); } //获取桌子信息 PassValue.Tables = httpReq.HttpGet <List <Table> >("tables"); //获取交接班需要的信息 Shift shift = new Shift(); shift.cashier = new Employee(); if (li != null) { shift.cashier.id = li.principal.id; } httpResult = httpReq.HttpPost("shifts", shift); if ((int)httpResult.StatusCode >= 200 && (int)httpResult.StatusCode < 300) { shift = httpReq.ScriptDeserialize <Shift>(httpResult.Html); PassValue.shiftId = shift.id; needHandOver = shift.isWarn; } else if ((int)httpResult.StatusCode == 0) { MessageBox.Show(string.Format("{0}{1}", httpResult.StatusDescription, httpResult.OtherDescription), "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } Main frmMain = new Main(this); frmMain.Show(); } else { MessageBox.Show("请输入正确的工号和密码!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); this.TxtKey.Text = ""; this.TxtUser.Text = ""; this.TxtUser.Focus(); } } }
private void Window_Loaded(object sender, RoutedEventArgs e) { LoginID.Focus(); }
private void SaveLoginPassword(string username, string password) { if (!string.IsNullOrEmpty(_loginId)) { PlayerPrefs.SetString(XsollaConstants.Prefs_UserLogin, username); PlayerPrefs.SetString(XsollaConstants.Prefs_UserPassword, Crypto.Encrypt(Encoding.ASCII.GetBytes(LoginID.Replace("-", string.Empty).Substring(0, 16)), password)); } }