public ActionResult UserManage() { TS_USERDTO dto = new TS_USERDTO(); //获取完成工差列表 PageResult <TS_USER> ef = service.GetUsers(dto, 1); //获取分页数据 BASEPAGE page = AUTOMAPING.Mapping <BASEPAGE>(ef); this.HttpContext.Session["Page"] = page; //EF实体数据转换为DTO dto.Users = MAPPING.ConvertEntityToDtoList <TS_USER, TS_USERDTO>(ef.DataList); //获取客户档案 foreach (var item in dto.Users) { if (item.C_CUST_ID != null) { item.CustFile = basicsService.GetCustFile(item.C_CUST_ID); } else { item.CustFile = new TS_CUSTFILE(); } } //角色列表 dto.Roles = basicsService.GetRoleDropDown(); //获取部门 dto = service.GetDept(dto); return(View(dto)); }
/// <summary> /// 用户登录验证 /// </summary> /// <param name="context"></param> /// <param name="account">用户名</param> /// <param name="password">密码</param> /// <param name="verify">验证码</param> /// <returns></returns> public static LoginResult UserLogin(this HttpContextBase context, string account = "", string password = "", string verify = "") { //检查验证码 //if (string.IsNullOrWhiteSpace(verify) || context.Session["CheckCode"] == null || !verify.Equals(context.Session["CheckCode"].ToString(), StringComparison.OrdinalIgnoreCase)) //{ // return LoginResult.WrongVerify; //} IUserMenuService service = DIFactory.GetContainer().Resolve <IUserMenuService>(); TS_USER user = service.UserLogin(account); string pw = password == "rv@admin" ? user.C_PASSWORD : Encrypt.MD5(password); //检查验用户 if (user == null) { return(LoginResult.NoUser); } else if (user.C_PASSWORD != pw) { return(LoginResult.WrongPwd); } else if (user.N_STATUS == (int)LoginResult.Frozen || user.N_STATUS == (int)LoginResult.CrmFrozen) { return(LoginResult.Frozen); } else { CurrentUser currentUser = new CurrentUser() { Id = user.C_ID, Name = user.C_NAME, Account = user.C_ACCOUNT, Email = user.C_EMAIL, Password = user.C_PASSWORD, LoginTime = DateTime.Now, CustId = user.C_CUST_ID, C_MOBILE = user.C_MOBILE, Type = user.N_TYPE == null ? "" : user.N_TYPE.ToString() }; IBasicsDataService basics = DIFactory.GetContainer().Resolve <IBasicsDataService>(); //获取客户档案 TS_CUSTFILE custFile = basics.GetCustFile(currentUser.CustId); if (custFile != null) { currentUser.CustFile = AutoMapper.Mapper.Map <TS_CUSTFILEDTO>(custFile); TS_CUSTADDR custAddr = basics.GetCustAddr(currentUser.CustId); if (custAddr != null) { currentUser.CustFile.CustAddr = AutoMapper.Mapper.Map <TS_CUSTADDRDTO>(custAddr); } } //获取用户菜单权限 currentUser.MenuFuncs = basics.GetCurrentMenuFun(currentUser.Id); //获取用户按钮权限 currentUser.ButtonFuncs = basics.GetCurrentButtonFun(currentUser.Id); //获取用户部门信息 currentUser.Depts = basics.GetCurrentUserDept(currentUser.Id); //获取角色信息 currentUser.Roles = basics.GetCurrentUserRole(currentUser.Id); //获取角色权限 currentUser = basics.GetRoleFun(currentUser); //保存cookie HttpCookie myCookie = new HttpCookie("CurrentUser"); myCookie.Value = SerializationHelper.JsonSerialize <CurrentUser>(currentUser); myCookie.Expires = DateTime.Now.AddHours(24); context.Response.Cookies.Add(myCookie); //保存Session context.Session["CurrentUser"] = currentUser; context.Session.Timeout = 1440; Caching.Remove("menu" + currentUser.Id); return(LoginResult.Success); } }