Files
BeWoPlaner/BeWo/View/TwoFactorAuthMessageDialog.xaml.cs
2024-07-31 21:54:06 +02:00

92 lines
2.5 KiB
C#

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;
private bool showCodeField = true;
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;
}
public bool ShowCodeField { get { return showCodeField; }
set
{
showCodeField = value;
if (!showCodeField)
{
textbox.Visibility = Visibility.Collapsed;
OkayButton.Visibility = Visibility.Collapsed;
CancelButton.Content = "OK";
}
}
}
private void CancelButton_OnClick(object sender, RoutedEventArgs e)
{
DialogResult = !showCodeField;
}
private void OkayButton_OnClick(object sender, RoutedEventArgs e)
{
var result = ServiceFacade.DoUserServiceSync(u => u.IsUserValidTwoFactor(this.username, this.password, textbox.Text, null));
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));
}
}
}
}