public ActionResult Login(LoginViewModel model) { Response.Cache.SetCacheability(HttpCacheability.NoCache); // admin login if (model.Username == ConfigurationManager.AppSettings["AdminUsername"]) { List<string> msg = AttemptToLoginAdmin(model.Password); if (msg == null) { CreateLoginAuthenticationTicket(model.Username); return Json(new { success = true }); } return Json(new { success = false, messages = msg }); } // standard login IEnumerable<string> result = _accountServices.ValidateLogin(model.Username, model.Password); if (result == null) { // credentials are good, authenticate the user CreateLoginAuthenticationTicket(model.Username); //Session["Username"] = model.Username; if (model.RememberMe) CreateRememberMeCookie(model.Username); return Json(new { success = true }); } // if we got this far, something failed, return a list of problems string[] msgs = result.ToArray(); return Json(new { success = false, messages = msgs }); }
public ActionResult Index(LoginViewModel model) { return View(LoadLoginViewModel()); }
private LoginViewModel LoadLoginViewModel() { var model = new LoginViewModel(); HttpCookie usernameCookie = Request.Cookies["userName"]; if (usernameCookie != null) model.Username = usernameCookie.Value; return model; }