public LoginResultForm Login(string username, string password) { LoginResultForm result = new LoginResultForm(); ISqlMapper mapper = MapperHelper.GetMapper(); UserDao userdao = new UserDao(mapper); UserInfoDao userInfoDao = new UserInfoDao(mapper); RoleDao roleDao = new RoleDao(mapper); User_RoleDao urdao = new User_RoleDao(mapper); LogonHistoryDao historyDao = new LogonHistoryDao(mapper); MenuDao menudao = new MenuDao(mapper); Menu_RoleDao mrdao = new Menu_RoleDao(mapper); var user = userdao.Query(new UserQueryForm { Name = username, Password = password }).FirstOrDefault(); if (user != null) { if (user.Enabled == 0) throw new Exception("该用户已被禁用,请联系管理员!"); string token = Guid.NewGuid().ToString().Replace("-", ""); var userinfo = userInfoDao.Query(new UserInfoQueryForm { ID = user.ID }).FirstOrDefault(); var ur = urdao.Query(new User_RoleQueryForm { UserID = user.ID }); List<string> roleidlist = new List<string>(); ur.ForEach(t => { roleidlist.Add(t.RoleID); }); var roles = roleDao.Query(new RoleQueryForm { IDs = roleidlist }); var mrs = mrdao.Query(new Menu_RoleQueryForm { RoleIDs = roleidlist }); var menuids = (from mr in mrs select mr.MenuID).Distinct().ToList(); result.Menu = menudao.Query(new MenuQueryForm { IDs = menuids, Enabled = 1 }); UserEntireInfo u = new UserEntireInfo { User = user, UserInfo = userinfo, Role = roles, }; 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.User = u; result.token = token; cache.AddItem(item, 1800); //MonitorCache.GetInstance().PushMessage(new CacheMessage { Message = "login user:"******",token:" + token }, SOAFramework.Library.CacheEnum.FormMonitor); return result; } else { throw new Exception("用户名或者密码错误!请输入正确的用户名和密码!"); } }
public List<Menu> Query(MenuQueryForm form) { ISqlMapper mapper = MapperHelper.GetMapper(); MenuDao dao = new MenuDao(mapper); return dao.Query(form); }
/// <summary> /// 查询角色 /// </summary> /// <param name="form"></param> /// <returns></returns> public List<FullRoleInfo> QueryFullRole(RoleQueryForm form) { ISqlMapper mapper = MapperHelper.GetMapper(); RoleDao dao = new RoleDao(mapper); Role_Module_ActionDao rmadao = new Role_Module_ActionDao(mapper); Menu_RoleDao mrdao = new Menu_RoleDao(mapper); MenuDao menudao = new MenuDao(mapper); List<FullRoleInfo> result = new List<FullRoleInfo>(); form.IsDeleted = 0; var roles = dao.Query(form); var roleids = (from r in roles select r.ID).ToList(); var rmas = rmadao.Query(new Role_Module_ActionQueryForm { RoleIDs = roleids }); var mrs = mrdao.Query(new Menu_RoleQueryForm { RoleIDs = roleids }); var menuids = (from mr in mrs select mr.MenuID).Distinct().ToList(); var menus = menudao.Query(new MenuQueryForm { IDs = menuids, Enabled = 1 }); AuthorityMapping mapping = XMLHelper.DeserializeFromFile<AuthorityMapping>(Common.AuthorityMappingFile); foreach (var role in roles) { var data = role.ConvertTo<FullRoleInfo>(); var parentrole = roles.Find(t => t.ID == role.ParentID); if (parentrole != null) data.ParentRoleName = parentrole.Name; #region 查询权限 var role_rmas = rmas.FindAll(t => t.RoleID.Equals(role.ID)); data.Authority = new List<AuthorityNodeForCheck>(); foreach (var auth in mapping.AuthNode) { auth.Checked = (from au in auth.Item from r in role_rmas where au.ModuleID == r.ModuleID && au.ActionID == r.ActionID select au).Count() == auth.Item.Count; data.Authority.Add(new AuthorityNodeForCheck { ID = auth.ID, Checked = auth.Checked, Name = auth.Name }); } #endregion #region 查询菜单 data.Menus = (from mr in mrs join m in menus on mr.MenuID equals m.ID where mr.RoleID.Equals(role.ID) select m).ToList(); #endregion result.Add(data); } return result; }