using System; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Xaml; using BeWo.ServiceProxy; using BS.Shared; using BS.Shared.Extensions; using BS.Shared.Translation; using XamlReader = System.Windows.Markup.XamlReader; namespace BeWo.View { public partial class TwoFactorAuthMessageDialog { private String username; private String password; public TwoFactorAuthMessageDialog(String username, String password) { InitializeComponent(); this.username = username; this.password = password; DataContext = this; OkayButton.IsDefault = true; CancelButton.IsDefault = false; } public void SetXaml(string xamlCode) { try { if(XamlReader.Parse(xamlCode) is UIElement element) { txtMessage.Visibility = Visibility.Collapsed; rootGrid.Children.Add(element); } } catch(Exception e) { //ignore } } public string Message { get => txtMessage.Text; set => txtMessage.Text = value; } private void CancelButton_OnClick(object sender, RoutedEventArgs e) { DialogResult = false; } private void OkayButton_OnClick(object sender, RoutedEventArgs e) { var result = ServiceFacade.DoUserServiceSync(u => u.IsUserValidTwoFactor(this.username, this.password, null, textbox.Text)); if (result == UserValidationResult.UserValid) { BeWoApp.TwoFactorPin = textbox.Text; DialogResult = true; } else { MessageBox.Show(Translator.Translate("Unbekannter Code. Bitte versuchen Sie es erneut!", "Fehler bei der Anmeldung", MessageBoxButton.OK, MessageBoxImage.Exclamation)); } } } }