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

            // Появление этого сообщения означает наличие ошибки; повторное отображение формы
            ModelState.AddModelError("", "Имя пользователя или пароль указаны неверно.");
            return View(model);
        }
 public ActionResult Login(LoginModel model, string returnUrl)
 {
     if (ModelState.IsValid){
         if(!WebSecurity.UserExists(model.UserName)) {
             ModelState.AddModelError("", "存在しないユーザー名です。");
         } else if (!WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)) {
             ModelState.AddModelError("", "パスワードが違います。");
         } else {
             return RedirectToLocal(returnUrl);
         }
     }
     return View(model);
 }
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (Membership.ValidateUser(model.UserName, model.Password))
            {
                var x = true;
            }

            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);
        }
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (Membership.ValidateUser(model.UserName, model.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    if (Url.IsLocalUrl(returnUrl))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index", "Home");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "提供的用户名或密码不正确。");
                }
            }

            // 如果我们进行到这一步时某个地方出错,则重新显示表单
            return View(model);
        }
        public JsonResult JsonLogin(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    return Json(new { success = true, redirect = returnUrl });
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed
            return Json(new { errors = GetErrorsFromModelState() });
        }
 public ActionResult Login(LoginModel model, string returnUrl)
 {
     if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
     {
         return PartialView("~/Views/Shared/_LoginPartial.cshtml", model);
         //return RedirectToLocal(returnUrl);
     }
     string message = "test";
     // If we got this far, something failed, redisplay form
     ModelState.AddModelError("", "The user name or password provided is incorrect.");
     return Content("<span>error</span>", "text/html");
     //return View(model);
 }