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; }
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); }
/// <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); }
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); }
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; }
/// <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; }