Skip to content

Commit cb582eb

Browse files
committed
Dynamic view for the SignIn/SignUp by the configuration of /status api
1 parent 9b494e7 commit cb582eb

6 files changed

Lines changed: 193 additions & 25 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Globalization;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Windows.Data;
8+
9+
namespace gamevault.Converter
10+
{
11+
class BoolToVisibilityConverter : IValueConverter
12+
{
13+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
14+
{
15+
return (bool)value ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed;
16+
}
17+
18+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
19+
{
20+
return null;
21+
}
22+
}
23+
}

gamevault/Models/ServerInfo.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
using System;
1+
using gamevault.ViewModels;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Text;
56
using System.Text.Json.Serialization;
67
using System.Threading.Tasks;
8+
using System.Windows.Controls;
79

810
namespace gamevault.Models
911
{
@@ -20,4 +22,30 @@ public struct ServerInfo
2022
[JsonPropertyName("available_authentication_methods")]
2123
public string[] AvailableAuthenticationMethods { get; set; }
2224
}
25+
public class BindableServerInfo
26+
{
27+
public bool IsAvailable { get; set; }
28+
29+
public bool IsRegistrationEnabled { get; set; }
30+
public bool IsFirstNameMandatory { get; set; }
31+
public bool IsLastNameMandatory { get; set; }
32+
public bool IsEMailMandatory { get; set; }
33+
public bool IsBirthDateMandatory { get; set; }
34+
35+
public bool IsBasicAuthEnabled { get; set; }
36+
public bool IsSSOEnabled { get; set; }
37+
38+
public BindableServerInfo() { }
39+
public BindableServerInfo(ServerInfo info)
40+
{
41+
IsAvailable = true;
42+
IsRegistrationEnabled = info.RegistrationEnabled;
43+
IsFirstNameMandatory = info.RequiredRegistrationFields.Contains("first_name");
44+
IsLastNameMandatory = info.RequiredRegistrationFields.Contains("last_name");
45+
IsEMailMandatory = info.RequiredRegistrationFields.Contains("email");
46+
IsBirthDateMandatory = info.RequiredRegistrationFields.Contains("birth_date");
47+
IsBasicAuthEnabled = info.AvailableAuthenticationMethods.Contains("basic");
48+
IsSSOEnabled = info.AvailableAuthenticationMethods.Contains("sso");
49+
}
50+
}
2351
}

