示例#1
0
        public virtual ActionResult Login(LoginFormViewModel loginFormViewModel)
        {
            var redirectUrl = (string)Session[ReturnUrlSessionKey];

            return Handle(() =>
                              {
                                  var user = _documentSession.Query<User>().SingleOrDefault(u => u.Login == loginFormViewModel.Login);
                                  if (user == null)
                                  {
                                      ModelState.AddModelError(String.Empty, "Неверный логин или пароль");
                                      return;
                                  }

                                  var passHash = _passwordEncoder.GenerateHash(loginFormViewModel.Password, user.PassSalt);
                                  if (!passHash.SequenceEqual(user.PassHash))
                                  {
                                      ModelState.AddModelError(String.Empty, "Неверный логин или пароль");
                                      return;
                                  }

                                  FormsAuthentication.SetAuthCookie(user.Login, true);
                                  Session.Remove(ReturnUrlSessionKey);
                              },
                              successUrl: redirectUrl);
        }
示例#2
0
        public virtual ActionResult Login()
        {
            SetNavigationHierarchy(NavigationsItems.MainPage, new NavigationItem("Вход"));

            //ToDo: Add support of ReturnUrl query parameter which if set in case of automatic redirect to login page
            if (Request.UrlReferrer != Request.Url) //redirect after validation error
                if (Request.UrlReferrer != null) 
                    Session[ReturnUrlSessionKey] = Request.UrlReferrer.AbsoluteUri;

            var loginFormViewModel = new LoginFormViewModel();

            return View(Views.Login, loginFormViewModel);
        }