void channel_BeforeLogin(object sender, BeforeLoginEventArgs e) { if (e.FirstTry == true && string.IsNullOrEmpty(this.SupervisorUserName) == false) { e.UserName = this.SupervisorUserName; e.Password = this.SupervisorPassword; e.Parameters = "location=#setup,type=worker,client=dp2CapoInstall|0.01"; // 2016/5/6 加上 0.01 部分 if (String.IsNullOrEmpty(e.UserName) == false) { return; // 立即返回, 以便作第一次 不出现 对话框的自动登录 } } // IWin32Window owner = null; if (sender is IWin32Window) { owner = (IWin32Window)sender; } else { owner = this; } ConfirmSupervisorDialog dlg = new ConfirmSupervisorDialog(); FontUtil.AutoSetDefaultFont(dlg); // dlg.Text = ""; dlg.ServerUrl = this.comboBox_url.Text; dlg.Comment = e.ErrorInfo; dlg.UserName = e.UserName; dlg.Password = e.Password; dlg.StartPosition = FormStartPosition.CenterScreen; dlg.ShowDialog(owner); if (dlg.DialogResult == DialogResult.Cancel) { e.Cancel = true; return; } e.UserName = dlg.UserName; e.Password = dlg.Password; e.SavePasswordShort = true; e.Parameters = "location=#setup,type=worker,client=dp2CapoInstall|0.01"; e.SavePasswordLong = true; e.LibraryServerUrl = dlg.ServerUrl; this.SupervisorUserName = e.UserName; this.SupervisorPassword = e.Password; }
private void button_editMasterServer_Click(object sender, EventArgs e) { ConfirmSupervisorDialog dlg = new ConfirmSupervisorDialog(); GuiUtil.AutoSetDefaultFont(dlg); dlg.Text = "主服务器"; dlg.Comment = "请设置主服务器的地址和用户名"; dlg.ServerUrl = this.m_strUrl; dlg.UserName = this.m_strUserName; dlg.Password = this.m_strPassword; dlg.PhoneNumberVisible = false; dlg.ServerUrlReadOnly = false; dlg.StartPosition = FormStartPosition.CenterScreen; REDO_INPUT: dlg.ShowDialog(this); if (dlg.DialogResult == DialogResult.Cancel) { return; } if (string.IsNullOrEmpty(dlg.ServerUrl)) { MessageBox.Show(this, "尚未输入服务器 URL"); goto REDO_INPUT; } if (string.IsNullOrEmpty(dlg.UserName)) { MessageBox.Show(this, "尚未输入用户名"); goto REDO_INPUT; } if (dlg.ServerUrl != this.m_strUrl || dlg.UserName != this.m_strUserName || dlg.Password != this.m_strPassword) { this.m_strUrl = dlg.ServerUrl; this.m_strUserName = dlg.UserName; this.m_strPassword = dlg.Password; RefreshMasterServerSummary(); this.Changed = true; } }
// 用 supervisor 用户名进行登录 void _channels_LoginSupervisor(object sender, LoginEventArgs e) { MessageConnection connection = sender as MessageConnection; if (string.IsNullOrEmpty(this.ManagerUserName) == false) { e.UserName = this.ManagerUserName; e.Password = this.ManagerPassword; e.Parameters = "propertyList=biblio_search,libraryUID=install"; return; } ConfirmSupervisorDialog dlg = new ConfirmSupervisorDialog(); FontUtil.AutoSetDefaultFont(dlg); // dlg.Text = ""; dlg.ServerUrl = this.textBox_url.Text; dlg.Comment = "为在 dp2mserver 服务器上创建图书馆账户,请使用超级用户登录"; dlg.UserName = e.UserName; dlg.Password = e.Password; dlg.StartPosition = FormStartPosition.CenterScreen; dlg.ShowDialog(this); if (dlg.DialogResult == DialogResult.Cancel) { e.ErrorInfo = "放弃登录"; return; } e.UserName = dlg.UserName; if (string.IsNullOrEmpty(e.UserName) == true) { throw new Exception("尚未指定用户名,无法进行登录"); } e.Password = dlg.Password; e.Parameters = "propertyList=biblio_search,libraryUID=install"; }
// 为确认身份而登录 // return: // -1 出错 // 0 放弃登录 // 1 登录成功 internal int ConfirmLogin(out string strError) { strError = ""; ConfirmSupervisorDialog login_dlg = new ConfirmSupervisorDialog(); MainForm.SetControlFont(login_dlg, this.MainForm.DefaultFont); login_dlg.UserName = this.MainForm.AppInfo.GetString( "default_account", "username", ""); login_dlg.ServerUrl = this.MainForm.LibraryServerUrl; login_dlg.Comment = "重要操作前,需要验证您的身份"; login_dlg.StartPosition = FormStartPosition.CenterScreen; login_dlg.ShowDialog(this); if (login_dlg.DialogResult != DialogResult.OK) return 0; string strLocation = this.MainForm.AppInfo.GetString( "default_account", "location", ""); string strParameters = "location=" + strLocation + ",type=worker"; // return: // -1 error // 0 登录未成功 // 1 登录成功 long lRet = this.Channel.Login(login_dlg.UserName, login_dlg.Password, strParameters, out strError); if (lRet == -1) return -1; if (lRet == 0) { // strError = ""; return -1; } return 1; }
// 要求操作者用 supervisor 账号登录一次。以便后续进行各种重要操作。 // 只需要 library.xml 即可,不需要 dp2library 在运行中。 // return: // -2 实例没有找到 // -1 出错 // 0 放弃验证 // 1 成功 public static int LibrarySupervisorLogin(IWin32Window owner, string strInstanceName, string strComment, out string strError) { strError = ""; LibraryInstanceInfo info = null; // return: // -1 出错 // 0 实例没有找到 // 1 成功 int nRet = GetLibraryInstanceInfo( strInstanceName, out info, out strError); if (nRet == -1) { return -1; } if (nRet == 0) { strError = "实例 '" + strInstanceName + "' 没有找到"; return -2; } if (string.IsNullOrEmpty(info.SupervisorUserName) == true) { // TODO: 此时是否可以不用验证了呢? strError = "实例 '" + strInstanceName + "' 的账户中,没有找到具有 managedatabase 权限的管理员账户,因此无法验证操作者身份"; return -1; } ConfirmSupervisorDialog dlg = new ConfirmSupervisorDialog(); GuiUtil.AutoSetDefaultFont(dlg); dlg.Comment = strComment; dlg.ServerUrl = "实例 '" + strInstanceName + "'"; dlg.UserName = info.SupervisorUserName; dlg.StartPosition = FormStartPosition.CenterScreen; REDO_LOGIN: dlg.ShowDialog(owner); if (dlg.DialogResult == DialogResult.Cancel) return 0; if (info.Version <= 2.0) { // 以前的做法 if (dlg.Password != info.SupervisorPassword) { MessageBox.Show(owner, "密码不正确。请重新输入密码"); goto REDO_LOGIN; } } else { // 新的做法 nRet = LibraryServerUtil.MatchUserPassword(dlg.Password, info.SupervisorPassword, out strError); if (nRet == -1) { strError = "MatchUserPassword() error: " + strError; return -1; } Debug.Assert(nRet == 0 || nRet == 1, ""); if (nRet == 1) { MessageBox.Show(owner, "密码不正确。请重新输入密码"); goto REDO_LOGIN; } } return 1; }
// 要求操作者用 supervisor 账号登录一次。以便后续进行各种重要操作。 // 只需要 library.xml 即可,不需要 dp2library 在运行中。 // return: // -2 实例没有找到 // -1 出错 // 0 放弃验证 // 1 成功 public static int LibrarySupervisorLogin(IWin32Window owner, string strInstanceName, string strComment, out string strError) { strError = ""; LibraryInstanceInfo info = null; // return: // -1 出错 // 0 实例没有找到 // 1 成功 int nRet = GetLibraryInstanceInfo( strInstanceName, out info, out strError); if (nRet == -1) { return(-1); } if (nRet == 0) { strError = "实例 '" + strInstanceName + "' 没有找到"; return(-2); } if (string.IsNullOrEmpty(info.SupervisorUserName) == true) { // TODO: 此时是否可以不用验证了呢? strError = "实例 '" + strInstanceName + "' 的账户中,没有找到具有 managedatabase 权限的管理员账户,因此无法验证操作者身份"; return(-1); } ConfirmSupervisorDialog dlg = new ConfirmSupervisorDialog(); GuiUtil.AutoSetDefaultFont(dlg); dlg.Comment = strComment; dlg.ServerUrl = "实例 '" + strInstanceName + "'"; dlg.UserName = info.SupervisorUserName; dlg.StartPosition = FormStartPosition.CenterScreen; REDO_LOGIN: dlg.ShowDialog(owner); if (dlg.DialogResult == DialogResult.Cancel) { return(0); } if (info.Version <= 2.0) { // 以前的做法 if (dlg.Password != info.SupervisorPassword) { MessageBox.Show(owner, "密码不正确。请重新输入密码"); goto REDO_LOGIN; } } else { // 新的做法 nRet = LibraryServerUtil.MatchUserPassword(dlg.Password, info.SupervisorPassword, out strError); if (nRet == -1) { strError = "MatchUserPassword() error: " + strError; return(-1); } Debug.Assert(nRet == 0 || nRet == 1, ""); if (nRet == 1) { MessageBox.Show(owner, "密码不正确。请重新输入密码"); goto REDO_LOGIN; } } return(1); }