more
authorStricted <info@stricted.de>
Thu, 29 Oct 2015 08:34:44 +0000 (09:34 +0100)
committerStricted <info@stricted.de>
Thu, 29 Oct 2015 08:34:44 +0000 (09:34 +0100)
SpeedportHybridControl.Implementations/PasswordHelper.cs [new file with mode: 0644]
SpeedportHybridControl.Implementations/SpeedportHybridControl.Implementations.csproj
SpeedportHybridControl/App.xaml
SpeedportHybridControl/MainWindow.xaml
SpeedportHybridControl/Model/LoginPageModel.cs [new file with mode: 0644]
SpeedportHybridControl/SpeedportHybridControl.csproj
SpeedportHybridControl/model/MainWindowModel.cs
SpeedportHybridControl/page/LoginPage.xaml
SpeedportHybridControl/page/LoginPage.xaml.cs

diff --git a/SpeedportHybridControl.Implementations/PasswordHelper.cs b/SpeedportHybridControl.Implementations/PasswordHelper.cs
new file mode 100644 (file)
index 0000000..8782491
--- /dev/null
@@ -0,0 +1,83 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+
+namespace SpeedportHybridControl.Implementations {
+       public static class PasswordHelper {
+               public static readonly DependencyProperty PasswordProperty =
+                       DependencyProperty.RegisterAttached("Password",
+                       typeof(string), typeof(PasswordHelper),
+                       new FrameworkPropertyMetadata(string.Empty, OnPasswordPropertyChanged));
+
+               public static readonly DependencyProperty AttachProperty =
+                       DependencyProperty.RegisterAttached("Attach",
+                       typeof(bool), typeof(PasswordHelper), new PropertyMetadata(false, Attach));
+
+               private static readonly DependencyProperty IsUpdatingProperty =
+                  DependencyProperty.RegisterAttached("IsUpdating", typeof(bool),
+                  typeof(PasswordHelper));
+
+
+               public static void SetAttach (DependencyObject dp, bool value) {
+                       dp.SetValue(AttachProperty, value);
+               }
+
+               public static bool GetAttach (DependencyObject dp) {
+                       return (bool)dp.GetValue(AttachProperty);
+               }
+
+               public static string GetPassword (DependencyObject dp) {
+                       return (string)dp.GetValue(PasswordProperty);
+               }
+
+               public static void SetPassword (DependencyObject dp, string value) {
+                       dp.SetValue(PasswordProperty, value);
+               }
+
+               private static bool GetIsUpdating (DependencyObject dp) {
+                       return (bool)dp.GetValue(IsUpdatingProperty);
+               }
+
+               private static void SetIsUpdating (DependencyObject dp, bool value) {
+                       dp.SetValue(IsUpdatingProperty, value);
+               }
+
+               private static void OnPasswordPropertyChanged (DependencyObject sender,
+                       DependencyPropertyChangedEventArgs e) {
+                       PasswordBox passwordBox = sender as PasswordBox;
+                       passwordBox.PasswordChanged -= PasswordChanged;
+
+                       if (!(bool)GetIsUpdating(passwordBox)) {
+                               passwordBox.Password = (string)e.NewValue;
+                       }
+                       passwordBox.PasswordChanged += PasswordChanged;
+               }
+
+               private static void Attach (DependencyObject sender,
+                       DependencyPropertyChangedEventArgs e) {
+                       PasswordBox passwordBox = sender as PasswordBox;
+
+                       if (passwordBox == null)
+                               return;
+
+                       if ((bool)e.OldValue) {
+                               passwordBox.PasswordChanged -= PasswordChanged;
+                       }
+
+                       if ((bool)e.NewValue) {
+                               passwordBox.PasswordChanged += PasswordChanged;
+                       }
+               }
+
+               private static void PasswordChanged (object sender, RoutedEventArgs e) {
+                       PasswordBox passwordBox = sender as PasswordBox;
+                       SetIsUpdating(passwordBox, true);
+                       SetPassword(passwordBox, passwordBox.Password);
+                       SetIsUpdating(passwordBox, false);
+               }
+       }
+}
index e2cfa21661fd3d3f09a239025b131cade3e6934c..ecba430c1ede443869682e62966b8836b49e7de8 100644 (file)
@@ -39,6 +39,7 @@
       <Private>True</Private>
     </Reference>
     <Reference Include="PresentationCore" />
+    <Reference Include="PresentationFramework" />
     <Reference Include="System" />
     <Reference Include="System.Core" />
     <Reference Include="System.Xml.Linq" />
     <Reference Include="System.Data" />
     <Reference Include="System.Net.Http" />
     <Reference Include="System.Xml" />
+    <Reference Include="WindowsBase" />
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Cryptography.cs" />
     <Compile Include="DelegateCommand.cs" />
     <Compile Include="LogManager.cs" />
+    <Compile Include="PasswordHelper.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="SingletonFactory.cs" />
     <Compile Include="sjcl.cs" />
