public ActionResult LogOn(LogOnModel model, string returnUrl) { if (ModelState.IsValid) { string user = Membership.GetUserNameByEmail(model.UserName); if (user != null) model.UserName = user; if (Membership.ValidateUser(model.UserName, model.Password)&&(Session["Captcha"]==null||Session["Captcha"].ToString()==model.Captcha)) { string pass = model.Password; string nom = model.UserName; Session.Remove("conteo"); Session.Remove("Captcha"); BibliotecaDataContext con = new BibliotecaDataContext(); var fila= from f1 in con.aspnet_Memberships join f2 in con.aspnet_Users on f1.UserId equals f2.UserId where f2.UserName==nom select new{ ID=f1.UserId }; Session["userid"] = fila.ToArray()[0].ID; ViewBag.id = (Guid)Session["userid"]; FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return Redirect(returnUrl); } else { return RedirectToAction("Index", "Home"); } } else { if (Session["conteo"] == null) Session["conteo"] = 2; else { if (Session["conteo"].ToString() != "0") { String temp = Session["conteo"].ToString(); int t = Convert.ToInt16(temp) - 1; Session["conteo"] = t; } } ModelState.AddModelError("", "El usuario o password es incorrecto."); if (Convert.ToInt16(Session["conteo"]) == 0) { ModelState.AddModelError("", "No puedes seguir intentando"); Session["conteo"] = 0; } else { ModelState.AddModelError("", "Puedes intentar " + Session["conteo"] + " veces mas"); } ViewBag.x = Session["conteo"]; } } // If we got this far, something failed, redisplay form return View(model); }
public ActionResult LogOn(LogOnModel model, string returnUrl) { if (ModelState.IsValid) { string user = Membership.GetUserNameByEmail(model.UserName); if (user != null) model.UserName = user; if (Membership.ValidateUser(model.UserName, model.Password)&&(Session["Captcha"]==null||Session["Captcha"].ToString()==model.Captcha)) { Session.Remove("conteo"); Session.Remove("Captcha"); FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return Redirect(returnUrl); } else { return RedirectToAction("Index", "Home"); } } else { if (Session["conteo"] == null) Session["conteo"] = 2; else { if (Session["conteo"].ToString() != "0") { String temp = Session["conteo"].ToString(); int t = Convert.ToInt16(temp) - 1; Session["conteo"] = t; } } ModelState.AddModelError("", "El usuario o password es incorrecto."); if (Convert.ToInt16(Session["conteo"]) == 0) { ModelState.AddModelError("", "No puedes seguir intentando"); Session["conteo"] = 0; } else { ModelState.AddModelError("", "Puedes intentar " + Session["conteo"] + " veces mas"); } ViewBag.x = Session["conteo"]; } } // If we got this far, something failed, redisplay form return View(model); }
public ActionResult LogOn(LogOnModel model, string returnUrl) { if (ModelState.IsValid) { if (Membership.ValidateUser(model.UserName, model.Password)) { FormsAuthentication.SetAuthCookie(model.UserName, model.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(model); }