Beispiel #1
0
        public View_IMUser LoginIM(string username, string userpwd, string Ip, string port, out string error)
        {
            error = string.Empty;
            View_IMUser user = Dal.Find <View_IMUser>(View_IMUser._.Code == username);

            if (user == null)
            {
                error = "用户名不正确";
            }
            else
            if (user.Pwd != userpwd)
            {
                error = "密码不正确";
                user  = null;
            }
            else
            {
                //更新sessionlog
                List <SystemSessionLog> logList = Dal.From <SystemSessionLog>().Where(SystemSessionLog._.UserID == user.ID &&
                                                                                      SystemSessionLog._.OutDate == null).OrderBy(SystemSessionLog._.EntryDate.Desc).List <SystemSessionLog>();

                if (logList == null || logList.Count == 0)
                {
                    SystemSessionLog log = new SystemSessionLog();
                    log.ID         = Guid.NewGuid().ToString();
                    log.UserID     = user.ID;
                    log.UserCode   = user.Code;
                    log.UserName   = user.Name;
                    log.CompID     = user.DepartID;
                    log.CompName   = user.IMGroupName;
                    log.DepartID   = user.DepartID;
                    log.DepartName = user.IMGroupName;
                    log.GroupID    = user.DepartID;
                    log.GroupName  = user.IMGroupName;
                    log.EntryDate  = DateTime.Now;
                    log.EntryIP    = Ip;
                    log.PortName   = port;
                    log.EntryStats = "在线";
                    Dal.Submit(log);
                }
                else
                {
                    SystemSessionLog LastLog = logList[0];
                    //检测ip是否相等
                    if (LastLog.EntryIP != Ip)
                    {
                        //检测是否同一天,如果是同一天,则提示已经再其他地方登录,
                        //if (LastLog.EntryDate.Date == DateTime.Now.Date)
                        //{
                        //    error = "该账户已在其他机器登录,不能重复登录";
                        //    user = null;
                        //}
                        //else
                        //{
                        //否则则冲掉前一次登录,并重新设置登录日期
                        //LastLog.EntryDate = DateTime.Now;
                        LastLog.EntryIP  = Ip;
                        LastLog.PortName = port;
                        if (logList.Count > 1)
                        {
                            for (int i = 1; i < logList.Count; i++)
                            {
                                logList[i].OutDate = DateTime.Now;
                            }
                        }
                        Dal.Submit(logList);
                        //}
                    }
                    else
                    {
                        //ip相等
                        LastLog.PortName = port;
                        if (logList.Count > 1)
                        {
                            for (int i = 1; i < logList.Count; i++)
                            {
                                logList[i].OutDate = DateTime.Now;
                            }
                        }
                        Dal.Submit(logList);
                    }
                }
            }
            return(user);
        }
Beispiel #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string linkurl    = "consult.aspx?sid={0}&code={0}&name={1}";
                string offlinkurl = "javascript:void(0)";
                string tmpl       = @" <td  align='right'  valign=middle   width='{3}%'>
                                <a href='{0}'>  <img src='image/chatlist_head_0{1}.png' /></a> </td><td   valign=middle   width='{3}%'><a href='{0}'>{2}</a>
                            </td>";
                string grouptmpl  = @"<tr  style='background:#eee;font-weight:bold;'>
                            <td colspan={1}>
                                {0}
                            </td>
 
                        </tr>";

                Dictionary <string, string> data = new Dictionary <string, string>();
                data = codingChatHub.UserHandler.SeverIds;
                AuthorityClient.UserInfoClient client = new AuthorityClient.UserInfoClient();
                List <View_IMUser>             list   = client.GetIMUserList().ToList <View_IMUser>();

                int    oneRowCount = 2;
                string group       = "";
                string result      = "";
                int    groupCount  = 0;
                int    tdWidth     = 100 / (oneRowCount * 2);
                for (int k = 0; k < list.Count; k++)
                {
                    View_IMUser item = list[k];
                    if (group != item.DepartCode)
                    {
                        group      = item.DepartCode;
                        groupCount = 0;
                        if (string.IsNullOrWhiteSpace(item.DepartName))
                        {
                            item.DepartName = "未分组";
                        }
                        else
                        {
                            result += string.Format(grouptmpl, item.DepartName, oneRowCount * 2);
                        }
                    }
                    else
                    {
                        groupCount++;
                    }
                    int currentBL = groupCount % oneRowCount;
                    if (currentBL == 0)
                    {
                        result += "<tr>";
                    }

                    if (item.IsOnLine)
                    {
                        result += string.Format(tmpl, string.Format(linkurl, item.ID, item.Name), 1, item.Name, tdWidth);
                    }
                    else
                    {
                        result += string.Format(tmpl, offlinkurl, 2, item.Name, tdWidth);
                    }
                    if (currentBL == oneRowCount - 1)
                    {
                        result += "</tr>";
                    }
                }


                result             = "<table class='onlinelist' width='100%'>" + result + "</table>";
                userinfo.InnerHtml = result;
            }
        }
