public ActionResult Auth(UserView user) { if (ModelState.IsValid) { var login = UoW.Repository<Blog.Data.Model.User>() .Get() .SingleOrDefault( x => x.Login.Equals(user.Login, StringComparison.OrdinalIgnoreCase) && x.Password.Equals(user.Password, StringComparison.OrdinalIgnoreCase)); if (login != null) { FormsAuthentication.SetAuthCookie(user.Login, false); return !String.IsNullOrWhiteSpace(user.UrlRegefer) ? (ActionResult) Redirect(user.UrlRegefer) : RedirectToAction("Index", "Blog"); } } else { ModelState.AddModelError("error", "не правильная комбинация логин/пароль"); } return RedirectToAction("Login", "User"); }
public ActionResult Login(string referUrl) { var referurl = Url.Action("Index", "Home"); if (HttpContext.Request.UrlReferrer != null) { referurl = HttpContext.Request.UrlReferrer.AbsoluteUri; } if (TempData[Constant.Backurl] != null ) { referurl = TempData[Constant.Backurl].ToString(); } if (HttpContext.User.Identity.IsAuthenticated) Redirect(referurl); var error = TempData["error"]; var uv = new UserView { SavePass = true, UrlRegefer = referurl}; if (error != null) { uv.Status = error.ToString(); } return View(uv); }