public AjaxResult PostUser(JObject jData) { AjaxResult result = new AjaxResult(); try { //获取EF用户 TS_USER user = service.CheckToken(Token); //用户信息 AppCurrentUser currentUser = new AppCurrentUser() { Id = user.C_ID, Name = user.C_NAME, Account = user.C_ACCOUNT, CustId = user.C_CUST_ID, CustTel = user.C_MOBILE, Type = user.N_TYPE.ToString() }; //获取客户档案 TS_CUSTFILE custFile = service.GetCustFile(currentUser.CustId); if (custFile != null) { currentUser.C_NC_M_ID = custFile.C_NC_M_ID; currentUser.CustName = custFile.C_NAME; currentUser.CustNo = custFile.C_NO; TS_CUSTADDR custAddr = service.GetCustAddr(currentUser.CustId); if (custAddr != null) { //currentUser.CustTel = custAddr.C_CGMOBILE; currentUser.CustAddress = custAddr.C_CGADDR; } } //获取用户菜单权限 //currentUser.MenuFuncs = service.GetCurrentMenuFun(currentUser.Id); //获取用户按钮权限 //currentUser.ButtonFuncs = service.GetCurrentButtonFun(currentUser.Id); //获取用户部门信息 //currentUser.Depts = service.GetCurrentUserDept(currentUser.Id); //获取角色信息 //currentUser.Roles = service.GetCurrentUserRole(currentUser.Id); //获取角色权限 //currentUser = service.GetRoleFun(currentUser); //保存cookie HttpCookie myCookie = new HttpCookie("CurrentUser"); myCookie.Value = SerializationHelper.JsonSerialize <AppCurrentUser>(currentUser); myCookie.Expires = DateTime.Now.AddHours(24); //myCookie.Expires = DateTime.Now.AddMinutes(1); HttpContext.Current.Response.Cookies.Add(myCookie); //保存Session HttpContext.Current.Session["CurrentUser"] = currentUser; HttpContext.Current.Session.Timeout = 1440; result.Code = DoResult.Success; result.Result = JsonConvert.SerializeObject(currentUser); } catch (Exception e) { result.Code = DoResult.Failed; result.Result = e.Message; } return(result); }
/// <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); } }