Beispiel #3
0
        public static IMUserInfo Clone(this View_IMUser imuser)
        {

            IMUserInfo tem = new IMUserInfo();
            tem.ID = imuser.ID;

            tem.Code = imuser.Code;

            tem.Name = imuser.Name;

            tem.NickyName = imuser.NickyName;

            tem.Signature = imuser.Signature;

            tem.Photo = imuser.Photo;

            tem.Pwd = imuser.Pwd;

            tem.Sex = imuser.Sex;
            if (imuser.Birthday.HasValue)
            {
                tem.Birthday = imuser.Birthday.Value.ToString();
            }


            tem.ContactPhone = imuser.ContactPhone;

            tem.AgentID = imuser.AgentID;

            tem.AgentGroup = imuser.AgentGroup;

            tem.ICallPwd = imuser.ICallPwd;

            tem.IsWebPerson = imuser.IsWebPerson;

            tem.BJDH = imuser.BJDH;

            tem.Note = imuser.Note;

            tem.Email = imuser.Email;

            tem.QQ = imuser.QQ;

            tem.CompName = imuser.CompName;

            tem.DepartName = imuser.DepartName;

            tem.IMGroupName = imuser.IMGroupName;
            tem.DepartID = imuser.DepartID;
            /// <summary>
            /// 获取用户状态
            /// </summary>
            tem.UserState = imuser.UserState;
            /// <summary>
            /// 登录结果
            /// </summary>
            tem.Response = imuser.Response;
            /// <summary>
            /// 是否在线
            /// </summary>
            tem.IsOnline = imuser.IsOnLine;
            return tem;

        }
Beispiel #4
0
        //处理用户登录
        private void IncomingLoginHandler(PacketHeader header, Connection Connection, IMUserInfo loginInfo)
        {
            try
            {
                //从数据库中验证登录信息
                string      ip       = Connection.ConnectionInfo.LocalEndPoint.ToString();
                string      port     = Connection.ConnectionInfo.LocalEndPoint.Port.ToString();
                string      error    = string.Empty;
                View_IMUser userinfo = null;
                if (loginInfo.IsWebMsg)
                {
                    userinfo      = new View_IMUser();
                    userinfo.ID   = loginInfo.Code;
                    userinfo.Code = loginInfo.Code;
                    userinfo.Name = "网页用户";
                }
                else
                {
                    userinfo = new AuthorityClient.LoginClient().Login(loginInfo.Code, loginInfo.Pwd, ip, port, out error);
                }

                if (userinfo == null)
                {
                    UserLoginContract resContract = new UserLoginContract(error, null);
                    Connection.SendObject("ResUserLogin", resContract);
                }
                else
                {
                    UserLoginContract resContract = new UserLoginContract(error, userinfo.Clone());
                    Connection.SendObject("ResUserLogin", resContract);
                    if (string.IsNullOrWhiteSpace(error))
                    {
                        lock (syncLocker)
                        {
                            //同一账号登陆,先退出已经登陆的客户端
                            if (userManager.ContainsKey(userinfo.ID))
                            {
                                //通知相应的连接,关闭此连接
                                foreach (Connection conn in NetworkComms.GetExistingConnection(userManager[userinfo.ID], ConnectionType.TCP))
                                {
                                    conn.SendObject("CloseConnection", "msg");
                                }

                                userManager.Remove(userinfo.ID);
                            }
                            //注册新的用户
                            if (!userManager.ContainsKey(userinfo.ID))
                            {
                                userManager.Add(userinfo.ID, Connection.ConnectionInfo.NetworkIdentifier);
                            }
                        }

                        //用户上线后,通知其他用户
                        UserStateNotify(userinfo.ID, OnlineState.Online);
                    }
                }
            }
            catch (Exception ex)
            {
                LogTools.LogException(ex, "IncomingLoginHandler");
            }
        }