public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { User user = null; using (EFDbUserContext db = new EFDbUserContext()) { user = db.Users.FirstOrDefault(u => u.Email == model.Name); } if (user == null) { using (EFDbUserContext db = new EFDbUserContext()) { db.Users.Add(new User { Email = model.Name, Password = model.Password, RoleId = 2 }); db.SaveChanges(); user = db.Users.Where(u => u.Email == model.Name && u.Password == model.Password).FirstOrDefault(); } if (user != null) { FormsAuthentication.SetAuthCookie(model.Name, true); return(RedirectToAction("List", "Game")); } } else { ModelState.AddModelError("", "User with this login already exists..."); } } return(View(model)); }
public ActionResult Login(LoginModel model) { if (ModelState.IsValid) { User user = null; using (EFDbUserContext db = new EFDbUserContext()) { user = db.Users.FirstOrDefault(u => u.Email == model.Name && u.Password == model.Password); } if (user != null) { FormsAuthentication.SetAuthCookie(model.Name, true); return(RedirectToAction("List", "Game")); } else { ModelState.AddModelError("", "User with this login isn't exist..."); } } return(View(model)); }