public ActionResult LogOn(string username, string password, int zoneId, int tableId) { if (this.User.Identity.IsAuthenticated == true) { return RedirectToAction("Index", "Client"); } UserService userService = new UserService(); User user = userService.Get(username); if (user == null) { ModelState.AddModelError("", "Le nom est incorrect."); return View(new LogOnViewModel()); } if (user.Password != password) { ModelState.AddModelError("", "Le mot de passe est incorrect."); return View(new LogOnViewModel()); } var cookie = GenerateCookie(user, tableId); this.Response.Cookies.Add(cookie); return RedirectToAction("Index", "Client"); }
public ActionResult AddUser(string name, string password) { if (string.IsNullOrWhiteSpace(name) == true || string.IsNullOrWhiteSpace(password) == true) { ModelState.AddModelError("", "Le nom et le mot de passe ne doivent pas être vides."); return View(); } UserService userService = new UserService(); User user = new User { Name = name, Password = password }; userService.AddUser(user); return RedirectToAction("ListUsers"); }
public ActionResult ListUsers() { UserService userService = new UserService(); List<User> users = userService.GetAll(); return View(users); }