public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
            {
                return RedirectToLocal(returnUrl);
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            return View(model);
        }
Пример #2
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            var user = RavenSession.GetUserByUserName(model.UserName);

            if (user == null || user.ValidatePassword(model.Password) == false)
            {
                ModelState.AddModelError("UserNotExistOrPasswordNotMatch",
                                         "Email and password do not match to any known user.");
            }
            else if (user.Enabled == false)
            {
                ModelState.AddModelError("NotEnabled", "The user is not enabled");
            }

            if (ModelState.IsValid)
            {
                FormsAuthentication.SetAuthCookie(model.UserName, true);
                return RedirectToLocal(returnUrl);
            }

            return View(model);
        }