private void CreateNew(Pwds pwds) { try { if (pwds.Pb1.Password != pwds.Pb2.Password) { throw new Exception("Passwords do not match"); } if (!emailMatch.IsMatch(NewUser.Email) && !String.IsNullOrEmpty(NewUser.Email)) { throw new Exception("Email does not have required format"); } NewUser.SetPlainTextPassword(pwds.Pb1.Password); UserRepository.Create(NewUser.Username, NewUser); TcoAppDomain.Current.Logger.Information($"New user '{NewUser.Username}' created. {{@sender}}", new { UserName = NewUser.Username, Roles = NewUser.Roles }); UsersChanged(); ClearFields(pwds); } catch (Exception ex) { MessageBox.Show($"Error creating new user: '******'", "Failed to create user", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void ClearFields(Pwds p) { NewUser.Username = string.Empty; NewUser.Email = string.Empty; NewUser.CanUserChangePassword = false; NewUser.Roles.Clear(); p.Pb1.Password = string.Empty; p.Pb2.Password = string.Empty; AllRolesFiltered.ReplaceWith(AllRoles.Select(x => x.Name).ToList()); }