index 6a27a044bb51a79327ae23bc6058acc5615dab45..40e8a085aeaa74d85f6fe4768184be65db62a353 100644 (file)
@@ -7,7 +7,8 @@
     <Application.Resources>
         <ResourceDictionary>
             <model:MainWindowModel x:Key="MainWindowModel"></model:MainWindowModel>
-                       
+            <model:LoginPageModel x:Key="LoginPageModel"></model:LoginPageModel>
+            
             <model:Status x:Key="Status"></model:Status>
             <model:LTE x:Key="LTE"></model:LTE>
             <model:LTE x:Key="LTE2"></model:LTE>
index 2fe46ad318da8c0c354dbc92597b26ca0987fe5c..15b3040211048978b2eeb7a7aace72287cd11fa8 100644 (file)
@@ -21,7 +21,7 @@
                 </Style>
             </StackPanel.Resources>
 
-            <Button Command="{Binding Path=SwitchToLoginPage}" Background="{Binding Path=ButtonLoginPageBackground}" x:Name="btnLogin" Content="Login"/>
+            <Button Command="{Binding Path=SwitchToLoginPage}" Background="{Binding Path=ButtonLoginPageBackground}" x:Name="btnLogin" Content="{Binding Path=LoginButtonContent}"/>
             <Button Command="{Binding Path=SwitchToStatusPage}" Background="{Binding Path=ButtonStatusPageBackground}" Click="button_click" x:Name="btnStatus" Content="Status"/>
             <Button Command="{Binding Path=SwitchToOverviewPage}" IsEnabled="{Binding Path=ButtonOverviewPageIsActive}" Background="{Binding Path=ButtonOverviewPageBackground}"  x:Name="btnOverview" Content="Overview"/>
             <Button Command="{Binding Path=SwitchToDSLPage}" IsEnabled="{Binding Path=ButtonDSLPageIsActive}" Background="{Binding Path=ButtonDSLPageBackground}" x:Name="btnDsl" Content="DSL"/>
diff --git a/SpeedportHybridControl/Model/LoginPageModel.cs b/SpeedportHybridControl/Model/LoginPageModel.cs
new file mode 100644 (file)
index 0000000..a1589c3
--- /dev/null
@@ -0,0 +1,72 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SpeedportHybridControl.Implementations;
+
+namespace SpeedportHybridControl.Model {
+       class LoginPageModel : SuperViewModel {
+               private string _ip = "speedport.ip";
+               private string _password;
+               private bool _showPassword;
+               private bool _savePassword;
+
+               private DelegateCommand _showPasswordCommand;
+               private DelegateCommand _savePasswordCommand;
+               private DelegateCommand _loginCommand;
+
+               public string ip {
+                       get { return _ip; }
+                       set { SetProperty(ref _ip, value); }
+               }
+
+               public string password {
+                       get { return _password; }
+                       set { SetProperty(ref _password, value); }
+               }
+
+               public bool ShowPassword {
+                       get { return _showPassword; }
+                       set { SetProperty(ref _showPassword, value); }
+               }
+
+               public bool SavePassword {
+                       get { return _savePassword; }
+                       set { SetProperty(ref _savePassword, value); }
+               }
+
+               public DelegateCommand ShowPasswordCommand {
+                       get { return _showPasswordCommand; }
+                       set { SetProperty(ref _showPasswordCommand, value); }
+               }
+
+               public DelegateCommand SavePasswordCommand {
+                       get { return _savePasswordCommand; }
+                       set { SetProperty(ref _savePasswordCommand, value); }
+               }
+
+               public DelegateCommand LoginCommand {
+                       get { return _loginCommand; }
+                       set { SetProperty(ref _loginCommand, value); }
+               }
+
+               private void OnShowPasswordCommandExecute () {
+                       Console.WriteLine(ShowPassword);
+               }
+
+               private void OnSavePasswordCommandExecute () {
+                       Console.WriteLine(SavePassword);
+               }
+
+               private void OnLoginCommandExecute () {
+                       Console.WriteLine(password);
+               }
+
+               public LoginPageModel () {
+                       ShowPasswordCommand = new DelegateCommand(new Action(OnShowPasswordCommandExecute));
+                       SavePasswordCommand = new DelegateCommand(new Action(OnSavePasswordCommandExecute));
+                       LoginCommand = new DelegateCommand(new Action(OnLoginCommandExecute));
+               }
+       }
+}
index ac9adf87892f266fc59bdf403505ea7709efac60..96aa70429da2fbfe615b4f2d8dbd33f6a15679a0 100644 (file)
@@ -65,6 +65,7 @@
     <Compile Include="Model\bonding_client.cs" />
     <Compile Include="Model\DeviceViewModel.cs" />
     <Compile Include="Model\DSLViewModel.cs" />
+    <Compile Include="Model\LoginPageModel.cs" />
     <Compile Include="Model\LTEViewModel.cs" />
     <Compile Include="Model\MainWindowModel.cs" />
     <Compile Include="Model\OverviewModel.cs" />