gamevault/UserControls/SettingsUserControl.xaml.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ private async void LogoutFromAllDevices_Click(object sender, RoutedEventArgs e)
202202
{
203203
Preferences.DeleteKey(AppConfigKey.Password, LoginManager.Instance.GetUserProfile().UserConfigFile);
204204
}
205+
Preferences.DeleteKey(AppConfigKey.LastUserProfile, ProfileManager.ProfileConfigFile);
206+
((MainWindow)App.Current.MainWindow).Dispose();
207+
App.Current.MainWindow = new LoginWindow(true);
208+
App.Current.MainWindow.Show();
205209
}
206210
catch (Exception ex)
207211
{

gamevault/ViewModels/LoginWindowViewModel.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ public string StatusText
3131
get { return statusText; }
3232
set { statusText = value; OnPropertyChanged(); }
3333
}
34+
private BindableServerInfo loginServerInfo { get; set; } = new BindableServerInfo();
35+
public BindableServerInfo LoginServerInfo
36+
{
37+
get { return loginServerInfo; }
38+
set { loginServerInfo = value; OnPropertyChanged(); }
39+
}
3440
private LoginUser loginUser { get; set; }
3541
public LoginUser LoginUser
3642
{
@@ -44,6 +50,12 @@ public LoginUser LoginUser
4450
}
4551
set { loginUser = value; OnPropertyChanged(); }
4652
}
53+
private BindableServerInfo signUpServerInfo { get; set; } = new BindableServerInfo();
54+
public BindableServerInfo SignUpServerInfo
55+
{
56+
get { return signUpServerInfo; }
57+
set { signUpServerInfo = value; OnPropertyChanged(); }
58+
}
4759
private LoginUser signupUser { get; set; }
4860
public LoginUser SignupUser
4961
{

gamevault/Windows/LoginWindow.xaml

Lines changed: 91 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
Height="500" Width="720" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" Loaded="LoginWindow_Loaded" Closing="MetroWindow_Closing">
1414
<mah:MetroWindow.Resources>
1515
<conv:InverseBoolConverter x:Key="invBoolConv"/>
16+
<conv:BoolToVisibilityConverter x:Key="boolToVisConv"/>
1617
</mah:MetroWindow.Resources>
1718
<Grid>
1819
<TabControl SelectedIndex="{Binding LoginStepIndex}" Background="{DynamicResource MahApps.Brushes.ThemeBackground2}">
@@ -172,10 +173,31 @@
172173
<TextBlock Text="Sign In" FontSize="30" HorizontalAlignment="Center"/>
173174
<TextBlock Text="Specify Your Server URL" TextDecorations="Underline" Margin="0,15,0,5"/>
174175
<StackPanel Orientation="Horizontal" Margin="0,0,0,0">
175-
<TextBox Text="{Binding LoginUser.ServerUrl}" mah:ControlsHelper.CornerRadius="5" BorderThickness="2" Width="400" LostFocus="ServerUrlInput_LostFocus"/>
176-
<Path Data="{StaticResource IconCheck}" Fill="Green" Margin="2,1,-25,0" Visibility="Collapsed"/>
176+
<TextBox Text="{Binding LoginUser.ServerUrl}" mah:ControlsHelper.CornerRadius="5" BorderThickness="2" Width="400" TextChanged="ServerUrlInput_TextChanged"/>
177+
<Path Data="{StaticResource IconCheck}" Fill="Green" Margin="2,1,-25,0">
178+
<Path.Style>
179+
<Style TargetType="Path">
180+
<Setter Property="Visibility" Value="Collapsed"/>
181+
<Style.Triggers>
182+
<DataTrigger Binding="{Binding LoginServerInfo.IsAvailable}" Value="True">
183+
<Setter Property="Visibility" Value="Visible"/>
184+
</DataTrigger>
185+
</Style.Triggers>
186+
</Style>
187+
</Path.Style>
188+
</Path>
177189
</StackPanel>
178-
<StackPanel IsEnabled="{Binding LoginUser.IsLoggedInWithSSO,Converter={StaticResource invBoolConv}}">
190+
<StackPanel>
191+
<StackPanel.Style>
192+
<Style TargetType="StackPanel">
193+
<Setter Property="IsEnabled" Value="False"/>
194+
<Style.Triggers>
195+
<DataTrigger Binding="{Binding LoginServerInfo.IsBasicAuthEnabled}" Value="True">
196+
<Setter Property="IsEnabled" Value="{Binding LoginUser.IsLoggedInWithSSO,Converter={StaticResource invBoolConv}}"/>
197+
</DataTrigger>
198+
</Style.Triggers>
199+
</Style>
200+
</StackPanel.Style>
179201
<TextBlock Text="Username or Email" TextDecorations="Underline" Margin="0,15,0,5"/>
180202
<TextBox Text="{Binding LoginUser.Username}" mah:ControlsHelper.CornerRadius="5" BorderThickness="2"/>
181203

@@ -187,7 +209,18 @@
187209
<TextBlock Text="OR" HorizontalAlignment="Center" Margin="10,0,10,0"/>
188210
<Rectangle Fill="{DynamicResource MahApps.Brushes.ThemeForeground}" Width="70" Height="2"/>
189211
</StackPanel>
190-
<CheckBox IsChecked="{Binding LoginUser.IsLoggedInWithSSO}" Content="Sign in using your Identity Provider" mah:CheckBoxHelper.CheckCornerRadius="5" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,15,0,0"/>
212+
<CheckBox IsChecked="{Binding LoginUser.IsLoggedInWithSSO}" Content="Sign in using your Identity Provider" mah:CheckBoxHelper.CheckCornerRadius="5" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,15,0,0">
213+
<CheckBox.Style>
214+
<Style TargetType="CheckBox" BasedOn="{StaticResource MahApps.Styles.CheckBox}">
215+
<Setter Property="IsEnabled" Value="False"/>
216+
<Style.Triggers>
217+
<DataTrigger Binding="{Binding LoginServerInfo.IsSSOEnabled}" Value="True">
218+
<Setter Property="IsEnabled" Value="True"/>
219+
</DataTrigger>
220+
</Style.Triggers>
221+
</Style>
222+
</CheckBox.Style>
223+
</CheckBox>
191224
</StackPanel>
192225
<uc:IconButton Text="Save and Login" Height="30" Margin="0,0,10,10" Width="100" HorizontalAlignment="Right" VerticalAlignment="Bottom" Click="SaveAndLogin_Click"/>
193226
<uc:IconButton Text="Back" Kind="Skeleton" BorderThickness="1" Height="30" Margin="10,0,0,10" Width="100" HorizontalAlignment="Left" VerticalAlignment="Bottom" Click="Back_Click" Tag="{x:Static local:LoginStep.SignInOrSignUp}"/>
@@ -198,8 +231,32 @@
198231
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Width="400" Height="430" Margin="0,8,0,0">
199232
<TextBlock Text="Sign Up" FontSize="30" HorizontalAlignment="Center"/>
200233
<TextBlock Text="Specify Your Server URL" TextDecorations="Underline" Margin="0,15,0,5"/>
201-
<TextBox Text="{Binding SignupUser.ServerUrl}" mah:ControlsHelper.CornerRadius="5" BorderThickness="2"/>
202-
<StackPanel IsEnabled="{Binding SignupUser.IsLoggedInWithSSO,Converter={StaticResource invBoolConv}}">
234+
<StackPanel Orientation="Horizontal">
235+
<TextBox Text="{Binding SignupUser.ServerUrl}" mah:ControlsHelper.CornerRadius="5" Width="400" BorderThickness="2" TextChanged="ServerUrlInput_TextChanged"/>
236+
<Path Data="{StaticResource IconCheck}" Fill="Green" Margin="2,1,-25,0">
237+
<Path.Style>
238+
<Style TargetType="Path">
239+
<Setter Property="Visibility" Value="Collapsed"/>
240+
<Style.Triggers>
241+
<DataTrigger Binding="{Binding SignUpServerInfo.IsAvailable}" Value="True">
242+
<Setter Property="Visibility" Value="Visible"/>
243+
</DataTrigger>
244+
</Style.Triggers>
245+
</Style>
246+
</Path.Style>
247+
</Path>
248+
</StackPanel>
249+
<StackPanel>
250+
<StackPanel.Style>
251+
<Style TargetType="StackPanel">
252+
<Setter Property="IsEnabled" Value="False"/>
253+
<Style.Triggers>
254+
<DataTrigger Binding="{Binding SignUpServerInfo.IsBasicAuthEnabled}" Value="True">
255+
<Setter Property="IsEnabled" Value="{Binding SignupUser.IsLoggedInWithSSO,Converter={StaticResource invBoolConv}}"/>
256+
</DataTrigger>
257+
</Style.Triggers>
258+
</Style>
259+
</StackPanel.Style>
203260
<Grid>
204261
<Grid.ColumnDefinitions>
205262
<ColumnDefinition Width="Auto"/>
@@ -211,11 +268,17 @@
211268
<TextBox Text="{Binding SignupUser.Username}" mah:ControlsHelper.CornerRadius="5" BorderThickness="2"/>
212269
</StackPanel>
213270
<StackPanel Width="195" Grid.Column="2">
214-
<TextBlock Text="Birth Date" TextDecorations="Underline" Margin="0,15,0,5"/>
271+
<StackPanel Orientation="Horizontal" Margin="0,15,0,5">
272+
<TextBlock Text="Birth Date" TextDecorations="Underline"/>
273+
<TextBlock Text="(Mandatory)" Visibility="{Binding SignUpServerInfo.IsBirthDateMandatory,Converter={StaticResource boolToVisConv}}" VerticalAlignment="Center" Margin="5,0,0,0"/>
274+
</StackPanel>
215275
<DatePicker SelectedDate="{Binding SignupUser.BirthDate}" mah:ControlsHelper.CornerRadius="5" BorderThickness="2"/>
216276
</StackPanel>
217277
</Grid>
218-
<TextBlock Text="E-Mail" TextDecorations="Underline" Margin="0,15,0,5"/>
278+
<StackPanel Orientation="Horizontal" Margin="0,15,0,5">
279+
<TextBlock Text="E-Mail" TextDecorations="Underline"/>
280+
<TextBlock Text="(Mandatory)" Visibility="{Binding SignUpServerInfo.IsEMailMandatory,Converter={StaticResource boolToVisConv}}" VerticalAlignment="Center" Margin="5,0,0,0"/>
281+
</StackPanel>
219282
<TextBox Text="{Binding SignupUser.EMail}" mah:ControlsHelper.CornerRadius="5" BorderThickness="2"/>
220283
<Grid>
221284
<Grid.ColumnDefinitions>
@@ -224,11 +287,17 @@
224287
<ColumnDefinition Width="Auto"/>
225288
</Grid.ColumnDefinitions>
226289
<StackPanel Width="195" Grid.Column="0">
227-
<TextBlock Text="First Name" TextDecorations="Underline" Margin="0,15,0,5"/>
290+
<StackPanel Orientation="Horizontal" Margin="0,15,0,5">
291+
<TextBlock Text="First Name" TextDecorations="Underline"/>
292+
<TextBlock Text="(Mandatory)" Visibility="{Binding SignUpServerInfo.IsFirstNameMandatory,Converter={StaticResource boolToVisConv}}" VerticalAlignment="Center" Margin="5,0,0,0"/>
293+
</StackPanel>
228294
<TextBox Text="{Binding SignupUser.FirstName}" mah:ControlsHelper.CornerRadius="5" BorderThickness="2"/>
229295
</StackPanel>
230296
<StackPanel Width="195" Grid.Column="2">
231-
<TextBlock Text="Last Name" TextDecorations="Underline" Margin="0,15,0,5"/>
297+
<StackPanel Orientation="Horizontal" Margin="0,15,0,5">
298+
<TextBlock Text="Last Name" TextDecorations="Underline"/>
299+
<TextBlock Text="(Mandatory)" Visibility="{Binding SignUpServerInfo.IsLastNameMandatory,Converter={StaticResource boolToVisConv}}" VerticalAlignment="Center" Margin="5,0,0,0"/>
300+
</StackPanel>
232301
<TextBox Text="{Binding SignupUser.LastName}" mah:ControlsHelper.CornerRadius="5" BorderThickness="2"/>
233302
</StackPanel>
234303
</Grid>
@@ -253,7 +322,18 @@
253322
<Rectangle Fill="{DynamicResource MahApps.Brushes.ThemeForeground}" Width="70" Height="2"/>
254323
</StackPanel>
255324
</StackPanel>
256-
<CheckBox IsChecked="{Binding SignupUser.IsLoggedInWithSSO}" Content="Sign up using your Identity Provider" mah:CheckBoxHelper.CheckCornerRadius="5" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,15,0,0"/>
325+
<CheckBox IsChecked="{Binding SignupUser.IsLoggedInWithSSO}" Content="Sign up using your Identity Provider" mah:CheckBoxHelper.CheckCornerRadius="5" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,15,0,0">
326+
<CheckBox.Style>
327+
<Style TargetType="CheckBox" BasedOn="{StaticResource MahApps.Styles.CheckBox}">
328+
<Setter Property="IsEnabled" Value="False"/>
329+
<Style.Triggers>
330+
<DataTrigger Binding="{Binding SignUpServerInfo.IsSSOEnabled}" Value="True">
331+
<Setter Property="IsEnabled" Value="True"/>
332+
</DataTrigger>
333+
</Style.Triggers>
334+
</Style>
335+
</CheckBox.Style>
336+
</CheckBox>
257337
</StackPanel>
258338
<uc:IconButton Text="Save and Sign Up" Height="30" Margin="0,0,10,10" Width="100" HorizontalAlignment="Right" VerticalAlignment="Bottom" Click="SaveAndSignUp_Click"/>
259339
<uc:IconButton Text="Back" Kind="Skeleton" BorderThickness="1" Height="30" Margin="10,0,0,10" Width="100" HorizontalAlignment="Left" VerticalAlignment="Bottom" Click="Back_Click" Tag="{x:Static local:LoginStep.SignInOrSignUp}"/>

0 commit comments

Comments
 (0)