fully implemented login

This commit is contained in:
WeeXnes 2023-11-21 21:02:39 +01:00
parent f6e3687ec2
commit 55b0ff1c45
10 changed files with 112 additions and 12 deletions

View file

@ -8,7 +8,7 @@ namespace WeeXnes.Core
{ {
public class Information public class Information
{ {
public const string Version = "4.4.7"; public const string Version = "4.4.8";
public const string EncryptionHash = "8zf5#RdyQ]$4x4_"; public const string EncryptionHash = "8zf5#RdyQ]$4x4_";
public const string ApiUrl = "https://api.github.com/repos/weexnes/weexnessuite/releases/latest"; public const string ApiUrl = "https://api.github.com/repos/weexnes/weexnessuite/releases/latest";
} }

View file

@ -19,7 +19,7 @@ namespace WeeXnes.Core
} }
public static void arg_debugMode() public static void arg_debugMode()
{ {
MessageBox.Show("user debug mode enabled");
} }
public static void arg_enableConsole() public static void arg_enableConsole()
{ {

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Net.Http; using System.Net.Http;
using Newtonsoft.Json; using Newtonsoft.Json;
using WeeXnes.Views.ProfileView;
using WeeXnes.Views.Settings; using WeeXnes.Views.Settings;
using Wpf.Ui.Appearance; using Wpf.Ui.Appearance;
using Wpf.Ui.Controls; using Wpf.Ui.Controls;
@ -73,10 +74,12 @@ namespace WeeXnes.Core
_token = token; _token = token;
return token; return token;
//Console.WriteLine($"Token: {token}"); //Console.WriteLine($"Token: {token}");
} }
else else
{ {
WeeXnes.Core.CustomConsole.WriteLine("Error: " + response.StatusCode); WeeXnes.Core.CustomConsole.WriteLine("Error: " + response.StatusCode);
LoginView.errorStringCache.Value = response.StatusCode.ToString();
return null; return null;
} }
} }
@ -116,6 +119,7 @@ namespace WeeXnes.Core
//Console.WriteLine($"Email: {user.email}"); //Console.WriteLine($"Email: {user.email}");
// Access other properties as needed // Access other properties as needed
_currentUserCache.Value = user; _currentUserCache.Value = user;
LoginView.alreadyLoggedIn = true;
return user; return user;
} }
else else
@ -124,6 +128,8 @@ namespace WeeXnes.Core
_currentUserCache.Value = null; _currentUserCache.Value = null;
WeeXnes.Core.CustomConsole.WriteLine("Error: " + response.StatusCode); WeeXnes.Core.CustomConsole.WriteLine("Error: " + response.StatusCode);
LoginView.errorStringCache.Value = response.StatusCode.ToString();
return null; return null;
} }
} }

View file

@ -97,7 +97,7 @@
Icon="InprivateAccount24" Icon="InprivateAccount24"
Name="ButtonProfile" Name="ButtonProfile"
PageTag="Profile" PageTag="Profile"
PageType="{x:Type profile:ProfileView}"/> PageType="{x:Type profile:LoginView}"/>
</ui:NavigationStore.Items> </ui:NavigationStore.Items>
<ui:NavigationStore.Footer> <ui:NavigationStore.Footer>
<ui:NavigationItem <ui:NavigationItem

View file

@ -0,0 +1,15 @@
<Page x:Class="WeeXnes.Views.ProfileView.LoginError"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WeeXnes.Views.ProfileView"
mc:Ignorable="d"
Title="LoginError" Height="Auto" Width="Auto">
<Grid>
<StackPanel VerticalAlignment="Center">
<Label Content="wrong credentials" HorizontalAlignment="Center" Padding="0,0,0,10"/>
<Button Content="Back to login" HorizontalAlignment="Center" Click="ButtonBase_OnClick"/>
</StackPanel>
</Grid>
</Page>

View file

@ -0,0 +1,19 @@
using System;
using System.Windows;
using System.Windows.Controls;
namespace WeeXnes.Views.ProfileView
{
public partial class LoginError : Page
{
public LoginError()
{
InitializeComponent();
}
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/Views/ProfileView/LoginView.xaml",UriKind.Relative));
}
}
}

View file

@ -5,8 +5,15 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WeeXnes.Views.ProfileView" xmlns:local="clr-namespace:WeeXnes.Views.ProfileView"
mc:Ignorable="d" mc:Ignorable="d"
Title="LoginView" Height="450" Width="800"> Title="LoginView" Height="Auto" Width="Auto"
Loaded="LoginView_OnLoaded">
<Grid> <Grid>
<StackPanel>
<Label Content="Email:"/>
<TextBox Name="tb_email" Margin="0,0,0,10" KeyDown="InputKeydown"/>
<Label Content="Password:"/>
<TextBox Name="tb_password" Margin="0,0,0,10" KeyDown="InputKeydown"/>
<Button Content="Login" HorizontalAlignment="Center" Name="LoginButton" Click="LoginButton_OnClick"/>
</StackPanel>
</Grid> </Grid>
</Page> </Page>

View file

