Ejemplo n.º 1
0
 /// <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
     }
 }
Ejemplo n.º 2
0
 /// <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);
         }
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 接收客户端消息数据。
        /// </summary>
        /// <param name="data"></param>
        protected virtual void ReceiveClientData(Msg data)
        {
            if (data == null) return;
            this.RaiseChanged("监听:" + data.ToString());
            switch (data.Kind)
            {
                case MSGKind.ClientClose://学生机下线。
                    {
                        ClientClose cc = data as ClientClose;
                        if (cc != null)
                        {
                            StudentEx student = Program.STUDENTS[cc.StudentID];
                            if (student != null)
                            {
                                if ((student.Status & StudentControl.EnumStudentState.Online) == StudentControl.EnumStudentState.Online)
                                {
                                    student.Status &= ~StudentControl.EnumStudentState.Online;
                                }
                                student.Status |= StudentControl.EnumStudentState.Offline;
                                this.RaiseChanged(string.Format("学生机:({0}){1}[{2}] 关闭客户端!", student.MachineName, student.StudentName, student.IP));
                                this.OnUpdateControls(student);
                            }
                        }
                    }
                    break;
                case MSGKind.ReqLogin://请求登录。
                    {
                        ReqLogin req = data as ReqLogin;
                        if (req != null)
                        {
                            this.RaiseChanged(string.Format("学生机IP:{0},{1:HH-mm-ss} 请求登录!", req.UIP, req.Time));
                            RespLogin resp = new RespLogin();
                            resp.Method = this.sci.LoginMethod;
                            resp.Students = this.sci.ClassInfo.Students;
                            resp.Catalog = this.sci.CatalogInfo;
                            resp.Time = DateTime.Now;
                            resp.UID = this.userInfo.UserID;

                            bool result = this.SendOrderToClient(resp, req.UIP);
                            this.RaiseChanged(string.Format("学生机IP:{0},{1:HH-mm-ss} 请求登录,{2}!", req.UIP, req.Time, result ? "成功" : "失败"));
                        }
                    }
                    break;
                case MSGKind.Logining://开始登录。
                    {
                        StartLogin s = data as StartLogin;
                        if (s != null)
                        {
                            object o = STU_Login_Cache[s.UserAccount];
                            if (o == null)
                            {
                                STU_Login_Cache[s.UserAccount] = s.UserAccount;
                                this.VerifyLogin(s);
                            }
                            else
                            {
                                EndLogin end = new EndLogin();
                                end.UID = this.userInfo.UserID;
                                end.Time = DateTime.Now;
                                end.Result = false;
                                end.Error = string.Format("学生[{0}]正在登录中,请稍后...", s.UserAccount);
                                this.SendOrderToClient(end, s.UIP);
                            }
                        }
                    }
                    break;
            }
        }