//This method along with the AssignUserRole were just loose functions in the create method but we have extracted the to //reduce method bloat...which to be honest just makes things hard to read. This keeps things in a very obvious grouping. private string AssignName() { MenuClient <string> userStringClient = new MenuClient <string>(); userStringClient.Prompt = "Enter User name"; return(userStringClient.GetUserInput()); }
private void UserLogin(User userSelection) { MenuClient <string> stringClient = new MenuClient <string>(); stringClient.Prompt = "Please login with your password"; bool passwordValid = false; //Here we enter a while loop until a valid password is entered while (passwordValid == false) { //This is checking against the stringClient's method for receiving user input //If that return value is not equal to the password of the userSelection that //was passed into the method from the posterior method. if (stringClient.GetUserInput() != userSelection.Password) { //We tell you that you entered the wrong password. Console.WriteLine("Invalid password..."); } else { //Otherwise, the only alternative is that your entry is == userSelection.Password //then we assign your selection to the CurrentUser Property of the UserManager Current = userSelection; //and your password was true after all so... passwordValid = true; } } }
private string AssignPassword() { MenuClient <string> userStringClient = new MenuClient <string>(); userStringClient.Prompt = "Password"; bool passwordValid = false; string userPassword; while (!passwordValid) { userPassword = userStringClient.GetUserInput(); if (userPassword.Count() >= 8) { passwordValid = true; } return(userPassword); } throw new Exception("Password Invalid"); }
public override void Create() { MenuClient <string> userNameClient = new MenuClient <string>(); userNameClient.Prompt = "User name"; string userName = userNameClient.GetUserInput(); MenuClient <UserRole> userRoleClient = new MenuClient <UserRole>(); userRoleClient.Prompt = "What is your role?"; foreach (UserRole role in Enum.GetValues(typeof(UserRole)).Cast <UserRole>().ToList <UserRole>()) { userRoleClient.Selections.Add(role); } UserRole userRole = userRoleClient.GetUserSelection(); MenuClient <string> userPasswordClient = new MenuClient <string>() { Prompt = "Password" }; string userPassword = userPasswordClient.GetUserInput(); User newUser = new User(userName, userRole, userPassword); Contents.Add(newUser); Current = newUser; }