@ -1,12 +1,49 @@
using System.Windows.Controls; using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using WeeXnes.Core;
namespace WeeXnes.Views.ProfileView namespace WeeXnes.Views.ProfileView
{ {
public partial class LoginView : Page public partial class LoginView : Page
{ {
public static bool alreadyLoggedIn = false;
public static UpdateVar<string> errorStringCache = new UpdateVar<string>();
public LoginView() public LoginView()
{ {
InitializeComponent(); InitializeComponent();
} }
private void SwitchToProfileView()
{
NavigationService.Navigate(new Uri("/Views/ProfileView/ProfileView.xaml",UriKind.Relative));
}
private void LoginView_OnLoaded(object sender, RoutedEventArgs e)
{
if (alreadyLoggedIn)
{
SwitchToProfileView();
}
}
private void LoginButton_OnClick(object sender, RoutedEventArgs e)
{
attemptLogin();
}
private void InputKeydown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
attemptLogin();
}
private void attemptLogin()
{
ProfileView.auth._email = tb_email.Text;
ProfileView.auth._password = tb_password.Text;
SwitchToProfileView();
}
} }
} }

View file

@ -16,13 +16,13 @@ namespace WeeXnes.Views.ProfileView
public ProfileView() public ProfileView()
{ {
InitializeComponent(); InitializeComponent();
auth._email = "";
auth._password = "";
} }
private void ProfileView_OnLoaded(object sender, RoutedEventArgs e) private void ProfileView_OnLoaded(object sender, RoutedEventArgs e)
{ {
auth.ExceptionCache.ValueChanged += LoginWorkerException; auth.ExceptionCache.ValueChanged += LoginWorkerException;
auth._currentUserCache.ValueChanged += userCacheChanged; auth._currentUserCache.ValueChanged += userCacheChanged;
LoginView.errorStringCache.ValueChanged += errorStringChanged;
WeeXnes.Core.CustomConsole.WriteLine("Error Hooks loaded");
WeeXnes.Core.CustomConsole.WriteLine("Event hooks loaded"); WeeXnes.Core.CustomConsole.WriteLine("Event hooks loaded");
if (auth._currentUserCache.Value == null) if (auth._currentUserCache.Value == null)
@ -32,6 +32,7 @@ namespace WeeXnes.Views.ProfileView
} }
else else
{ {
LoadProfileToGui();
ProfileContentPanel.Visibility = Visibility.Visible; ProfileContentPanel.Visibility = Visibility.Visible;
} }
} }
@ -49,8 +50,11 @@ namespace WeeXnes.Views.ProfileView
} }
else else
{ {
ProfileContentPanel.Visibility = Visibility.Collapsed; this.Dispatcher.Invoke(() =>
LoadingScreen.Visibility = Visibility.Visible; {
ProfileContentPanel.Visibility = Visibility.Collapsed;
LoadingScreen.Visibility = Visibility.Visible;
});
} }
} }
@ -76,8 +80,16 @@ namespace WeeXnes.Views.ProfileView
auth.ExceptionCache.ValueChanged -= LoginWorkerException; auth.ExceptionCache.ValueChanged -= LoginWorkerException;
auth._currentUserCache.ValueChanged -= userCacheChanged; auth._currentUserCache.ValueChanged -= userCacheChanged;
LoginView.errorStringCache.ValueChanged -= errorStringChanged;
WeeXnes.Core.CustomConsole.WriteLine("Event hooks unloaded"); WeeXnes.Core.CustomConsole.WriteLine("Event hooks unloaded");
} }
private void errorStringChanged()
{
this.Dispatcher.Invoke(() =>
{
NavigationService.Navigate(new Uri("/Views/ProfileView/LoginError.xaml",UriKind.Relative));
});
}
} }
} }

View file

@ -4,7 +4,7 @@
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<Version>4.4.7</Version> <Version>4.4.8</Version>
<ProjectGuid>{4B33CEE7-C74D-43B9-B99A-8B273D5195BC}</ProjectGuid> <ProjectGuid>{4B33CEE7-C74D-43B9-B99A-8B273D5195BC}</ProjectGuid>
<OutputType>WinExe</OutputType> <OutputType>WinExe</OutputType>
<RootNamespace>WeeXnes</RootNamespace> <RootNamespace>WeeXnes</RootNamespace>
@ -106,6 +106,9 @@
<Compile Include="Views\PasswordGenerator\SaveToKeyManagerView.xaml.cs"> <Compile Include="Views\PasswordGenerator\SaveToKeyManagerView.xaml.cs">
<DependentUpon>SaveToKeyManagerView.xaml</DependentUpon> <DependentUpon>SaveToKeyManagerView.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="Views\ProfileView\LoginError.xaml.cs">
<DependentUpon>LoginError.xaml</DependentUpon>
</Compile>
<Compile Include="Views\ProfileView\LoginView.xaml.cs"> <Compile Include="Views\ProfileView\LoginView.xaml.cs">
<DependentUpon>LoginView.xaml</DependentUpon> <DependentUpon>LoginView.xaml</DependentUpon>
</Compile> </Compile>
@ -150,6 +153,7 @@
<Page Include="Views\PasswordGenerator\PasswordGenView.xaml" /> <Page Include="Views\PasswordGenerator\PasswordGenView.xaml" />
<Page Include="Views\PasswordGenerator\SavePasswordView.xaml" /> <Page Include="Views\PasswordGenerator\SavePasswordView.xaml" />
<Page Include="Views\PasswordGenerator\SaveToKeyManagerView.xaml" /> <Page Include="Views\PasswordGenerator\SaveToKeyManagerView.xaml" />
<Page Include="Views\ProfileView\LoginError.xaml" />
<Page Include="Views\ProfileView\LoginView.xaml" /> <Page Include="Views\ProfileView\LoginView.xaml" />
<Page Include="Views\ProfileView\ProfileView.xaml" /> <Page Include="Views\ProfileView\ProfileView.xaml" />
<Page Include="Views\Settings\ChangePathsView.xaml" /> <Page Include="Views\Settings\ChangePathsView.xaml" />