コード例 #1
0
ファイル: AccountLogics.cs プロジェクト: Followin/MotorDepot
        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;
        }
コード例 #2
0
 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");
 }