public ActionResult Create(string username, string password, string confirmpassword) { if (password != confirmpassword) { Error("Passordene er ikke like"); } if (_userRepository.UsernameExists(username)) { Error("Brukernavnet er tatt, velg et annet"); } if (password.Length < 7) { Error("Skjerpings, minst 7 bokstaver i passord"); } if (ErrorMessages.Any()) { return(View()); } var user = authUtil.CreateUser(username, password); _userRepository.Save(user); Info("Bruker opprettet"); return(RedirectToAction("Index", "Home")); }
public ActionResult Create(Employee employee) { var username = employee.SuggestUsername(); if (_userRepo.UsernameExists(username)) { var counter = 1; while (_userRepo.UsernameExists(username + counter)) { counter++; } username = username + counter; } _userRepo.Save(authUtil.CreateUser(username, AuthUtil.DEFAULT_PASSWORD)); Info("Ansatt ble opprettet"); Info("Brukernavn: " + username); Info("Passord: " + AuthUtil.DEFAULT_PASSWORD); var user = _userRepo.GetByUserName(username); employee.UserId = user.Id; _employeeRepo.Save(employee); return(RedirectToAction("Index")); }