Files
BeWoPlaner/BeWo/View/TwoFactorAuthMessageDialog.xaml.cs
2021-02-21 19:01:51 +01:00

108 lines
3.2 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 XamlReader = System.Windows.Markup.XamlReader;
namespace BeWo.View
{
public partial class TwoFactorAuthMessageDialog
{
public TwoFactorAuthMessageDialog()
{
InitializeComponent();
DataContext = this;
OkayButton.IsDefault = true;
CancelButton.IsDefault = false;
}
public TwoFactorAuthMessageDialog(Action pAfterPasswordConfirmationCallBack)
{
IsInConfirmationWithPasswordMode = true;
AfterPasswordConfirmationCallBack = pAfterPasswordConfirmationCallBack;
InitializeComponent();
DataContext = this;
OkayButton.IsDefault = true;
CancelButton.IsDefault = false;
}
public Action AfterPasswordConfirmationCallBack { get; set; }
public bool IsInConfirmationWithPasswordMode { get; set; }
private ICommand _OpenBrowserCommand;
public ICommand OpenBrowserCommand => _OpenBrowserCommand ?? (_OpenBrowserCommand = new OpenBrowserCommandImpl());
public class OpenBrowserCommandImpl : ICommand
{
public bool CanExecute(object parameter)
{
return true;
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
if (parameter != null)
{
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(parameter.ToString()));
}
}
}
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 = true;
Close();
}
private void OkayButton_OnClick(object sender, RoutedEventArgs e)
{
//var result = ServiceFacade.DoUserServiceSync(u => u.IsUserValid(BeWoApp.UserName, PasswordBox.Password, null), result =>
//{
// if(result == UserValidationResult.UserValid)
// {
// AfterPasswordConfirmationCallBack?.Invoke();
// this.Dispatch(Close);
// }
// else
// {
// MessageBox.Show("Anmeldeinformationen nicht bekannt. Bitte überprüfen Sie den Benutzernamen und das Passwort!", "Fehler bei der Anmeldung", MessageBoxButton.OK, MessageBoxImage.Exclamation);
// }
//}, true);
}
}
}