private async void InitializeWindow() { // Gets the desktoplanguages _languageList = (await _languageRepo.GetAllAsync()).Where(l => l.IsDesktopLanguage == true).ToList(); // Checks whether the languageList contains the desktopLanguages bool listContainsDesktopLanguages = _languageList.Any(l => l.LocalName == "Nederlands") && _languageList.Any(l => l.LocalName == "English"); NewDesktopUser = new DesktopUser() { IsAdmin = false, VerifiedByAdmin = false, Salt = Encryption.GetNewSalt(32) }; // If the languageList contains the necessary DesktopLanguages, choose dutch per default if (!listContainsDesktopLanguages) { rbPreferNL.IsChecked = true; // If it doesnt contain the desktopLanguages, collapse the selector, so the preferredLanguageID will remain null languageSelector.Visibility = Visibility.Collapsed; lblPrefLang.Visibility = Visibility.Collapsed; } // Selects the radiobutton for the language that the user selected in the login screen SelectRadioButtonByLanguage(); DataContext = this; }
private async void InitializeUserControl() { // Gets the current user _currentUser = await _userRepo.GetAsync(Properties.Settings.Default.CurrentUser.ID); // Puts the current user in a global accessible variable Properties.Settings.Default.CurrentUser = _currentUser; // Gets all the languages _languageList = (await _languageRepo.GetAllAsync()).Where(l => l.IsDesktopLanguage == true).ToList(); // Checks whether the database already contains the 2 default display languages listContainsDesktopLanguages = _languageList.Any(l => l.LocalName == "Nederlands") && _languageList.Any(l => l.LocalName == "English"); // If the desktop languages exist yet... if (listContainsDesktopLanguages) { // ... But the user has no preferred Language yet, select Dutch if (_currentUser.PreferredLanguageID == null) { rbPreferNL.IsChecked = true; } // ... And the user has a preferred language, select its preferred language else { SelectRadioButtonByLanguage(); } } // Else, hide the selector else { languageSelector.Visibility = Visibility.Collapsed; } }
private async void btnSave_Click(object sender, RoutedEventArgs e) { try { // Encrypts the user password NewDesktopUser.EncryptedPassword = Encryption.EncryptPassword(NewDesktopUser.Salt, pwdPassword.Password); try { // Create new user NewDesktopUser = _userRepo.Add(NewDesktopUser); await _userRepo.SaveChangesAsync(); } catch (Exception) { MessageBox.Show(LangResource.ErrSaveFailedContent, LangResource.ErrSaveFailedTitle); NewDesktopUser.EncryptedPassword = null; pwdPassword.Password = null; } // Opens up the mainwindow NavigationWindow naviWindow = new NavigationWindow(NewDesktopUser.ID); naviWindow.Show(); this.Close(); } catch (Exception) { // TODO ERROR MESSAGE pwdPassword.Password = null; throw; } }
private async void btnSave_Click(object sender, RoutedEventArgs e) { try { // Encrypts the user password NewDesktopUser.EncryptedPassword = Encryption.EncryptPassword(NewDesktopUser.Salt, pwdPassword.Password); // Create the new user NewDesktopUser = _userRepo.Add(NewDesktopUser); await _userRepo.SaveChangesAsync(); SendMailToAdmin(); SendMailToNewUser(); LoginWindow login = new LoginWindow(); login.Show(); MessageBox.Show(LangResource.NewAccountMadeInfo); this.Close(); } catch (UsernameTaken) { MessageBox.Show(LangResource.UsernameIsTaken); pwdPassword.Password = null; } catch (Exception) { pwdPassword.Password = null; MessageBox.Show(LangResource.ErrSaveFailedContent, LangResource.ErrSaveFailedTitle); } }
public async Task <int?> Authenticate() { DesktopUser loginUser = await _repo.FindByUsernameAsync(this.Username); if (loginUser == null) { return(null); } string encryptedPassword = Encryption.EncryptPassword(loginUser.Salt, this.Password); if (loginUser.VerifiedByAdmin) { if (loginUser.EncryptedPassword == encryptedPassword) { return(loginUser.ID); } else { return(null); } } else { return(0); } }
private void InitializeWindow(int userID) { // Gets the user based on the user id sent by the login screen _currentUser = _userRepo.Get(userID); // Puts the user in global accessible settings Properties.Settings.Default.CurrentUser = _currentUser; // Gets the language based on the preferrence of the user _preferredLanguage = _currentUser.PreferredLanguage; // Enable the user tab if the current user is the admin EnableUserTab(); // Sets the display language SetLanguageDictionary(); }
private async void ApplySettings(DesktopUser desktopUser) { // Sets the preferredLanguage based on the one chosen in the settings page _preferredLanguage = await _langRepo.GetAsync((int)desktopUser.PreferredLanguageID); SetLanguageDictionary(); foreach (ContentControl contentControl in UserControls.Children) { contentControl.Content = null; } menuOrderOverview(null, null); }
public AdminUserForm() { InitializeComponent(); NewDesktopUser = new DesktopUser() { IsAdmin = true, VerifiedByAdmin = true, Salt = Encryption.GetNewSalt(32) }; _languageRepo = new LanguageRepository(); _userRepo = new DesktopUserRepository(); InitializeWindow(); }
private void MakeAdmin(object sender, RoutedEventArgs e) { try { SetLanguageDictionary(); DesktopUser newAdmin = ((FrameworkElement)sender).DataContext as DesktopUser; string messageboxContent = String.Format(LangResource.MBContentMakeUserAdmin, newAdmin.FullName); string messageboxTitle = String.Format(LangResource.MBTitleMakeUserAdmin, newAdmin.FullName); MessageBoxManager.Yes = LangResource.Yes; MessageBoxManager.No = LangResource.No; MessageBoxManager.Register(); if (MessageBox.Show(messageboxContent, messageboxTitle, MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { _userRepo.AssignNewAdmin(newAdmin); _userRepo.SaveChangesAsync(); LoginWindow login = new LoginWindow(); login.Show(); NavigationWindow win = (NavigationWindow)Window.GetWindow(this); win.Close(); MessageBoxManager.Unregister(); } else { MessageBoxManager.Unregister(); } } catch (Exception) { MessageBox.Show(LangResource.ErrUpdateOverviewFailed); MessageBoxManager.Unregister(); } }
private void SendMailToAdmin() { // Builds the email to the admin DesktopUser admin = _userRepo.GetAllQueryable().SingleOrDefault(du => du.IsAdmin == true); string title = "TODO Title"; string content = "TODO Content"; if (admin.PreferredLanguage != null) { switch (_preferredLanguage.LocalName) { case "Nederlands": title = $"{NewDesktopUser.ToString()} heeft een account aangemaakt"; content = $"Beste {admin.ToString()}, \r\n" + "\r\n" + $"{NewDesktopUser.ToString()} (gebruikersnaam: {NewDesktopUser.Username} ; e-mail: {NewDesktopUser.Email} ) heeft een account aangemaakt om toegang te krijgen tot de applicatie. \r\n" + $"Als u {NewDesktopUser.ToString()} toegang wil geven tot de applicatie, gelieve dan in te loggen en onder 'Beheer Gebruikers' de nieuwe gebruiker toegang te verlenen \r\n" + "\r\n" + "Met vriendelijke groeten, \r\n" + "Rudycommerce"; break; case "English": title = $"{NewDesktopUser.ToString()} has made an account"; content = $"Dear {admin.ToString()}, \r\n" + "\r\n" + $"{NewDesktopUser.ToString()} (username: {NewDesktopUser.Username} ; email: {NewDesktopUser.Email} ) has made an account to gain access to the application. \r\n" + $"If you want to give {NewDesktopUser.ToString()} access to the application, please log in and give the new user access within the 'Manage Users' page. \r\n" + "\r\n" + "With kind regards, \r\n" + "Rudycommerce"; break; default: title = $"{NewDesktopUser.ToString()} heeft een account aangemaakt"; content = $"Beste {admin.ToString()}, \r\n" + "\r\n" + $"{NewDesktopUser.ToString()} (gebruikersnaam: {NewDesktopUser.Username} ; e-mail: {NewDesktopUser.Email} ) heeft een account aangemaakt om toegang te krijgen tot de applicatie. \r\n" + $"Als u {NewDesktopUser.ToString()} toegang wil geven tot de applicatie, gelieve dan in te loggen en onder 'Beheer Gebruikers' de nieuwe gebruiker toegang te verlenen \r\n" + "\r\n" + "Met vriendelijke groeten, \r\n" + "Rudycommerce"; break; } } else { title = $"{NewDesktopUser.ToString()} heeft een account aangemaakt"; content = $"Beste {admin.ToString()}, \r\n" + "\r\n" + $"{NewDesktopUser.ToString()} (gebruikersnaam: {NewDesktopUser.Username} ; e-mail: {NewDesktopUser.Email} ) heeft een account aangemaakt om toegang te krijgen tot de applicatie. \r\n" + $"Als u {NewDesktopUser.ToString()} toegang wil geven tot de applicatie, gelieve dan in te loggen en onder 'Beheer Gebruikers' de nieuwe gebruiker toegang te verlenen \r\n" + "\r\n" + "Met vriendelijke groeten, \r\n" + "Rudycommerce"; } _notifier.Notify(new MailAddress(admin.Email, admin.ToString()), title, content); }
private void SendMailToNewUser() { // Builds the mail to the new user DesktopUser user = NewDesktopUser; string adminEmail = _userRepo.GetAllQueryable().SingleOrDefault(du => du.IsAdmin == true).Email; string title = "TODO Title"; string content = "TODO Content"; if (_preferredLanguage != null) { switch (_preferredLanguage.LocalName) { case "Nederlands": title = $"Account aangemaakt bij Rudycommerce"; content = $"Beste {user.ToString()}, \r\n" + "\r\n" + $"Uw account (met gebruikersnaam '{user.Username}' is aangemaakt, maar nu moet u afwachten tot de beheerder van de applicatie u de toegansgrechten zal toekennen.\r\n" + $"Gelieve de applicatiebeheerder ({adminEmail}) te contacteren indien u te lang moet wachten.\r\n" + "\r\n" + "Met vriendelijke groeten, \r\n" + "Rudycommerce"; break; case "English": title = $"Account created for Rudycommerce"; content = $"Dear {user.ToString()}, \r\n" + "\r\n" + $"Your account (with username '{user.Username}' has been created, but now you will have to wait till the administrator gives you access rights to the application.\r\n" + $"Please contact the administrator ({adminEmail}) in case you have to wait too long.\r\n" + "\r\n" + "With kind regards, \r\n" + "Rudycommerce"; break; default: title = $"Account aangemaakt bij Rudycommerce"; content = $"Beste {user.ToString()}, \r\n" + "\r\n" + $"Uw account (met gebruikersnaam '{user.Username}' is aangemaakt, maar nu moet u afwachten tot de beheerder van de applicatie u de toegansgrechten zal toekennen.\r\n" + $"Gelieve de applicatiebeheerder ({adminEmail}) te contacteren indien u te lang moet wachten.\r\n" + "\r\n" + "Met vriendelijke groeten, \r\n" + "Rudycommerce"; break; } } else { title = $"Account aangemaakt bij Rudycommerce"; content = $"Beste {user.ToString()}, \r\n" + "\r\n" + $"Uw account (met gebruikersnaam '{user.Username}' is aangemaakt, maar nu moet u afwachten tot de beheerder van de applicatie u de toegansgrechten zal toekennen.\r\n" + $"Gelieve de applicatiebeheerder ({adminEmail}) te contacteren indien u te lang moet wachten.\r\n" + "\r\n" + "Met vriendelijke groeten, \r\n" + "Rudycommerce"; } _notifier.Notify(new MailAddress(user.Email, user.ToString()), title, content); }