added first part of persistence to locally save a new login and got 2 or 3 buttons working - no errors in this build

This commit is contained in:
Taarly 2025-04-14 16:47:25 +02:00
parent 7c5e88071f
commit bb901f23af
16 changed files with 219 additions and 31 deletions

View File

@ -0,0 +1,15 @@
namespace Project.Model;
public class CreateLogin
{
public string newLoginname { get; set; }
public string newMasterpassword { get; set; }
public string newEmail { get; set; }
public CreateLogin(string username, string password, string email)
{
newLoginname = username;
newMasterpassword = password;
newEmail = email;
}
}

View File

@ -1,6 +1,6 @@
namespace Project.Model;
public class entry
public class Entry
{
public string? entryname;
public string? username;

View File

@ -0,0 +1,9 @@
using System.Reflection.Metadata;
namespace Project.Model;
public class LoginCredentials
{
public string? loginname { get; set; }
public string? masterpassword { get; set; }
}

View File

@ -1,7 +0,0 @@
namespace Project.Model;
public class loginCredentials
{
public string? loginname;
public string? masterpassword;
}

View File

@ -1,6 +0,0 @@
namespace Project.Persistence;
public class Class1
{
}

View File

@ -0,0 +1,12 @@
using Project.Model;
namespace Project.Persistence;
public static class UserStorage
{
private static readonly string FilePath = "C:/Users/lowns/desktop/users.txt";
public static void SaveUser(CreateLogin user)
{
var line = $"{user.newLoginname}:{user.newMasterpassword}:{user.newEmail}";
File.AppendAllLines(FilePath, new[] { line });
}
}

View File

@ -1,20 +1,46 @@
<UserControl
xmlns="https://github.com/avaloniaui"
x:Class="Project.View.LoginPage"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<UserControl
x:Class="Project.View.LoginPage"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid Background="SandyBrown">
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
<Image Source="avares://Project.View/Images/keywi_logo_2.png" Height="400" Width="400"/>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<Image
Height="400"
Source="avares://Project.View/Images/keywi_logo_2.png"
Width="400" />
</StackPanel>
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
<StackPanel
HorizontalAlignment="Center"
Orientation="Vertical"
VerticalAlignment="Center">
<TextBlock>Your Login Name:</TextBlock>
<TextBox Watermark="Login-Name" TextWrapping="Wrap"/>
<TextBox TextWrapping="Wrap" Watermark="Login-Name" />
<TextBlock>Password:</TextBlock>
<TextBlock>Password:</TextBlock>
<TextBox Watermark="Password" TextWrapping="Wrap" PasswordChar="*"/>
<Button Name="ConfirmButton" BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Center" Margin="20"> LOGIN </Button>
<TextBox
PasswordChar="*"
TextWrapping="Wrap"
Watermark="Password" />
<Button
BorderBrush="Black"
BorderThickness="1"
Click="LoginButtonOnClick"
HorizontalAlignment="Center"
Margin="20"
Name="ConfirmButton">
LOGIN
</Button>
<Button
BorderBrush="Black"
BorderThickness="1"
Click="NewUserButtonOnClick"
HorizontalAlignment="Center"
Margin="20"
Name="NewUserButton">
Create New User
</Button>
</StackPanel>
</Grid>

View File

@ -17,4 +17,13 @@ public partial class LoginPage : UserControl
InitializeComponent();
_controller = controller;
}
private async void LoginButtonOnClick(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
}
private async void NewUserButtonOnClick(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
var newLoginWindow = new NewLogin();
newLoginWindow.Show();
}
}

View File

@ -11,6 +11,6 @@ public partial class MainWindow : Window
{
InitializeComponent();
_controller = new();
MainGrid.Children.Add(new MenuView());
MainGrid.Children.Add(new LoginPage());
}
}

View File

