示例#1
0
 public ActionResult LogOn(LogOnModel model, string returnUrl)
 {
     if (ModelState.IsValid)
     {
         if (CodeFirstSecurity.Login(model.UserName, model.Password, model.RememberMe))
         {
             if (!String.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl))
             {
                 return(Redirect(returnUrl));
             }
             else
             {
                 if (TempData["returnUrl"] != null)
                 {
                     string url = TempData["returnUrl"].ToString();
                     TempData.Remove("returnUrl");
                     return(Redirect(url));
                 }
                 else
                 {
                     return(RedirectToRoute("Default", new { controller = "Home", action = "Index" }));
                 }
             }
         }
         else
         {
             ModelState.AddModelError("", "El usuario o contraseña son incorrectos");
         }
     }
     return(View(model));
 }
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (CodeFirstSecurity.Login(model.UserName, model.Password))
                {
                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") &&
                        !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
示例#3
0
        public ActionResult Login(FormCollection collection, string returnUrl)
        {
            string userMail, userPwd;

            userMail = collection["email"];
            userPwd  = collection["password"];
            bool rememberMe = (collection["forgetPWD"] == "on" ? true : false);

            if (ModelState.IsValid)
            {
                if (CodeFirstSecurity.Login(userMail, userPwd, rememberMe))
                {
                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") &&
                        !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View());
        }