public async Task <ActionResult> Function(int ID) { var user = this.userClient.FindById(new IdModel { ID = ID }); //返回菜单数据 var menus = this.menuClient.FindAll(); //返回功能数据 var menuFunctions = _menuFunctionClient.FindAll(); //返回已有权限 var userMenus = userMenuClient.FindMenuByUser(new IdModel { ID = ID }); //返回已有功能权限 var userFunctions = _userFunctionClient.FindAllByEntity(new Dictionary <string, string> { { "USER_ID", ID.ToString() } }); await user; await menus; await userMenus; await userFunctions; //仅显示已分配权限的菜单 var VisibleMenus = menus.Result.Where(m => userMenus.Result.Select(u => u.MAIN_MENU_ID).Contains(m.ID) || userMenus.Result.Select(u => u.SUBMENU_ID).Contains(m.ID)).ToList(); ViewBag.Menus = VisibleMenus; //获取对应菜单下功能 ViewBag.MenuFunctions = menuFunctions.Result.Where(mf => VisibleMenus.Select(m => m.ID).Contains(mf.MENU_ID.ToIntByIntNull())).ToList(); ViewBag.UserFunctions = userFunctions.Result; ViewBag.ID = ID; return(View()); }
/// <summary> /// 0成功 1用户不存在 2密码错误 3 验证码错误 4账号已冻结 /// </summary> /// <param name="context"></param> /// <param name="name"></param> /// <param name="pwd"></param> /// <param name="verify"></param> /// <returns></returns> public static LoginResultEntity UserLogin(this HttpContext context, IUserClient userClient, IUserFunctionClient userFunctionClient, Func <CurrentUserEntity, string> tokenBuildFunc, string name = "", string pwd = "", string verify = "", LoginSource loginSource = LoginSource.Client, int userId = 0) { //验证码 //var LoginValidateCode = context.Session.GetString("LoginValidateCode"); //context.Session.Remove("LoginValidateCode"); //if (string.IsNullOrEmpty(verify) || LoginValidateCode == null || !LoginValidateCode.Equals(verify, StringComparison.OrdinalIgnoreCase)) //{ // return LoginResult.WrongVerify; //} CurrentUserEntity currentUser; if (userId != 0) { var findUser = userClient.FindById(new B2b.ComEntity.IdModel { ID = userId }).Result; currentUser = new CurrentUserEntity() { END_DATE = findUser.END_DATE, ID = findUser.ID, IS_MAIN = findUser.IS_MAIN, IS_WXIN_LOGIN = findUser.IS_WXIN_LOGIN, MAIL = findUser.MAIL, MOBILE = findUser.MOBILE, PARTY_ID = Convert.ToInt32(findUser.PARTY_ID), PARTY_TYPE = findUser.PARTY_TYPE, REG_STATUS = findUser.REG_STATUS, START_DATE = findUser.START_DATE, USER = findUser.USER, USER_NAME = findUser.USER_NAME }; } else { if (loginSource == LoginSource.Client) { currentUser = userClient.UserLogin(new LoginEntity { USER = name, PASSWORD = pwd }).Result; } else { currentUser = userClient.ManagerUserLogin(new LoginEntity { USER = name, PASSWORD = pwd }).Result; } } if (currentUser == null || currentUser.ID == 0) { return(new LoginResultEntity(LoginResult.WrongLogin)); } else { if (currentUser.REG_STATUS == "0") { return(new LoginResultEntity(LoginResult.WaitAudit)); } //用户有效性判断 (且"当前日期"在“生效日期START_DATE”与“失效日期END_DATE”之间) else if (currentUser.REG_STATUS == "2" || currentUser.START_DATE == null || DateTime.Now < currentUser.START_DATE || (currentUser.END_DATE != null && DateTime.Now >= currentUser.END_DATE)) { return(new LoginResultEntity(LoginResult.Closed)); } var userFunctions = userFunctionClient.FindAllByEntity(new Dictionary <string, string> { { "USER_ID", currentUser.ID.ToString() } }).Result; for (int i = 0; i < userFunctions.Count; i++) { currentUser.UserFunctionEnabledList.Add(userFunctions[i].MENU_FUNCTION_CODE); } string token = tokenBuildFunc(currentUser); //context.Session.SetString("CurrentUser", JsonHelper.ToJson<CurrentUserEntity>(currentUser)); logger.Debug(string.Format("用户id={0} Name={1}登录系统", currentUser.ID, currentUser.USER)); userClient.LastLoginTimeReload(new ECP.B2b.ComEntity.IdModel { ID = currentUser.ID }); return(new LoginResultEntity(LoginResult.Success, token) { userId = currentUser.ID }); } }