public ActionResult Login(LoginViewModel model) { if (ModelState.IsValid) { var currentUser = clientService.GetClientByLoginAndPassword(model.Login, model.Password); if(currentUser != null) { string name; if (currentUser.FirstName != null) name = currentUser.FirstName + " " + currentUser.LastName; name = currentUser.Login; var authTicket = new FormsAuthenticationTicket( 1, currentUser.UserId.ToString(), DateTime.Now, DateTime.Now.AddMinutes(60), true, name ); string encryptedTicket = FormsAuthentication.Encrypt(authTicket); var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); HttpContext.Response.Cookies.Add(authCookie); return RedirectToAction("Index", "Home"); } } return View(model); }
public ActionResult Login(LoginViewModel model) { if (ModelState.IsValid) { var currentUser = employeeService.GetEmployeeByLoginAndPassword(model.Login, model.Password); if (currentUser != null) { var authTicket = new FormsAuthenticationTicket( 1, currentUser.Login, DateTime.Now, DateTime.Now.AddMinutes(60), true, "Employee," + (currentUser.Role).ToString() ); string encryptedTicket = FormsAuthentication.Encrypt(authTicket); var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); HttpContext.Response.Cookies.Add(authCookie); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", "Неправильно указан логин или пароль"); return View(model); } } return View(model); }
public ActionResult Login(LoginViewModel model) { return View(); }
public ActionResult Login() { var model = new LoginViewModel(); return View(); }