bool wantToRegister = false;//allow user to create a client account and check if all data are valid private void Register_Click(object sender, RoutedEventArgs e) { LogIn.Visibility = Visibility.Collapsed; if (!wantToRegister) { ConfirmPassword.Visibility = Visibility.Visible; wantToRegister = true; tBValidation.Text = "Enter your data.."; tBValidation.Foreground = new SolidColorBrush(Colors.LightGreen); } else if (password.Text == tBConfirmPassword.Text) { if (!InterfaceManager.ValidPassword(password.Text)) { tBValidation.Foreground = new SolidColorBrush(Colors.Red); tBValidation.Text = "PassWord have to contain 8 characteres, upper and lower case"; } else if (!uCollect.IsUser(userName.Text)) { User temp = new User(AutorisationLevel.Client, userName.Text, tBConfirmPassword.Text); uCollect.AddUser(temp); tBValidation.Text = "Your account have been created.. you can login.."; tBValidation.Foreground = new SolidColorBrush(Colors.LightGreen); ConfirmPassword.Visibility = Visibility.Collapsed; ClearUI(); LogIn.Visibility = Visibility.Visible; wantToRegister = false; } else { tBValidation.Foreground = new SolidColorBrush(Colors.Red); tBValidation.Text = "An account already Exist with this username"; } } else { tBValidation.Foreground = new SolidColorBrush(Colors.Red); tBValidation.Text = "Your passwords are different"; } }
//Create a user private void createUser_Click(object sender, RoutedEventArgs e) { if (!InterfaceManager.ValidPassword(tBPasswordUser.Text)) { PasswordValidation.Foreground = new SolidColorBrush(Colors.Red); PasswordValidation.Text = "PassWord have to contain 8 characteres, upper and lower case"; return; } string password = tBPasswordUser.Text; if (_uCollect.IsUser(tBNameUser.Text)) { PasswordValidation.Foreground = new SolidColorBrush(Colors.Red); PasswordValidation.Text = "Username already exist. Chose another one..."; return; } string name = tBNameUser.Text; AutorisationLevel autoLevel; if (rBEmployee.IsChecked == true) { autoLevel = AutorisationLevel.Employee; } else if (rBManager.IsChecked == true) { autoLevel = AutorisationLevel.Manager; } else { PasswordValidation.Foreground = new SolidColorBrush(Colors.Red); PasswordValidation.Text = "Choose an autorisation Level"; return; } User tmp = new User(autoLevel, name, password); _uCollect.AddUser(tmp); PasswordValidation.Foreground = new SolidColorBrush(Colors.Green); PasswordValidation.Text = "User Created"; ClearUIData(); }