/// <summary> /// /// </summary> /// <param name="s"></param> /// <param name="stu"></param> /// <param name="end"></param> private void VerifyLoginEndHandler(StartLogin s,StudentEx stu,EndLogin end) { if (s != null && end != null) { STU_Login_Cache[s.UserAccount] = null; this.RaiseChanged(string.Format("学生机IP:({0})[{1}],{2:HH-mm-ss} 登录{3}!{4}", s.MachineName, s.UIP, s.Time, end.Result ? "成功" : "失败", end.Error)); if (end.Result && (stu != null)) { end.Student = new Student(stu.StudentID, stu.StudentCode, stu.StudentName); stu.MachineName = s.MachineName; stu.IP = s.UIP; if ((stu.Status & StudentControl.EnumStudentState.Offline) == StudentControl.EnumStudentState.Offline) { stu.Status &= ~StudentControl.EnumStudentState.Offline; } stu.Status |= StudentControl.EnumStudentState.Online; } this.SendOrderToClient(end, s.UIP); if (end.Result) { this.OnUpdateControls(stu); } } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnLogin_Click(object sender, EventArgs e) { try { string strUsername = null, strPassword = null; #region 验证。 this.OnClearErrorEvent(); if (this.loginMethod == EnumLoginMethod.UnifiedLogin) { strUsername = this.txtUsername.Text.Trim(); strPassword = this.txtPassword.Text.Trim(); } else if (this.loginMethod == EnumLoginMethod.Password) { strUsername = this.txtUsername.SelectedValue.ToString(); strPassword = this.txtPassword.Text.Trim(); } else { strUsername = this.txtUsername.SelectedValue.ToString(); } if (string.IsNullOrEmpty(strUsername)) { this.OnSetErrorEvent(this.txtUsername, "请选择学生帐号!"); return; } if (this.loginMethod != EnumLoginMethod.SelectName && string.IsNullOrEmpty(strPassword)) { this.OnSetErrorEvent(this.txtPassword, "请输入学生密码!"); return; } #endregion #region 登录。 this.btnLogin.Enabled = false; StartLogin sl = new StartLogin(); sl.MachineName = Dns.GetHostName(); sl.UserAccount = strUsername; sl.UserPassword = strPassword; this.OnMessageEvent(MessageType.Normal, "开始登录验证..."); this.socket.Send(sl, new IPEndPoint(this.hostIP, this.ports.ClientCallback)); #endregion } catch (Exception x) { this.OnMessageEvent(MessageType.Normal | MessageType.PopupWarn, "发生异常:" + x.Message); this.btnLogin.Enabled = true; } }
/// <summary> /// 验证登录。 /// </summary> /// <param name="s"></param> protected void VerifyLogin(StartLogin s) { if (this.userInfo == null || Program.STUDENTS == null || this.sci == null || this.sci.ClassInfo == null) return; this.RaiseChanged(string.Format("学生机IP:({0})[{1}],{2:HH-mm-ss} 开始登录!", s.MachineName, s.UIP, s.Time)); StudentEx stu = Program.STUDENTS[s.UserAccount]; EndLogin end = new EndLogin(); end.UID = this.userInfo.UserID; end.Time = DateTime.Now; if ((stu == null) && (this.sci.LoginMethod != EnumLoginMethod.UnifiedLogin)) { end.Result = false; end.Error = string.Format("学生[{0},{1}]不属于本班级[{2}].", s.MachineName, s.UIP, this.sci.ClassInfo.ClassName); this.VerifyLoginEndHandler(s, stu, end); } else if ((stu != null) && ((stu.Status & StudentControl.EnumStudentState.Online) == StudentControl.EnumStudentState.Online)) { end.Result = false; end.Error = string.Format("学生[{0},{1}]已经登录!", s.MachineName, s.UIP); this.VerifyLoginEndHandler(s, stu, end); } else { #region 验证账号。 switch (this.sci.LoginMethod) { case EnumLoginMethod.SelectName: case EnumLoginMethod.Password: { end.Result = true; end.Student = new Student(stu.StudentID, stu.StudentCode, stu.StudentName); if (this.sci.LoginMethod == EnumLoginMethod.Password) { if (!(end.Result = (this.sci.Password == s.UserPassword))) { end.Result = false; end.Student = null; end.Error = "密码错误!"; } } end.Time = DateTime.Now; this.VerifyLoginEndHandler(s, stu, end); } break; case EnumLoginMethod.UnifiedLogin: { Poxy.TeaClientServicePoxyFactory.Instance(this.service, this.RaiseChanged).Authentication(Yaesoft.SFIT.Client.TeaHost.Poxy.EnumUserAuthen.Student, s.UserAccount, s.UserPassword, new Yaesoft.SFIT.Client.TeaHost.Poxy.UserAuthenticationHandler(delegate(LocalUserInfo userInfo, Exception e) { if (end.Result = (userInfo != null)) { if ((stu = Program.STUDENTS[userInfo.UserID]) == null) { end.Result = false; end.Error = string.Format("学生[{0},{1}]不属于本班级[{2}].", s.MachineName, s.UIP, this.sci.ClassInfo.ClassName); } } else { end.Error = e.Message; } this.VerifyLoginEndHandler(s, stu, end); })); } break; } #endregion } }