Dateien nach "PenPaperMain" hochladen

This commit is contained in:
Jakob Weber 2025-09-03 10:22:26 +02:00
parent 84357ed360
commit 1608317714
4 changed files with 204 additions and 0 deletions

View File

@ -0,0 +1,44 @@
<Window x:Class="Pen_Paper_Main.Registrieren"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Registrieren" Height="450" Width="800">
<!--Jakob-->
<Grid Background="LightBlue">
<Border Width="350" Padding="20" Background="White" CornerRadius="10"
VerticalAlignment="Center" HorizontalAlignment="Center">
<StackPanel>
<TextBlock Text="Neues Konto anlegen"
FontSize="24" FontWeight="Bold"
HorizontalAlignment="Center" Margin="0,0,0,10"/>
<!-- Benutzername -->
<TextBlock Text="Benutzername" Margin="10,0,10,4"/>
<TextBox x:Name="BenutzernameInput"
Height="35" Margin="10"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"/>
<!-- Passwort -->
<TextBlock Text="Passwort" Margin="10,6,10,4"/>
<PasswordBox x:Name="PasswortBox"
Height="35" Margin="10"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"/>
<!-- Passwort bestätigen -->
<TextBlock Text="Passwort bestätigen" Margin="10,6,10,4"/>
<PasswordBox x:Name="PasswortBoxConfirm"
Height="35" Margin="10"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"/>
<Button Content="Jetzt Starten"
Height="40" Margin="10,16,10,0"
Background="#3B82F6" Foreground="White"
Click="Button_Click"/>
</StackPanel>
</Border>
</Grid>
</Window>

View File

@ -0,0 +1,82 @@
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows;
//jakob
namespace Pen_Paper_Main
{
public partial class Registrieren : Window
{
public Registrieren()
{
InitializeComponent();
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
string user = BenutzernameInput.Text.Trim();
string pass = PasswortBox.Password;
string pass2 = PasswortBoxConfirm.Password;
// simple Validierung
if (string.IsNullOrWhiteSpace(user) || string.IsNullOrWhiteSpace(pass))
{
MessageBox.Show("Bitte Benutzername und Passwort eingeben.");
return;
}
if (pass != pass2)
{
MessageBox.Show("Passwörter stimmen nicht überein.");
return;
}
var result = await CallApi("register", user, pass);
if (result.ok)
{
MessageBox.Show("Registrierung erfolgreich");
var a = new Anmeldung();
a.Show();
this.Close();
}
else
{
MessageBox.Show("Fehler: " + result.msg);
}
}
private async Task<(bool ok, string msg)> CallApi(string action, string u, string p)
{
try
{
//versucht api zu callen
using var client = new HttpClient();
var json = JsonSerializer.Serialize(new { username = u, password = p });
var resp = await client.PostAsync(
//url der api und worauf es verweist
$"http://localhost/api/users.php?action={action}",
new StringContent(json, Encoding.UTF8, "application/json")
);
// antwort wird erwartet
var body = await resp.Content.ReadAsStringAsync();
//text als json umformatieren
using var doc = JsonDocument.Parse(body);
//liest ob ok true oder false ist (ist definiert in db.php)
bool ok = doc.RootElement.GetProperty("ok").GetBoolean();
string msg = doc.RootElement.GetProperty("msg").GetString() ?? "";
return (ok, msg);
}
catch
{
return (false, "invalid response");
}
}
}
}

View File

@ -0,0 +1,51 @@
<Window x:Class="Pen_Paper_Main.SitzungVerwalten"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Pen_Paper_Main"
mc:Ignorable="d"
Title="SitzungVerwalten" Height="450" Width="800">
<DockPanel Background="LightBlue">
<TextBlock DockPanel.Dock="Top" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="35" FontWeight="Bold">Sitzungen</TextBlock>
<Border Width="Auto" Padding="20" Height="Auto" Background="White" CornerRadius="10"
VerticalAlignment="Center" HorizontalAlignment="Center" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" FontSize="15" HorizontalAlignment="Center"
VerticalAlignment="Center" FontWeight="Bold" Margin="15">Sitzung erstellen</TextBlock>
<TextBlock Grid.Row="0" Grid.Column="1" FontSize="15" HorizontalAlignment="Center"
VerticalAlignment="Center" FontWeight="Bold" Margin="15">Sitzung beitreten</TextBlock>
<TextBox Grid.Row="1" Grid.Column="0" FontSize="15" HorizontalAlignment="Center" Foreground="LightGray"
VerticalAlignment="Center" Margin="10">Titel eingeben</TextBox>
<Button Grid.Row="2" Grid.Column="0" FontSize="15" HorizontalAlignment="Center"
VerticalAlignment="Center" Margin="15">Sitzung erstellen</Button>
<TextBox Grid.Row="1" Grid.Column="1" HorizontalAlignment="Center" Foreground="LightGray"
VerticalAlignment="Center" >Code eingeben</TextBox>
<Button Grid.Row="2" Grid.Column="1" FontSize="15" HorizontalAlignment="Center"
VerticalAlignment="Center" Margin="15">Sitzung beitreten</Button>
</Grid>
</Border>
</DockPanel>
</Window>

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace Pen_Paper_Main
{
/// <summary>
/// Interaktionslogik für SitzungVerwalten.xaml
/// </summary>
public partial class SitzungVerwalten : Window
{
public SitzungVerwalten()
{
InitializeComponent();
}
}
}