public ActionResult Login(LogInViewModel viewModel) { if (!ModelState.IsValid) { return(View()); } var user = AuthorizeManager.Login(viewModel.UserName, viewModel.Password); if (user != null) { //获取用户所属的功能权限列表,并保持的Session中 var permissions = AuthorizeManager.GetUserAuthKey(viewModel.UserName); UserAccountListDto userInfo = _userAccountAppService.GetUserAccountBySysNo(user.SysNO); if (userInfo != null) { Session["DepartId"] = userInfo.DepartmentID; Session["PostId"] = userInfo.PostID; } else { return(View((object)"账号未同步到商学院系统中!")); } Session["UserPermissions"] = permissions; Session["UserId"] = user.SysNO; Session["UserName"] = viewModel.UserName; Session["DisplayName"] = user.DisplayName; FormsAuthentication.SetAuthCookie(viewModel.UserName, true); viewModel.ReturnUrl = HttpUtility.UrlDecode(viewModel.ReturnUrl); if (string.IsNullOrWhiteSpace(viewModel.ReturnUrl)) { return(RedirectToAction("Index", "Home")); } else { return(Redirect(viewModel.ReturnUrl)); } } else { return(View((object)"用户名或密码不正确!")); } }
public ActionResult Login(LogInViewModel viewModel) { if (!ModelState.IsValid) { return(View()); } var user = AuthorizeManager.Login(viewModel.UserName, viewModel.Password); if (user != null) { //获取用户所属的功能权限列表,并保持的Session中 var permissions = AuthorizeManager.GetUserAuthKey(viewModel.UserName); UserAccountListDto userInfo = _userAccountAppService.GetUserAccountBySysNo(user.SysNO); if (userInfo != null) { CookieHelper.SetCookie("UserId", user.SysNO.ToString()); CookieHelper.SetCookie("DepartId", userInfo.DepartmentID.ToString()); CookieHelper.SetCookie("PostId", userInfo.PostID.ToString()); CookieHelper.SetCookie("UserName", viewModel.UserName.ToString()); CookieHelper.SetCookie("DisplayUserName", charTrans(user.DisplayName.ToString() == string.Empty? viewModel.UserName.ToString() : user.DisplayName.ToString())); } FormsAuthentication.SetAuthCookie(viewModel.UserName, true); viewModel.ReturnUrl = HttpUtility.UrlDecode(viewModel.ReturnUrl); if (string.IsNullOrWhiteSpace(viewModel.ReturnUrl)) { return(RedirectToAction("Index", "Home")); } else { return(Redirect(viewModel.ReturnUrl)); } } else { viewModel.SuccessMessage = "用户名或密码不正确!"; return(View(viewModel)); } }