/// <summary> /// 登录 /// </summary> /// <returns></returns> public ActionResult AjaxLogin(string UserName, string PassWord) { AjaxResult json = new AjaxResult(); PassWord = PassWord.ToMD5(); Sys_UserAccount SystemUser = DapperCommand.SelectSingle <Sys_UserAccount>(new { UserName, PassWord }, " UserName=@UserName and PassWord=@PassWord"); if (SystemUser == null) { json.Message = "用户名或密码不正确!"; json.Code = 1; json.Result = false; } else if (SystemUser.Status == 1) { json.Message = "账户已锁定,请与管理员联系!"; json.Code = 1; json.Result = false; } else { FormsAuthen(SystemUser, SystemUser.UserName); SystemUser.LastTime = DateTime.Now; SystemUser.Update(); json.Message = "登录成功!"; json.Code = 0; json.Result = true; try { UserPermisstionsOperate userPermisstionsOperate = new UserPermisstionsOperate(SystemUser.GUID); userPermisstionsOperate.StoragePermissions(); if (SystemUser.IsAdmin != 1) { //判断是否有权限 if (userPermisstionsOperate.HasRightList().Count == 0) { json.Message = "此账号未分配权限!请与管理员联系!"; json.Code = 1; json.Result = false; } } } catch (Exception) { json.Message = "此账号未分配权限!请与管理员联系!"; json.Code = 1; json.Result = false; } } return(Content(json.ToJson())); }
/// <summary> /// 缓存权限 /// </summary> public void StoragePermissions() { #region 用户缓存 //获取用户 Model Sys_UserAccount admin = DapperCommand.SelectSingle <Sys_UserAccount>(new { GUID }, " GUID=@GUID "); Cache.AddCache(GUID.ToString() + "-Admin", admin, SystemExtends.CacheExpiredTime); #endregion if (GetAdmin.IsAdmin == 0) { #region 角色缓存 //获取用户角色集合 List <Sys_UserRole> listUserRole = DapperCommand.Select <Sys_UserRole>(new { UserAccId = GUID }, " UserAccId=@UserAccId ").ToList(); //获取角色OID集合 List <string> listRoleOID = new List <string>(); listUserRole.ForEach(x => { if (x.RoleID != null && x.RoleID != "") { string item = "'" + x.RoleID + "'"; if (!listRoleOID.Contains(item)) { listRoleOID.Add(item); } } }); //获取角色集合 保存至 缓存 List <Sys_Role> listRoles = DapperCommand.Select <Sys_Role>(new { GUID = listRoleOID.ToArray() }, " GUID in ({0}) and Deleted = 0 ").ToList(); Cache.AddCache(GUID.ToString() + "-Roles", listRoles, SystemExtends.CacheExpiredTime); #endregion #region 权限缓存 //获取角色权限集合 List <Sys_RoleRight> listRoleRight = DapperCommand.Select <Sys_RoleRight>(new { RoleID = listRoleOID.ToArray() }, " RoleID in ({0}) Deleted = 0 ").ToList(); //获取权限OID集合 List <string> listRightOID = new List <string>(); listRoleRight.ForEach(x => { if (x.RightID != null && x.RightID != "") { string item = "'" + x.RightID + "'"; if (!listRightOID.Contains(item)) { listRightOID.Add(item); } } }); //获取权限集合 保存至缓存 List <Sys_Right> listRights = DapperCommand.Select <Sys_Right>(new { GUID = listRightOID.ToArray() }, " GUID in ({0}) Deleted = 0 ").ToList(); Cache.AddCache(GUID.ToString() + "-Rights", listRights, SystemExtends.CacheExpiredTime); #endregion #region 模块缓存 //获取模块OID List <string> listModulesOID = new List <string>(); listRights.ForEach(x => { if (x.ForModuleID != null && x.ForModuleID != "") { string item = "'" + x.ForModuleID + "'"; if (!listModulesOID.Contains(item)) { listModulesOID.Add(item); } } }); //获取模块集合 保存至缓存 List <Sys_Module> listModule = DapperCommand.Select <Sys_Module>(new { GUID = listModulesOID.ToArray() }, " GUID in ({0}) Deleted = 0 ").ToList(); Cache.AddCache(GUID.ToString() + "-Module", listModule, SystemExtends.CacheExpiredTime); #endregion } }