public ActionResult LogIn(LoginModel model) { if (ModelState.IsValid) { if (authService.CheckForm(model.ToAuthorizationEntity())) { FormsAuthentication.SetAuthCookie(model.Email, true); return RedirectToAction("Index", "Client"); } ModelState.AddModelError("", ""); } return View(model); }
public ActionResult SignIn(LoginModel loginModel) { if (ModelState.IsValid) { User user = new User(loginModel.Email, loginModel.Password); if (DependencyResolver.Current.GetService<IAuthenticationService>().Login(user, loginModel.RememberMe)) { _logger.Trace("User " + loginModel.Email + " login"); return RedirectToAction("Main", "Home"); } else { Response.StatusCode = (int)HttpStatusCode.BadRequest; return Content("Email or password is incorrect", MediaTypeNames.Text.Plain); } } else { _logger.Trace("User with email " + (loginModel.Email ?? "undefined") + " tried to sign in."); Response.StatusCode = (int)HttpStatusCode.BadRequest; return Content("Log in data is not valid", MediaTypeNames.Text.Plain); } }
public ActionResult Login(LoginModel model) { if (ModelState.IsValid) { var password = Common.CalculateMD5Hash(model.Password); var user = (from u in db.Users where u.Username == model.UserName && u.Password == password select u).FirstOrDefault(); if (user != null) { Session["UserType"] = (UserTypes)user.Type; Session["UserId"] = user.Id.ToString(); Session["UserName"] = user.Username; if (model.RememberMe) { var userData = Common.CalculateMD5Hash(DateTime.Now.ToString() + "VialpandoBlog" + "Na ezt találd ki hülye gyerek!"); string cookieName = "VialpandoBlogAuth"; HttpCookie myCookie = Request.Cookies[cookieName] ?? new HttpCookie(cookieName); myCookie.Values["UserId"] = user.Id.ToString(); myCookie.Values["UserData"] = userData; myCookie.Expires = DateTime.Now.AddDays(20); Response.Cookies.Add(myCookie); user.CookieHash = userData; db.SaveChanges(); } TempData["GlobalMessageType"] = MessageTypes.Success; TempData["ViewBag.GlobalHeader"] = Resources.Common.Success; TempData["ViewBag.GlobalMessage"] = Resources.Common.LoginMessage; return Redirect(Request.UrlReferrer.ToString()); } TempData["GlobalMessageType"] = MessageTypes.Error; TempData["ViewBag.GlobalHeader"] = Resources.Common.Error; TempData["ViewBag.GlobalMessage"] = Resources.Admin.Login.Error; } return Redirect(Request.UrlReferrer.ToString()); }
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); }