public ActionResult Login(LoginModel model) { if (ModelState.IsValid) { User user = service.GetUserByEmail(model.EmailAddress); if (user == null) { ModelState.AddModelError("", "Login failed"); return(View(model)); } if (!BCryptHelper.CheckPassword(model.Password, user.Password)) { ModelState.AddModelError("", "The password you entered does not match the password for your account"); return(View(model)); } if (user.IsActive == false) { ModelState.AddModelError("", "Your account has not been activated yet, please click the link in the verification email that was sent to you."); return(RedirectToAction("login")); } // write the login cookie, redirect. if (model.RememberMe) { CookieHelpers.WriteCookie("Amorlc", "uid", user.ID.ToString(), DateTime.Now.AddDays(30)); } else { CookieHelpers.WriteCookie("Amorlc", "uid", user.ID.ToString()); } if (TempData["returnUrl"] != null) { return(Redirect(TempData["returnUrl"].ToString())); } return(RedirectToAction("index", "home")); } return(View(model)); }