public LoginResponse Login(LoginViewModel model) { var userId = _authService.ValidateUser(model.Login, model.Password); var eventInfo = new LogEventInfo(LogLevel.Info, _logger.Name, "Login"); eventInfo.Properties["Login"] = model.Login; if (userId.HasValue) { var userInfo = _authService.GetUserInfo(userId.Value); var ticket = new FormsAuthenticationTicket(1, userInfo.Nickname, DateTime.Now, DateTime.Now.AddDays(1), model.Persistent, userId.Value.ToString()); var ticketStr = FormsAuthentication.Encrypt(ticket); var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, ticketStr); _logger.Info(eventInfo); return new LoginResponse { Name = userInfo.Nickname, Cookie = cookie, Role = userInfo.Role.Name }; } _logger.Error(eventInfo); return null; }
public ActionResult Login(LoginViewModel model) { if (!User.Identity.IsAuthenticated && ModelState.IsValid) { var responseObj = _logics.Login(model); if (responseObj != null) { Response.Cookies.Add(responseObj.Cookie); SuccessMessage("Вы успешно вошли в систему"); } else { ModelState.AddModelError("","Логин или пароль неверен"); return View(); } } return RedirectToAction("Index", "Voyage"); }