public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } // This doen't count login failures towards lockout only two factor authentication // To enable password failures to trigger lockout, change to shouldLockout: true var result = await SignInHelper.PasswordSignIn(model.UserName, model.Password, model.RememberMe, shouldLockout : false); switch (result) { case SignInStatus.Success: Session["date"] = String.Format("{0:dd/MM/yyyy}", DateTime.Today.Date); TDKTEntities td = new TDKTEntities(); if (Session["year"] == null) { Session["year"] = td.getYear().FirstOrDefault().ToString(); } var tmp = this.UserManager.Users.FirstOrDefault(u => u.UserName == model.UserName); if (await this.UserManager.IsInRoleAsync(tmp.Id, "Theo dõi đơn vị")) { Session["donvi"] = tmp.MaDonVi; } else { Session["donvi"] = null; } return(RedirectToLocal(returnUrl)); case SignInStatus.LockedOut: return(View("Lockout")); case SignInStatus.RequiresTwoFactorAuthentication: return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl })); case SignInStatus.Failure: default: ModelState.AddModelError("", "Đăng nhập không thành công!"); return(View(model)); } }
protected void Session_Start(Object sender, EventArgs e) { if (Request.IsAuthenticated) { Session["date"] = String.Format("{0:dd/MM/yyyy}", DateTime.Today.Date); TDKTEntities td = new TDKTEntities(); if (Session["year"] == null) { HttpContext.Current.Session.Add("year", td.getYear().FirstOrDefault().ToString()); } if (User.IsInRole("Theo dõi đơn vị")) { Session["donvi"] = td.getMaDonvi(User.Identity.GetUserId().ToString()).FirstOrDefault().ToString(); } else { Session["donvi"] = null; } } }