mirror of
https://github.com/XFox111/GUTSchedule.git
synced 2026-04-22 06:58:01 +03:00
Cabinet functionality updated (#25)
Cabinet authorization has been turned on Occupation check in functionality
This commit is contained in:
@@ -61,15 +61,18 @@
|
||||
<ColumnDefinition Width="0"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<StackPanel Padding="10" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||
<Button x:Uid="applyForOccupation" x:Name="applyForOccupation" Content="Register for lesson" Click="ApplyForLesson" Style="{StaticResource AccentButtonStyle}" Visibility="Collapsed"/>
|
||||
|
||||
<TextBlock x:Uid="scheduleParametersTitle" Style="{StaticResource SubtitleTextBlockStyle}" Text="Schedule parameters"/>
|
||||
|
||||
<CheckBox x:Uid="authorizeCheckbox" Content="Authorize via personal cabinet" Checked="ChangeAuthorizationMethod" Unchecked="ChangeAuthorizationMethod" IsChecked="False" IsEnabled="False" x:Name="authorize"/>
|
||||
<StackPanel x:Name="credentialMethod" Visibility="Collapsed">
|
||||
<CheckBox x:Uid="authorizeCheckbox" Content="Authorize via personal cabinet" Checked="ChangeAuthorizationMethod" Unchecked="ChangeAuthorizationMethod" IsChecked="True" x:Name="authorize"/>
|
||||
<StackPanel x:Name="credentialMethod" Visibility="Visible">
|
||||
<TextBox x:Uid="email" PlaceholderText="E-mail" x:Name="email" IsSpellCheckEnabled="False"/>
|
||||
<PasswordBox x:Uid="password" PlaceholderText="Password" x:Name="password"/>
|
||||
<Button x:Uid="validateCredential" x:Name="validateCredential" Content="Validate credential" Click="ValidateCredential"/>
|
||||
<CheckBox x:Uid="remember" Content="Remember" x:Name="rememberCredential" Checked="RememberCredential_Checked" Unchecked="RememberCredential_Checked"/>
|
||||
</StackPanel>
|
||||
<StackPanel x:Name="defaultMethod" Visibility="Visible">
|
||||
<StackPanel x:Name="defaultMethod" Visibility="Collapsed">
|
||||
<ComboBox x:Uid="facultySpinner" x:Name="faculty" PlaceholderText="No schedule is available" Header="Course" SelectionChanged="Faculty_SelectionChanged"/>
|
||||
<ComboBox x:Uid="courseSpinner" x:Name="course" Header="Course" SelectionChanged="Course_SelectionChanged">
|
||||
<ComboBoxItem Content="1"/>
|
||||
|
||||
@@ -24,6 +24,17 @@ namespace GUTSchedule.UWP.Pages
|
||||
private readonly ResourceLoader resources = ResourceLoader.GetForCurrentView();
|
||||
static readonly ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
|
||||
|
||||
private List<(string, string)> _availableOccupations;
|
||||
private List<(string, string)> AvailableOccupations
|
||||
{
|
||||
get => _availableOccupations;
|
||||
set
|
||||
{
|
||||
_availableOccupations = value;
|
||||
applyForOccupation.Visibility = value.Count > 0 ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
|
||||
public MainPage() =>
|
||||
InitializeComponent();
|
||||
|
||||
@@ -34,7 +45,7 @@ namespace GUTSchedule.UWP.Pages
|
||||
PackageVersion ver = Package.Current.Id.Version;
|
||||
version.Text = $"v{ver.Major}.{ver.Minor}.{ver.Build}.{ver.Revision}";
|
||||
|
||||
//authorize.IsChecked = (bool?)settings.Values["Authorize"] ?? true;
|
||||
authorize.IsChecked = (bool?)settings.Values["Authorize"] ?? true;
|
||||
if (vault.RetrieveAll() is IReadOnlyList<PasswordCredential> credentials && credentials.Count > 0)
|
||||
{
|
||||
email.Text = credentials.First().UserName;
|
||||
@@ -59,6 +70,15 @@ namespace GUTSchedule.UWP.Pages
|
||||
|
||||
reminder.SelectedIndex = (int?)settings.Values["Reminder"] ?? 2;
|
||||
addGroupToTitle.IsChecked = (bool?)settings.Values["AddGroupToTitle"] ?? false;
|
||||
|
||||
try
|
||||
{
|
||||
AvailableOccupations = await Parser.CheckAvailableOccupations(email.Text, password.Password);
|
||||
}
|
||||
catch
|
||||
{
|
||||
AvailableOccupations = new List<(string, string)>();
|
||||
}
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
@@ -281,5 +301,49 @@ namespace GUTSchedule.UWP.Pages
|
||||
|
||||
await dialog.ShowAsync();
|
||||
}
|
||||
|
||||
private async void ValidateCredential(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
validateCredential.IsEnabled = false;
|
||||
await Parser.VaildateAuthorization(email.Text, password.Password);
|
||||
|
||||
if (rememberCredential.IsChecked.Value)
|
||||
vault.Add(new PasswordCredential
|
||||
{
|
||||
UserName = email.Text,
|
||||
Password = password.Password,
|
||||
Resource = "xfox111.gutschedule"
|
||||
});
|
||||
else
|
||||
foreach (PasswordCredential credential in vault.RetrieveAll())
|
||||
vault.Remove(credential);
|
||||
|
||||
AvailableOccupations = await Parser.CheckAvailableOccupations(email.Text, password.Password);
|
||||
await new MessageDialog(resources.GetString("validationSuccess")).ShowAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await new MessageDialog($"{resources.GetString("validationFailed")}\n{ex.Message}").ShowAsync();
|
||||
}
|
||||
validateCredential.IsEnabled = true;
|
||||
}
|
||||
|
||||
private async void ApplyForLesson(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
applyForOccupation.Visibility = Visibility.Collapsed;
|
||||
AvailableOccupations = await Parser.CheckAvailableOccupations(email.Text, password.Password);
|
||||
await Parser.ApplyForOccupations(email.Text, password.Password, AvailableOccupations);
|
||||
await new MessageDialog(resources.GetString("attendSuccess")).ShowAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await new MessageDialog($"{resources.GetString("attendFailed")}\n{ex.Message}").ShowAsync();
|
||||
applyForOccupation.Visibility = Visibility.Visible;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user