public ActionResult Login(Login model) { if (!ModelState.IsValid) { return(View(model)); } using (var context = new Entities.GvGenEntities()) { var entities = context.TUsers.Where(m => m.Name == model.Email && m.Password == model.Password).ToList(); if (entities.Count == 1) { var tickValue = string.Concat(entities[0].Id.ToString(), "|", DateTime.Now.ToFileTime()); var ticket = new FormsAuthenticationTicket(1, "userId", DateTime.Now, DateTime.Now.AddMinutes(30), false, tickValue); string token = System.Web.Security.FormsAuthentication.Encrypt(ticket); AccountHelper.Token = token; //new FormsAuthentication().SetAuthCookie(model.Email, model.RememberMe, ticketData); FormsAuthentication.SetAuthCookie(model.Email, model.RememberMe); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("Email", "Login failed. Email or Username is not existed"); } } return(View("login")); }
public bool Validate(Login model) { using (var context = new Entities.GvGenEntities()) { var entities = context.TUsers.Where(m => m.Name == model.Email && m.Password == model.Password).ToList(); if (entities.Count == 1) { FormsAuthentication.SetAuthCookie(model.Email, model.RememberMe); return(true); } return(false); } }