@ -48,6 +48,11 @@
HorizontalAlignment="Left"
Margin="23"
Text="Name:" />
<TextBlock
FontSize="20"
HorizontalAlignment="Left"
Margin="23"
Text="Login-Name:" />
<TextBlock
FontSize="20"
HorizontalAlignment="Left"
@ -71,6 +76,11 @@
Margin="20"
Text="THE NAME OF YOUR SAVED LOGIN"
TextWrapping="Wrap" />
<TextBox
Height="30"
Margin="20"
Text="YOUR LOGIN NAME ON THIS PAGE"
TextWrapping="Wrap" />
<TextBox
Height="30"
Margin="20"

View File

@ -20,9 +20,10 @@ public partial class MenuView : UserControl
}
private void NewEntryButton_OnClick(object? sender, RoutedEventArgs e)
private async void NewEntryButton_OnClick(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
var newEntry = new NewEntry(_controller);
NewEntry.Show(newEntry);
var newEntryWindow = new NewEntry();
newEntryWindow.Show();
}
}

View File

@ -1,4 +1,6 @@
<UserControl
Height="500"
Width="350"
x:Class="Project.View.NewEntry"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

View File

@ -5,7 +5,7 @@ using Project.Controller;
namespace Project.View;
public partial class NewEntry : UserControl
public partial class NewEntry : Window
{
readonly AppController? _controller;
public NewEntry()
@ -18,4 +18,5 @@ public partial class NewEntry : UserControl
InitializeComponent();
_controller = controller;
}
}

View File

@ -0,0 +1,57 @@
<UserControl
Height="500"
Width="350"
x:Class="Project.View.NewLogin"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<Border Background="SaddleBrown">
<StackPanel Orientation="Vertical">
<TextBlock
FontSize="20"
HorizontalAlignment="Left"
Text="Username:" />
<TextBox
TextWrapping="Wrap"
Watermark="Username"
x:Name="NewLoginUsernameBox" />
<TextBlock
FontSize="20"
HorizontalAlignment="Left"
Margin="23"
Text="Password:" />
<TextBox
PasswordChar="*"
TextWrapping="Wrap"
Watermark="Password:"
x:Name="NewLoginPasswordBox" />
<TextBlock
FontSize="20"
HorizontalAlignment="Left"
Margin="23"
Text="Email:" />
<TextBox
TextWrapping="Wrap"
Watermark="Email:"
x:Name="NewLoginEmailBox" />
<StackPanel Orientation="Horizontal">
<Button
BorderBrush="Black"
BorderThickness="1"
Click="NewLoginSaveOnClick"
Content="Save" />
<Button
BorderBrush="Black"
BorderThickness="1"
Click="NewLoginCancelOnClick"
Content="Cancel" />
</StackPanel>
</StackPanel>
</Border>
</Grid>
</UserControl>

View File

@ -0,0 +1,44 @@
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Media;
using Project.Controller;
using Project.Model;
using Project.Persistence;
namespace Project.View;
public partial class NewLogin : Window
{
readonly AppController? _controller;
public NewLogin()
{
InitializeComponent();
}
public NewLogin(AppController controller)
{
InitializeComponent();
_controller = controller;
}
private void NewLoginSaveOnClick(object? sender, RoutedEventArgs e)
{
string username = NewLoginUsernameBox.Text?.Trim();
string password = NewLoginPasswordBox.Text?.Trim();
string email = NewLoginEmailBox.Text?.Trim();
var user = new CreateLogin(username, password, email);
UserStorage.SaveUser(user);
NewLoginUsernameBox.Text = "";
NewLoginPasswordBox.Text = "";
NewLoginEmailBox.Text = "";
}
private void NewLoginCancelOnClick(object? sender, RoutedEventArgs e)
{
}
}

View File

@ -25,4 +25,19 @@
<ProjectReference Include="..\Project.Model\Project.Model.csproj" />
<AvaloniaResource Include="Images\**" />
</ItemGroup>
<ItemGroup>
<Compile Update="NewLogin\NewLogin.axaml.cs">
<DependentUpon>NewLogin.axaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Update="NewLogin\NewLogin.axaml.cs">
<DependentUpon>NewEntry.axaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="NewLogin\NewLogin.axaml" />
</ItemGroup>
</Project>