private void checkuserright() { try { this.Cursor = Cursors.WaitCursor; btnOk.Enabled = false; this.Update(); //必须 string userID = edtUserID.Text; string password = CEncoder.GenerateMD5Hash(edtPwd.Text); /*常规加密*/ string loginReturn = RestClient.Login(userID, password, loginType); if (loginReturn == "0") //调用登录策略 { this.SaveLoginInfo(); //跟据选项保存登录信息 this.DialogResult = DialogResult.OK; //成功 this.Close(); } else { Warning(Globals.UserInfo.msg); btnOk.Enabled = true; edtPwd.Focus(); edtPwd.SelectAll(); } } catch { btnOk.Enabled = true; Warning("验证错误,请检查网络!"); edtPwd.Focus(); edtPwd.SelectAll(); } this.Cursor = Cursors.Default; }
public Tuple <string, string> Login(string userName, string password, EnumRightType rightType) { string addr = "http://" + RestClient.server + "/" + RestClient.apiPath + "/padinterface/login.json"; var encodePwd = CEncoder.GenerateMD5Hash(password); var request = new AuthorizeLoginRequest(userName, encodePwd, GetRightCode(rightType)); try { var result = HttpHelper.HttpPost <AuthorizeLoginResponse>(addr, request); return(result.IsSuccess ? new Tuple <string, string>(null, result.fullname) : new Tuple <string, string>(result.msg, null)); } catch (Exception ex) { //AllLog.Instance.E(ex); return(new Tuple <string, string>(ex.Message, null)); } }
private void btnLogin_Click(object sender, EventArgs e) { if (focusedt.Text.Trim().ToString().Equals("")) { focusedt.Focus(); return; } else if (txtPwd.Text.Trim().ToString().Length <= 0) { txtPwd.Focus(); txtPwd.SelectAll(); focusedt = txtPwd; return; } try { this.Cursor = Cursors.WaitCursor; this.SetButtonEnable(false); this.Update();//必须 this.ShowLoginInfo("正在验证用户名及密码"); string userID = txtUser.Text; string password = CEncoder.GenerateMD5Hash(txtPwd.Text); /*常规加密*/ //string dataSetID = txtDataset.EditValue.ToString();//帐套编号 string dataSetDB = "user"; // GetDataSetDBName(); //LoginUser loginUser = new LoginUser(userID, password, dataSetID, dataSetDB); string loginReturn = RestClient.Login(userID, password, ((int)EnumRightType.Login).ToString()); if (loginReturn == "0") //调用登录策略 { //Msg.ShowError(loginReturn); if (chkSaveLoginInfo.Checked) { this.SaveLoginInfo(); //跟据选项保存登录信息 } Program.MainForm = new frmAllTable(); //登录成功创建主窗体 //登录成功,获取权限 getUserRigth(); if (!Globals.userRight.right6) { getUserRigth(); } this.DialogResult = DialogResult.OK; //成功 this.Close(); //关闭登陆窗体 } else if (loginReturn == "") { this.ShowLoginInfo("登录失败,请检查网络和后台服务!"); Warning("登录失败,请检查网络和后台服务!"); this.SetButtonEnable(true); txtPwd.Focus(); txtPwd.SelectAll(); } else { this.ShowLoginInfo(Globals.UserInfo.msg); //"登录失败,请检查用户名和密码!" Warning(Globals.UserInfo.msg); //"登录失败,请检查用户名和密码!" this.SetButtonEnable(true); txtPwd.Focus(); txtPwd.SelectAll(); } } catch (CustomException ex) { this.SetButtonEnable(true); this.ShowLoginInfo(ex.Message); Warning(ex.Message); txtPwd.Focus(); txtPwd.SelectAll(); } catch (Exception ex) { this.SetButtonEnable(true); this.ShowLoginInfo("登录失败,请检查用户名和密码!" + ex.Message); Warning("登录失败,请检查用户名和密码!"); txtPwd.Focus(); txtPwd.SelectAll(); } this.Cursor = Cursors.Default; }