Пример #1
0
 /// <summary>
 /// 获取本逻辑类单例
 /// </summary>
 /// <returns></returns>
 public static LoginLogBll GetInstence()
 {
     if (_LoginLogBll == null) {
         _LoginLogBll = new LoginLogBll();
     }
     return _LoginLogBll;
 }
Пример #2
0
        /// <summary>
        /// 用户点击退出系统时,调用本函数,本函数将在在线用户表中删除当前用户,并添加用户退出日志
        /// </summary>
        public void UserExit(Page page)
        {
            try
            {
                //获取用户Hashtable Key
                var userHashKey = GetUserHashKey();
                //判断用户的Session["UserHashKey"]是否存在,即用户是否TimeOut退出了
                if (userHashKey != null)
                {
                    //添加用户退出日志
                    LoginLogBll.GetInstence().Save(userHashKey + "", "用户【{0}】退出系统!在线时间【{1}】");

                    //删除数据库记录与IIS缓存
                    Delete(page, x => x.UserHashKey == userHashKey);
                    //清空Session
                    SessionHelper.RemoveSession(OnlineUsersTable.UserHashKey);
                    SessionHelper.RemoveSession(OnlineUsersTable.Md5);
                    SessionHelper.RemoveSession(PositionTable.PagePower);
                    SessionHelper.RemoveSession(PositionTable.ControlPower);
                    //删除Cookies
                    CookieHelper.ClearCookie(OnlineUsersTable.UserHashKey);
                    CookieHelper.ClearCookie(OnlineUsersTable.Md5);
                }
            }
            catch
            {
            }
        }
Пример #3
0
 /// <summary>
 /// 获取本逻辑类单例
 /// </summary>
 /// <returns></returns>
 public static LoginLogBll GetInstence()
 {
     if (_LoginLogBll == null)
     {
         _LoginLogBll = new LoginLogBll();
     }
     return(_LoginLogBll);
 }
Пример #4
0
        /// <summary>
        /// 将指定用户踢下线,并添加用户退出日志
        /// </summary>
        public void UserExit(Page page, string userHashKey)
        {
            var model = GetOnlineUsersModel(userHashKey);

            if (model != null)
            {
                //添加用户退出日志
                LoginLogBll.GetInstence().Save(userHashKey, "用户【" + model.Manager_CName + "】给管理员【" + GetManagerCName() + "】踢出系统!在线时间【{1}】");

                //删除数据库记录与IIS缓存
                Delete(page, model.Id);
            }
        }
Пример #5
0
        /// <summary>
        /// 判断用户是否被强迫离线[true是;false否]
        /// </summary>
        public bool IsOffline(Page page)
        {
            try
            {
                //获取当前用户Id
                var userinfoId = GetManagerId();

                //判断当前用户是否已经被系统清除
                if (userinfoId == 0)
                {
                    //通知用户
                    FineUI.Alert.Show("您太久没有操作已退出系统,请重新登录!", "检测通知", MessageBoxIcon.Information, "window.location.href='/WebManage/Login.aspx';");
                    return(true);
                }
                else
                {
                    //判断在线用户的Md5与当前用户存储的Md5是否一致
                    if (GenerateMd5() != CookieHelper.GetCookieValue(OnlineUsersTable.Md5))
                    {
                        //添加用户下线记录
                        LoginLogBll.GetInstence().Save(userinfoId, "用户【{0}】的账号已经在另一处登录,本次登陆下线!在线时间【{1}】");

                        //清除在线表里与当前用户同名的记录
                        Delete(null, x => x.Id == userinfoId);

                        //清空Session
                        SessionHelper.RemoveSession(OnlineUsersTable.UserHashKey);
                        SessionHelper.RemoveSession(OnlineUsersTable.Md5);
                        SessionHelper.RemoveSession(PositionTable.PagePower);
                        SessionHelper.RemoveSession(PositionTable.ControlPower);
                        //删除Cookies
                        CookieHelper.ClearCookie(OnlineUsersTable.UserHashKey);
                        CookieHelper.ClearCookie(OnlineUsersTable.Md5);

                        CommonBll.WriteLog("当前帐号已经下线,用户Id【" + userinfoId + "】");

                        //通知用户
                        FineUI.Alert.Show("您的账号已经在另一处登录,当前账号已经下线!", "检测通知", MessageBoxIcon.Information, "window.location.href='/WebManage/Login.aspx';");
                        return(true);
                    }
                }
                return(false);
            }
            catch (Exception ex)
            {
                CommonBll.WriteLog("Logic.Systems.Manager.CheckIsOffline出现异常", ex);

                FineUI.Alert.Show("系统已经开始更新维护,请稍后重新登录!", "检测通知", MessageBoxIcon.Information, "window.location.href='/WebManage/Login.aspx';");
                return(true);
            }
        }
        /// <summary>
        /// 更新在线人数,将不在线人员删除
        /// </summary>
        public void UpdateUserOnlineCount()
        {
            //获取在线列表
            var onlineUsers = (Hashtable)CacheHelper.GetCache("OnlineUsers");

            //如果不存在在线表则退出
            if (onlineUsers == null)
            {
                return;
            }

            //初始化下线用户KEY存储数组
            var users = new string[onlineUsers.Count];
            int i     = 0;

            //循环读取在线信息
            foreach (DictionaryEntry de in onlineUsers)
            {
                //判断该用户是否在线,不在线的话则将它暂停存储起来
                if (string.IsNullOrEmpty(GetUserHashKey()))
                {
                    users[i] = de.Key + "";
                    i++;
                }
            }

            //移除在线数据
            for (int j = 0; j < users.Length; j++)
            {
                if (users[j] == null)
                {
                    break;
                }

                //添加用户下线记录
                LoginLogBll.GetInstence().Save(users[j], "用户【{0}】退出系统!在线时间【{1}】");
                //将HashTable里存储的前一登陆帐户移除
                var userHashKey = users[j];
                Delete(null, x => x.UserHashKey == userHashKey);
                //移除在线用户
                RemoveUser(users[j]);
            }
        }
