示例#1
0
        public List <Menu> GetCurrentUserMenu(string token = null)
        {
            if (string.IsNullOrEmpty(token))
            {
                token = ServiceSession.Current.Context.Parameters["token"].ToString();
            }
            ISqlMapper     mapper  = Common.GetMapperFromSession();
            UserBLL        userbll = new UserBLL();
            Menu_RoleDao   dao     = new Menu_RoleDao(mapper);
            UserEntireInfo u       = userbll.GetUserFormCache(token);

            if (u == null)
            {
                u = userbll.GetCurrentUser(token);
            }
            if (u == null)
            {
                throw new Exception("该用户信息不存在!");
            }
            var menurole = dao.QueryByUserID(u.User.ID);
            var list     = GetAllMenu();
            var userMenu = list.FindAll(t => menurole.Exists(p => p.MenuID == t.ID) && t.Enabled == 1);

            return(userMenu);
        }
示例#2
0
        /// <summary>
        /// 3:验证失效。4:没有权限
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public int CheckUserAuth(string token)
        {
            ISqlMapper mapper = Common.GetMapperFromSession();
            //验证有没有登录
            UserEntireInfo user = GetUserEntireInfoFromCache(token);

            if (user == null)
            {
                return(3);
            }
            LogonHistoryDao logonhistorydao = new LogonHistoryDao(mapper);
            var             logonList       = logonhistorydao.Query(new LogonHistoryQueryForm {
                Token = token
            });

            //登录超时
            if (logonList.Count == 0 || DateTime.Now - logonList[0].ActiveTime > new TimeSpan(0, 30, 0))
            {
                return(3);
            }
            logonhistorydao.Update(new LogonHistoryUpdateForm
            {
                Entity = new LogonHistory {
                    ActiveTime = DateTime.Now
                },
                LogonHistoryQueryForm = new LogonHistoryQueryForm {
                    Token = token
                },
            });
            if (ServiceSession.Current != null)
            {
                return(CheckAuth(user.Role));
            }
            return(-1);
        }
示例#3
0
        public LogonResultForm GetUserInfo(string userid)
        {
            var     mapper  = Common.GetMapperFromSession();
            UserDao userdao = new UserDao(mapper);
            var     user    = userdao.Query(new UserQueryForm {
                Name = userid
            }).FirstOrDefault();

            if (user == null)
            {
                throw new Exception("用户:" + userid + "在系统中不存在!");
            }
            if (user.Enabled == 0)
            {
                throw new Exception("该用户已被禁用,请联系管理员!");
            }
            LogonResultForm result      = new LogonResultForm();
            UserInfoDao     userInfoDao = new UserInfoDao(mapper);
            RoleDao         roleDao     = new RoleDao(mapper);
            LogonHistoryDao historyDao  = new LogonHistoryDao(mapper);
            string          token       = Guid.NewGuid().ToString().Replace("-", "");
            var             userinfo    = userInfoDao.Query(new UserInfoQueryForm {
                ID = user.ID
            }).FirstOrDefault();
            UserEntireInfo u = new UserEntireInfo {
                User = user
            };

            if (userinfo != null)
            {
                u.UserInfo = userinfo;
            }
            u.Role = roleDao.QueryRoleByUserID(u.User.ID);
            LogonHistory history = new LogonHistory
            {
                LogonTime  = DateTime.Now,
                Token      = token,
                UserID     = user.ID,
                ActiveTime = DateTime.Now,
            };

            historyDao.Add(history);
            result.token    = token;
            result.UserInfo = userinfo;
            cache.AddItem(token, u, 30 * 60);
            MenuBLL menubll = new MenuBLL();

            result.Menu = menubll.GetCurrentUserMenu(result.token);
            return(result);
        }
示例#4
0
        public UserEntireInfo GetCurrentUser(string token = null)
        {
            ISqlMapper mapper = Common.GetMapperFromSession();

            if (string.IsNullOrEmpty(token))
            {
                token = ServiceSession.Current.Context.Parameters["token"].ToString();
            }
            var u = GetUserEntireInfoFromCache(token);

            if (u == null)
            {
                MonitorCache.GetInstance().PushMessage(new CacheMessage {
                    Message = "user is null"
                }, SOAFramework.Library.CacheEnum.FormMonitor);
                UserDao         userdao      = new UserDao(mapper);
                RoleDao         roledao      = new RoleDao(mapper);
                UserInfoDao     uidao        = new UserInfoDao(mapper);
                LogonHistoryDao lhdao        = new LogonHistoryDao(mapper);
                var             logonhistory = lhdao.Query(new LogonHistoryQueryForm {
                    Token = token
                }).FirstOrDefault();
                string userid = logonhistory.UserID;
                var    user   = userdao.Query(new UserQueryForm {
                    ID = userid
                }).FirstOrDefault();
                var userinfo = uidao.Query(new UserInfoQueryForm {
                    ID = userid
                }).FirstOrDefault();
                var roles = roledao.QueryRoleByUserID(userid);
                u = new UserEntireInfo
                {
                    User     = user,
                    Role     = roles,
                    UserInfo = userinfo,
                };
            }
            return(u);
        }
示例#5
0
        public UserEntireInfo GetUserEntireInfoFromCache(string token)
        {
            UserEntireInfo u = cache.GetItem <UserEntireInfo>(token);

            return(u);
        }