Exemplo n.º 1
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);
     CacheItem item = new CacheItem(token, u);
     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(item, 30 * 60);
     MenuBLL menubll = new MenuBLL();
     result.Menu = menubll.GetCurrentUserMenu(result.token);
     return result;
 }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 获得用户角色子级下的所有用户
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public List <string> GetUserSubUserIDs(string userid)
        {
            UserBLL      userbll = new UserBLL();
            ISqlMapper   mapper  = Common.GetMapperFromSession();
            User_RoleDao urdao   = new User_RoleDao(mapper);
            RoleDao      roledao = new RoleDao(mapper);
            var          urs     = urdao.Query(new User_RoleQueryForm {
                UserID = userid
            });
            List <string> useridlist = new List <string>();
            //检查用户的角色有没有全数据权限
            var roles = roledao.QueryRoleByUserID(userid);

            foreach (var role in roles)
            {
                if (role.DataAccessType == (int)DataAccesssEnum.All)
                {
                    return(null);
                }
            }

            useridlist.Add(userid);
            List <Role> list = new List <Role>();

            foreach (var ur in urs)
            {
                list.AddRange(GetAllSubRoles(ur.RoleID));
            }
            var roleids = (from r in list select r.ID).ToList();

            if (roleids.Count == 0)
            {
                return(useridlist);
            }
            var users = urdao.Query(new User_RoleQueryForm {
                RoleIDs = roleids
            });

            useridlist.AddRange((from u in users select u.UserID).ToList());
            return(useridlist);
        }
Exemplo n.º 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);
        }
Exemplo n.º 5
0
 public UserEntireInfo GetCurrentUser(string token = null)
 {
     ISqlMapper mapper = MapperHelper.GetMapper();
     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();
         if (logonhistory == null) throw new Exception("获取当前用户信息时发生错误,用户不存在");
         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;
 }
Exemplo n.º 6
0
        /// <summary>
        /// 获得用户角色子级下的所有用户
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public List<string> GetUserSubUserIDs(string userid)
        {
            UserBLL userbll = new UserBLL();
            ISqlMapper mapper = MapperHelper.GetMapper();
            User_RoleDao urdao = new User_RoleDao(mapper);
            RoleDao roledao = new RoleDao(mapper);
            var urs = urdao.Query(new User_RoleQueryForm { UserID = userid });
            List<string> useridlist = new List<string>();
            //检查用户的角色有没有全数据权限
            var roles = roledao.QueryRoleByUserID(userid);
            foreach (var role in roles)
            {
                if (role.DataAccessType == (int)DataAccesssEnum.All) return null;
            }

            useridlist.Add(userid);
            List<Role> list = new List<Role>();
            foreach (var ur in urs)
            {
                list.AddRange(GetAllSubRoles(ur.RoleID));
            }
            var roleids = (from r in list select r.ID).ToList();
            if (roleids.Count == 0) return useridlist;
            var users = urdao.Query(new User_RoleQueryForm { RoleIDs = roleids });
            useridlist.AddRange((from u in users select u.UserID).ToList());
            return useridlist;
        }