/// <summary>Modifies a <see cref="User"/> in the database.</summary> private async Task ModifyUser() { AppState.CurrentUser.Username = TxtUsername.Text.Trim(); AppState.CurrentUser.FirstName = TxtFirstName.Text.Trim(); AppState.CurrentUser.LastName = TxtLastName.Text.Trim(); AppState.CurrentUser.Password = PswdPassword.Password.Length >= 4 ? PBKDF2.HashPassword(PswdPassword.Password.Trim()) : AppState.CurrentUser.Password; if (AppState.CurrentUser != OriginalUser) { if (AppState.CurrentUser.Roles.ToList().Count > 0) { if (await AppState.ChangeUserDetails(OriginalUser, AppState.CurrentUser).ConfigureAwait(false)) { Dispatcher.Invoke(() => AppState.GoBack()); } } else { AppState.DisplayNotification("There are no roles assigned to this User.", "Time Clock"); } } else { AppState.DisplayNotification("There are no changes to save.", "Time Clock"); } }
private async void BtnSubmit_Click(object sender, RoutedEventArgs e) { bool success = false; if (PBKDF2.ValidatePassword(PswdCurrentPassword.Password, Admin ? AppState.AdminPassword : AppState.CurrentUser.Password) && PswdNewPassword.Password == PswdConfirmPassword.Password && PswdCurrentPassword.Password != PswdNewPassword.Password) { if (Admin && await AppState.ChangeAdminPassword(PBKDF2.HashPassword(PswdNewPassword.Password)).ConfigureAwait(false)) { AppState.DisplayNotification("Successfully changed administrator password.", "Time Clock"); success = true; } else if (!Admin) { User newUser = new User(AppState.CurrentUser) { Password = PBKDF2.HashPassword(PswdNewPassword.Password) }; if (await AppState.ChangeUserDetails(AppState.CurrentUser, newUser).ConfigureAwait(false)) { AppState.DisplayNotification("Successfully changed user password.", "Time Clock"); AppState.CurrentUser.Password = newUser.Password; success = true; } } } else if (PswdCurrentPassword.Password == PswdNewPassword.Password) { AppState.DisplayNotification("The new password can't be the same as the current password.", "Time Clock"); PswdNewPassword.Focus(); } else if (PswdNewPassword.Password != PswdConfirmPassword.Password) { AppState.DisplayNotification("Please ensure the new passwords match.", "Time Clock"); PswdConfirmPassword.Focus(); } else { AppState.DisplayNotification("Invalid current password.", "Time Clock"); PswdCurrentPassword.Focus(); } if (success) { AppState.GoBack(); } }