index 044786c38b7ad16c6d1af8d0bae510891c054a4c..51731e56ded0b1a1da27ad48d0d13399279be060 100644 (file)
@@ -6,6 +6,8 @@ using System.Windows.Media;
 
 namespace SpeedportHybridControl.Model {
        class MainWindowModel : SuperViewModel {
+               private string _loginButtonContent = "Login";
+
                private DelegateCommand _switchToLoginPage;
                private DelegateCommand _switchToStatusPage;
                private DelegateCommand _switchToOverviewPage;
@@ -41,6 +43,11 @@ namespace SpeedportHybridControl.Model {
 
                private Page _FrameSource;
 
+               public string LoginButtonContent {
+                       get { return _loginButtonContent; }
+                       set { SetProperty(ref _loginButtonContent, value); }
+               }
+
                public DelegateCommand SwitchToLoginPage {
                        get { return _switchToLoginPage; }
                        set { SetProperty(ref _switchToLoginPage, value); }
index 96adba30d1dbc9579a6d15d2a83bd2a58a122948..0dbb90403f08f511fee43642685d3c40d78d988b 100644 (file)
@@ -4,20 +4,21 @@
       xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
       xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
       xmlns:local="clr-namespace:SpeedportHybridControl"
+      xmlns:Implementations="clr-namespace:SpeedportHybridControl.Implementations;assembly=SpeedportHybridControl.Implementations"
       mc:Ignorable="d"
       Loaded="loaded"
       Width="Auto" Height="Auto"
       Title="LoginPage">
 
-    <Grid>
+    <Grid DataContext="{StaticResource LoginPageModel}">
         <TextBlock x:Name="diTextBlock" HorizontalAlignment="Left" Margin="51,21,0,0" TextWrapping="Wrap" Text="Domain/IP:" VerticalAlignment="Top"/>
-        <TextBox x:Name="tbip" HorizontalAlignment="Left" Height="23" Margin="115,14,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
+        <TextBox Text="{Binding Path=ip, Mode=TwoWay}" x:Name="tbip" HorizontalAlignment="Left" Height="23" Margin="115,14,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
 
         <TextBlock x:Name="tbpw" Text="Passwort:" HorizontalAlignment="Left" Margin="55,49,0,0" VerticalAlignment="Top" />
-        <PasswordBox x:Name="PasswordBox" HorizontalAlignment="Left" Height="23" Margin="115,42,0,0" VerticalAlignment="Top" Width="120" ForceCursor="True"/>
-        <TextBox x:Name="PasswordTextBox" HorizontalAlignment="Left" Height="23" Margin="115,42,0,0" VerticalAlignment="Top" Width="120" Visibility="Hidden"/>
-        <CheckBox x:Name="PasswordCheckBox" Content="Passwort anzeigen" Margin="240,50,0,0" Checked="CheckBox" Unchecked="CheckBox" HorizontalAlignment="Left" VerticalAlignment="Top" />
-        <CheckBox x:Name="cbSave" Content="Passwort speichern" Margin="240,65,0,0" Checked="CheckBox" Unchecked="CheckBox" HorizontalAlignment="Left" VerticalAlignment="Top" />
-        <Button x:Name="button1" Content="Login" HorizontalAlignment="Left" Margin="115,70,0,0" VerticalAlignment="Top" Width="75" Click="button_click" IsDefault="True"/>
+        <PasswordBox Implementations:PasswordHelper.Attach="True" Implementations:PasswordHelper.Password="{Binding Path=password, Mode=TwoWay}"  x:Name="PasswordBox" HorizontalAlignment="Left" Height="23" Margin="115,42,0,0" VerticalAlignment="Top" Width="120" ForceCursor="True" />
+        <TextBox Text="{Binding Path=password, Mode=TwoWay}" x:Name="PasswordTextBox" HorizontalAlignment="Left" Height="23" Margin="115,42,0,0" VerticalAlignment="Top" Width="120" Visibility="Hidden"/>
+        <CheckBox Command="{Binding Path=ShowPasswordCommand}" IsChecked="{Binding Path=ShowPassword, Mode=TwoWay}" x:Name="PasswordCheckBox" Content="Passwort anzeigen" Margin="240,50,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" />
+        <CheckBox Command="{Binding Path=SavePasswordCommand}" IsChecked="{Binding Path=SavePassword, Mode=TwoWay}"  x:Name="cbSave" Content="Passwort speichern" Margin="240,65,0,0" Checked="CheckBox" Unchecked="CheckBox" HorizontalAlignment="Left" VerticalAlignment="Top" />
+        <Button Command="{Binding Path=LoginCommand}" x:Name="button1" Content="Login" HorizontalAlignment="Left" Margin="115,70,0,0" VerticalAlignment="Top" Width="75" IsDefault="True"/>
     </Grid>
 </Page>
index d20cc4d858532247ad98723211643ce12f7a54fe..41d52a75a8e7f63de5bd36917a78a96f20ee9589 100644 (file)
@@ -1,6 +1,8 @@
 using System.Windows;
 using System.Windows.Controls;
 using System.Threading;
+using System;
+using SpeedportHybridControl.Model;
 
 namespace SpeedportHybridControl.page {
        /// <summary>