2021-02-21 19:01:51 +01:00
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 ;
2021-02-22 10:14:07 +01:00
using BS.Shared.Translation ;
2021-02-21 19:01:51 +01:00
using XamlReader = System . Windows . Markup . XamlReader ;
namespace BeWo.View
{
public partial class TwoFactorAuthMessageDialog
{
2021-02-22 10:14:07 +01:00
private String username ;
private String password ;
public TwoFactorAuthMessageDialog ( String username , String password )
2021-02-21 19:01:51 +01:00
{
InitializeComponent ( ) ;
2021-02-22 10:14:07 +01:00
this . username = username ;
this . password = password ;
2021-02-21 19:01:51 +01:00
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 )
{
2021-02-22 10:14:07 +01:00
DialogResult = false ;
2021-02-21 19:01:51 +01:00
}
private void OkayButton_OnClick ( object sender , RoutedEventArgs e )
{
2021-02-22 10:14:07 +01:00
2024-06-24 16:30:36 +02:00
var result = ServiceFacade . DoUserServiceSync ( u = > u . IsUserValidTwoFactor ( this . username , this . password , textbox . Text , null ) ) ;
2021-02-22 10:14:07 +01:00
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 ) ) ;
}
2021-02-21 19:01:51 +01:00
}
}
}