public IActionResult Register(UserVM model) { if (!ModelState.IsValid) { return(View("Index", model)); } UserAccounts user = new UserAccounts(); user.Active = true; user.RegistrationDate = DateTime.Now; user.Username = model.Username; user.PasswordSalt = GeneratePassword.GenerateSalt(); user.PasswordHash = GeneratePassword.GenerateHash(model.Password, user.PasswordSalt); userRepository.InsertUser(user); userRepository.Save(); Clients client = new Clients(); client.Email = model.Email; client.FirstName = model.FirstName; client.LastName = model.LastName; client.UserId = user.Id; clientRepository.InsertClient(client); clientRepository.Save(); return(RedirectToAction("Index", "Autentification")); }
public IActionResult Save(MuseumVM museum) { if (!ModelState.IsValid) { museum.MuseumType = new SelectList(museumtypeRepository.GetMuseumTypes(), "Id", "Name").ToList(); return(View("Add", museum)); } UserAccounts u = new UserAccounts(); if (museum.PasswordHash == museum.PasswordSalt) { string password = museum.PasswordHash; u.PasswordSalt = GeneratePassword.GenerateSalt(); u.PasswordHash = GeneratePassword.GenerateHash(password, u.PasswordSalt); u.Username = museum.Username; u.RegistrationDate = DateTime.Now; u.Active = true; userRepository.InsertUser(u); museumRepository.Save(); Museums m = new Museums(); m.MuseumTypeId = museum.MuseumTypeId; m.Name = museum.Name; m.UserId = u.Id; museumRepository.InsertMuseum(m); museumRepository.Save(); } return(RedirectToAction("Index")); }
public IActionResult Login(LoginVM login) { UserAccounts u = userRepository.GetUser(login.Username); string password; if (u == null) { TempData["Error"] = "You have entered an invalid username or password!"; return(RedirectToAction("Index", "Autentification")); } password = GeneratePassword.GenerateHash(login.Password, u.PasswordSalt); u = userRepository.GetUser(login.Username, password); if (u == null) { TempData["Error"] = "You have entered an invalid username or password!"; return(RedirectToAction("Index", "Autentification", login)); } HttpContext.SetLoggedUser(u, login.RememberPassword); return(RedirectToAction("Index", "Home", new { area = "" })); }
public IActionResult Edit(MuseumVM museum) { if (!ModelState.IsValid) { museum.MuseumType = new SelectList(museumtypeRepository.GetMuseumTypes(), "Id", "Name").ToList(); return(View("Edit", museum)); } UserAccounts u = userRepository.GetUserById(museum.UserId); if (museum.PasswordHash != null && museum.PasswordSalt != null) { if (museum.NewPassword == museum.RepeatPassword) { if (museum.NewPassword != null && museum.RepeatPassword != null) { string password = museum.NewPassword; u.PasswordSalt = GeneratePassword.GenerateSalt(); u.PasswordHash = GeneratePassword.GenerateHash(password, u.PasswordSalt); } else { u.PasswordHash = museum.PasswordHash; u.PasswordSalt = museum.PasswordSalt; } u.Username = museum.Username; userRepository.UpdateUser(u); museumRepository.Save(); Museums m = museumRepository.GetMuseum(museum.Id); m.MuseumTypeId = museum.MuseumTypeId; m.Name = museum.Name; m.UserId = u.Id; museumRepository.UpdateMuseum(m); museumRepository.Save(); } } return(RedirectToAction("Index")); }
public IActionResult UserEdit(UserAccounts user) { if (!ModelState.IsValid) { Administrators a = adminRepository.GetAdministrator(user.Id); return(View("Index", a)); } if (user.PasswordHash != null && user.PasswordSalt != null) { if (user.PasswordHash == user.PasswordSalt) { string password = user.PasswordHash; user.PasswordSalt = GeneratePassword.GenerateSalt(); user.PasswordHash = GeneratePassword.GenerateHash(password, user.PasswordSalt); userRepository.UpdateUser(user); userRepository.Save(); } } return(RedirectToAction("Profile", "User")); }