Пример #7
0
        /// <summary>
        /// 检查在线列表,将不在线人员删除
        /// </summary>
        public void CheckOnline()
        {
            //获取在线列表
            var onlineUsers = GetList();

            //如果不存在在线表则退出
            if (onlineUsers == null || onlineUsers.Count == 0)
            {
                return;
            }

            //循环读取在线信息
            foreach (var model in onlineUsers)
            {
                //判断该用户最后更新时间是否已经有10分钟未更新,是的话则不将其添加到缓存中
                if (TimeHelper.DateDiff("n", model.UpdateTime, DateTime.Now) > 10)
                {
                    //添加用户下线记录
                    LoginLogBll.GetInstence().Save(model.UserHashKey, "用户【{0}】退出系统!在线时间【{1}】");
                    //移除在线数据
                    Delete(null, model.Id);
                }
            }
        }
Пример #8
0
        /// <summary>
        /// 判断用户是否超时退出(退出情况:1.系统更新,2.用户自动退出)
        /// </summary>
        public void IsTimeOut()
        {
            if (HttpContext.Current.Session == null || HttpContext.Current.Session[OnlineUsersTable.UserHashKey] == null)
            {
                try
                {
                    //不存在则表示Session失效了,重新从Cookies中加载
                    var userHashKey = CookieHelper.GetCookieValue(OnlineUsersTable.UserHashKey);
                    var md5         = CookieHelper.GetCookieValue(OnlineUsersTable.Md5);

                    //判断Cookies是否存在,存在则查询在线列表,重新获取用户信息
                    if (userHashKey.Length > 0 && md5.Length == 32)
                    {
                        //读取当前用户在线实体
                        var model = GetOnlineUsersModel(userHashKey);
                        //当前用户存在在线列表中
                        if (model != null)
                        {
                            //计算用户md5值
                            var key = GenerateMd5(model);

                            //判断用户的md5值是否正确
                            if (md5 == key)
                            {
                                //将UserHashKey存储到缓存中
                                HttpContext.Current.Session[OnlineUsersTable.UserHashKey] = userHashKey;
                                //获取用户权限并存储到用户Session里
                                PositionBll.GetInstence().SetUserPower(model.Position_Id);
                                //更新用户当前SessionId到在线表中
                                //UpdateUserOnlineInfo(model.Id + "", OnlineUsersTable.SessionId, HttpContext.Current.Session.SessionID);

                                return;
                            }
                            //添加用户下线记录
                            LoginLogBll.GetInstence().Save(model.Id, "用户【{0}】的账号已经在另一处登录,本次登陆下线!在线时间【{1}】");

                            //清除在线表里与当前用户同名的记录
                            Delete(null, x => x.Id == model.Id);

                            //清空Session
                            SessionHelper.RemoveSession(OnlineUsersTable.UserHashKey);
                            SessionHelper.RemoveSession(OnlineUsersTable.Md5);
                            SessionHelper.RemoveSession(PositionTable.PagePower);
                            SessionHelper.RemoveSession(PositionTable.ControlPower);
                            //删除Cookies
                            CookieHelper.ClearCookie(OnlineUsersTable.UserHashKey);
                            CookieHelper.ClearCookie(OnlineUsersTable.Md5);
                        }
                        else
                        {
                            //删除数据库记录与IIS缓存
                            Delete(null, x => x.UserHashKey == userHashKey);
                            //清空Session
                            SessionHelper.RemoveSession(OnlineUsersTable.UserHashKey);
                            SessionHelper.RemoveSession(OnlineUsersTable.Md5);
                            SessionHelper.RemoveSession(PositionTable.PagePower);
                            SessionHelper.RemoveSession(PositionTable.ControlPower);
                            //删除Cookies
                            CookieHelper.ClearCookie(OnlineUsersTable.UserHashKey);
                            CookieHelper.ClearCookie(OnlineUsersTable.Md5);
                        }
                    }
                }
                catch (Exception e)
                {
                    //出现异常,保存出错日志信息
                    CommonBll.WriteLog("", e);
                }

                //用户不存在,直接退出
                //FineUI.Alert.Show("当前用户登录已经过时或系统已更新,请重新登录!", "检测通知", MessageBoxIcon.Information, "top.location='Login.aspx'");
                //DotNet.Utilities.JsHelper.AlertAndParentUrl("当前用户登录已经过时或系统已更新,请重新登录!", "Login.aspx");
                HttpContext.Current.Response.Redirect("/WebManage/Login.aspx");
                HttpContext.Current.Response.End();
            }
        }