Feat : UserAuth & User load Save
continuous-integration/drone/push Build is passing Details

Popup_qui_marche_pas
BelsethUwU 2 years ago
parent 5f4051d56f
commit 405e77cbf3

@ -28,7 +28,11 @@ namespace StimPersistance
public void SaveUser(List<User> users) public void SaveUser(List<User> users)
{ {
throw new NotImplementedException(); XmlWriterSettings settings = new() { Indent = true };
DataContractSerializer serializer = new(typeof(List<User>));
using (TextWriter tw = File.CreateText("users.xml"))
using (XmlWriter writer = XmlWriter.Create(tw, settings)) serializer.WriteObject(writer, users);
} }
public ObservableCollection<Game> LoadGame() public ObservableCollection<Game> LoadGame()
@ -43,7 +47,12 @@ namespace StimPersistance
public List<User> LoadUser() public List<User> LoadUser()
{ {
throw new NotImplementedException(); if (File.Exists("users.xml"))
{
DataContractSerializer serializer = new(typeof(List<User>));
using (Stream stream = File.OpenRead("users.xml")) return serializer.ReadObject(stream) as List<User>;
}
return new();
} }
} }
} }

@ -8,5 +8,6 @@ namespace Model
public void SaveUser(List<User> users); public void SaveUser(List<User> users);
public ObservableCollection<Game> LoadGame(); public ObservableCollection<Game> LoadGame();
public List<User> LoadUser(); public List<User> LoadUser();
} }
} }

@ -8,6 +8,7 @@ namespace Model
public ObservableCollection<Game> GameList { get;} public ObservableCollection<Game> GameList { get;}
public ObservableCollection<Game> ResearchedGame { get; set; } public ObservableCollection<Game> ResearchedGame { get; set; }
public User CurrentUser { get; set; } public User CurrentUser { get; set; }
public List<User> Users { get; set; }
public Manager(IPersistance persistance) public Manager(IPersistance persistance)
{ {
@ -15,6 +16,7 @@ namespace Model
CurrentUser = new User(null,"username", "je suis née .... maintenat je fini à 19h30 à cause de l'IHM. GHGHTFCDXEFTGHYJKIJHNGFVCREDTGHNJIKJUHNYGVTFCREDZTGYHUNJIKJUHNYTGVFCREDRTYHUJIOUJNHYGVFRCCFTGYHUJIUJNHYTGBVCFDRRTGYHUI", "email@email.com", "password88"); CurrentUser = new User(null,"username", "je suis née .... maintenat je fini à 19h30 à cause de l'IHM. GHGHTFCDXEFTGHYJKIJHNGFVCREDTGHNJIKJUHNYGVTFCREDZTGYHUNJIKJUHNYTGVFCREDRTYHUJIOUJNHYGVFRCCFTGYHUJIUJNHYTGBVCFDRRTGYHUI", "email@email.com", "password88");
GameList = persistance.LoadGame(); GameList = persistance.LoadGame();
ResearchedGame = persistance.LoadGame(); ResearchedGame = persistance.LoadGame();
Users = persistance.LoadUser();
if (GameList == null) { GameList = new ObservableCollection<Game>();} if (GameList == null) { GameList = new ObservableCollection<Game>();}
} }
@ -23,6 +25,11 @@ namespace Model
GameList.Add(game); GameList.Add(game);
Mgrpersistance.SaveGame(GameList); Mgrpersistance.SaveGame(GameList);
} }
public void AddUsertoUserList(User user)
{
Users.Add(user);
Mgrpersistance.SaveUser(Users);
}
public void RemoveGameFromGamesList(Game game) public void RemoveGameFromGamesList(Game game)
{ {
@ -34,5 +41,17 @@ namespace Model
{ {
Mgrpersistance.SaveGame(GameList); Mgrpersistance.SaveGame(GameList);
} }
public User? SearchUser(string username)
{
foreach (User user in Users)
{
if (user.Username == username) return user;
}
return null;
}
public void SaveUser()
{
Mgrpersistance.SaveUser(Users);
}
} }
} }

@ -1,11 +1,16 @@
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel; using System.ComponentModel;
using System.Runtime.Serialization;
using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Xml.Linq;
namespace Model namespace Model
{ {
public class User : INotifyPropertyChanged [DataContract]
public class User : INotifyPropertyChanged , IEquatable<User>
{ {
[DataMember]
public string Username public string Username
{ {
get => username; get => username;
@ -16,7 +21,7 @@ namespace Model
} }
} }
private string username; private string username;
[DataMember]
public string Biographie public string Biographie
{ {
get => biographie; get => biographie;
@ -27,7 +32,7 @@ namespace Model
} }
} }
private string biographie; private string biographie;
[DataMember]
public string Email public string Email
{ {
get => email; get => email;
@ -40,7 +45,7 @@ namespace Model
} }
} }
private string email; private string email;
[DataMember]
public string Password public string Password
{ {
get => password; get => password;
@ -55,7 +60,7 @@ namespace Model
public event PropertyChangedEventHandler? PropertyChanged; public event PropertyChangedEventHandler? PropertyChanged;
[DataMember]
public ObservableCollection<Game> Followed_Games public ObservableCollection<Game> Followed_Games
{ {
get; get;
@ -86,6 +91,12 @@ namespace Model
else Password = password; else Password = password;
Followed_Games = new ObservableCollection<Game>(); Followed_Games = new ObservableCollection<Game>();
} }
public bool Equals(User? other)
{
if (string.IsNullOrWhiteSpace(Username)) return false;
return other != null && Username.Equals(other.Username);
}
public void AddReview(Game game, float rate, string text) public void AddReview(Game game, float rate, string text)
{ {
game.AddReview(new Review(Username, rate, text)); game.AddReview(new Review(Username, rate, text));

@ -1,7 +1,7 @@
using Model; using Model;
using Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific; using Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific;
using Application = Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific.Application; using Application = Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific.Application;
using Windows.Gaming.Preview.GamesEnumeration; //using Windows.Gaming.Preview.GamesEnumeration;
namespace Stim; namespace Stim;

@ -22,6 +22,7 @@ public partial class App : Application
{ {
Manager.Mgrpersistance = new Persistance(FileSystem.Current.AppDataDirectory); Manager.Mgrpersistance = new Persistance(FileSystem.Current.AppDataDirectory);
Manager.SaveGames(); Manager.SaveGames();
Manager.SaveUser();
}; };
return window; return window;

@ -10,6 +10,9 @@
> >
<FlyoutItem> <FlyoutItem>
<ShellContent Title="Login"
ContentTemplate="{DataTemplate views:LoginPage}"
Route="LoginPage"/>
<ShellContent Title="Accueil" <ShellContent Title="Accueil"
ContentTemplate="{DataTemplate views:MainPage}" ContentTemplate="{DataTemplate views:MainPage}"
Route="MainPage"/> Route="MainPage"/>

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Stim.Create"
Title="Create">
<Grid BackgroundColor="{StaticResource Tertiary}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="5*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<VerticalStackLayout BackgroundColor="Black" Grid.Column="0"/>
<VerticalStackLayout BackgroundColor="Black" Grid.Column="2"/>
<VerticalStackLayout BackgroundColor="Black" Grid.Column="0" Grid.Row="1"/>
<VerticalStackLayout BackgroundColor="Black" Grid.Column="2" Grid.Row="1"/>
<Grid Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="4*"/>
</Grid.RowDefinitions>
<Image Source="no_cover.png"/>
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Entry Placeholder="Adresse Mail" PlaceholderColor="{StaticResource Primary}" IsPassword="False" x:Name="Email" HeightRequest="50" ClearButtonVisibility="WhileEditing"/>
<Entry Placeholder="Username" PlaceholderColor="{StaticResource Primary}" IsPassword="False" x:Name="Username" HeightRequest="50" Grid.Row="1" ClearButtonVisibility="WhileEditing"/>
<Entry Placeholder="Mot de passe" PlaceholderColor="{StaticResource Primary}" IsPassword="True" x:Name="Pswd" HeightRequest="50" Grid.Row="2" ClearButtonVisibility="WhileEditing"/>
<Grid Grid.Row="3" Margin="10,0,0,10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button Text="Se connecter" Clicked="Se_connecter" HeightRequest="50" BackgroundColor="{StaticResource Gray500}"/>
<Button Text="Créer un compte" Clicked="Creer_un_compte" HeightRequest="50" BackgroundColor="{StaticResource Gray500}" Grid.Column="1"/>
</Grid>
</Grid>
</Grid>
</Grid>
</ContentPage>

@ -0,0 +1,33 @@
using System.Text.RegularExpressions;
namespace Stim;
public partial class Create : ContentPage
{
public Create()
{
InitializeComponent();
}
private async void Creer_un_compte(object sender, EventArgs e)
{
if (!string.IsNullOrWhiteSpace(Username.Text) || !string.IsNullOrWhiteSpace(Pswd.Text) || !string.IsNullOrWhiteSpace(Email.Text))
{
if (((App)App.Current).Manager.SearchUser(Username.Text) == null)
{
Regex rg = new Regex("^(?=.*[A-Za-z])(?=.*[0-9@$!%*#?&])[A-Za-z-0-9@$!%*#?&]{8,}$");
if (rg.IsMatch(Pswd.Text))
{
((App)App.Current).Manager.AddUsertoUserList(new("", Username.Text, "", Email.Text, Pswd.Text));
((App)App.Current).Manager.CurrentUser = ((App)App.Current).Manager.SearchUser(Username.Text);
await Navigation.PushAsync(new MainPage());
}
else throw new NotImplementedException();
}
else throw new NotImplementedException();
}
}
private async void Se_connecter(object sender, EventArgs e)
{
await Navigation.PushAsync(new LoginPage());
}
}

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Stim.LoginPage"
Title="LoginPage">
<Grid BackgroundColor="{StaticResource Tertiary}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="5*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<VerticalStackLayout BackgroundColor="Black" Grid.Column="0"/>
<VerticalStackLayout BackgroundColor="Black" Grid.Column="2"/>
<VerticalStackLayout BackgroundColor="Black" Grid.Column="0" Grid.Row="1"/>
<VerticalStackLayout BackgroundColor="Black" Grid.Column="2" Grid.Row="1"/>
<Grid Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="4*"/>
</Grid.RowDefinitions>
<Image Source="no_cover.png"/>
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Entry Placeholder="Username" PlaceholderColor="{StaticResource Primary}" IsPassword="False" x:Name="Username" HeightRequest="50" ClearButtonVisibility="WhileEditing"/>
<Entry Placeholder="Mot de passe" PlaceholderColor="{StaticResource Primary}" IsPassword="True" x:Name="Pswd" HeightRequest="50" Grid.Row="1" ClearButtonVisibility="WhileEditing"/>
<Grid Grid.Row="2" Margin="10,0,0,10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button Text="Se connecter" Clicked="Se_connecter" HeightRequest="50" BackgroundColor="{StaticResource Gray500}"/>
<Button Text="Créer un compte" Clicked="Creer_un_compte" HeightRequest="50" BackgroundColor="{StaticResource Gray500}" Grid.Column="1"/>
</Grid>
</Grid>
</Grid>
</Grid>
</ContentPage>

@ -0,0 +1,39 @@
//using Microsoft.UI.Xaml.Navigation;
using Model;
namespace Stim;
public partial class LoginPage : ContentPage
{
public LoginPage()
{
InitializeComponent();
}
private async void Se_connecter(object sender, EventArgs e)
{
if (!string.IsNullOrWhiteSpace(Username.Text) || !string.IsNullOrWhiteSpace(Pswd.Text))
{
User user = ((App)App.Current).Manager.SearchUser(Username.Text);
if (user != null)
{
if (user.Password == Pswd.Text)
{
((App)App.Current).Manager.CurrentUser = user;
await Navigation.PushAsync(new MainPage());
}
else throw new NotImplementedException();
}
else
{
throw new NotImplementedException();
}
}
}
private async void Creer_un_compte(object sender, EventArgs e)
{
await Navigation.PushAsync(new Create());
}
}

@ -39,18 +39,18 @@
<SearchBar x:Name="Tag2" TextChanged="SearchBar_GameChanged" Grid.Column="1" Grid.Row="1" Placeholder="Tag 2" WidthRequest="200" HorizontalOptions="Start" Margin="5"/> <SearchBar x:Name="Tag2" TextChanged="SearchBar_GameChanged" Grid.Column="1" Grid.Row="1" Placeholder="Tag 2" WidthRequest="200" HorizontalOptions="Start" Margin="5"/>
</Grid> </Grid>
<CollectionView ItemsSource="{Binding ResearchedGame}" SelectionMode="Single" SelectionChanged="OnClickGameList" ItemsLayout="VerticalGrid, 3" Grid.Column="1" Grid.Row="1"> <CollectionView ItemsSource="{Binding ResearchedGame}" SelectionMode="Single" SelectionChanged="OnClickGameList" ItemsLayout="VerticalGrid, 5" Grid.Column="1" Grid.Row="1">
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate> <DataTemplate>
<Border MinimumWidthRequest="200" Margin="10, 10, 10, 10"> <Border MinimumWidthRequest="200" Margin="10, 10, 10, 10">
<Grid HeightRequest="950"> <Grid HeightRequest="635">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="auto"/> <RowDefinition Height="auto"/>
<RowDefinition Height="auto"/> <RowDefinition Height="auto"/>
<RowDefinition Height="auto"/> <RowDefinition Height="auto"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Image Source="{Binding Cover}" Aspect="AspectFit" Margin="0,0,0,0" WidthRequest="900" HeightRequest="750"/> <Image Source="{Binding Cover}" Aspect="AspectFit" Margin="0,0,0,0" WidthRequest="900" HeightRequest="455"/>
<Label FontAttributes="Bold" FontSize="30" Text="{Binding Name}" Grid.Row="1" HorizontalTextAlignment="Center"/> <Label FontAttributes="Bold" FontSize="30" Text="{Binding Name}" Grid.Row="1" HorizontalTextAlignment="Center"/>
<Grid Grid.Row="2"> <Grid Grid.Row="2">
@ -62,11 +62,11 @@
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Label Text="Tags :"/> <Label Text="Tags :" Margin="0" Padding="0"/>
<CollectionView ItemsSource="{Binding Tags}" Grid.Row="1" Grid.ColumnSpan="2"> <CollectionView ItemsSource="{Binding Tags}" Grid.Row="1" Margin="0">
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate> <DataTemplate>
<Label Padding="10,0,0,0" Text="{Binding}"/> <Label Padding="5,0,0,0" Margin="0" Text="{Binding}"/>
</DataTemplate> </DataTemplate>
</CollectionView.ItemTemplate> </CollectionView.ItemTemplate>
</CollectionView> </CollectionView>

@ -39,7 +39,7 @@
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Border> <Border>
<Label Text="{Binding CurrentUser.Biographie}" HeightRequest="200"/> <Label Text="{Binding CurrentUser.Biographie}" HeightRequest="200" HorizontalTextAlignment="Start" VerticalTextAlignment="Start"/>
</Border> </Border>
<Button ImageSource="pen.png" Grid.Column="1" MaximumHeightRequest="32" MaximumWidthRequest="32" Padding="0,0,0,0" Margin="5,0,0,0" BackgroundColor="{StaticResource Gray500}"></Button> <Button ImageSource="pen.png" Grid.Column="1" MaximumHeightRequest="32" MaximumWidthRequest="32" Padding="0,0,0,0" Margin="5,0,0,0" BackgroundColor="{StaticResource Gray500}"></Button>
</Grid> </Grid>
@ -54,16 +54,6 @@
<Button ImageSource="pen.png" Grid.Column="1" MaximumHeightRequest="32" MaximumWidthRequest="32" Padding="0,0,0,0" Margin="5,0,0,0" BackgroundColor="{StaticResource Gray500}"></Button> <Button ImageSource="pen.png" Grid.Column="1" MaximumHeightRequest="32" MaximumWidthRequest="32" Padding="0,0,0,0" Margin="5,0,0,0" BackgroundColor="{StaticResource Gray500}"></Button>
</Grid> </Grid>
<UserInfo:UserInfo Bind="{Binding CurrentUser.Email}"/> <UserInfo:UserInfo Bind="{Binding CurrentUser.Email}"/>
<!--<Grid Margin="0,20,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border Margin="0,10,0,0" Padding="0">
<Label Text="{Binding CurrentUser.Email}"/>
</Border>
<Button ImageSource="pen.png" Grid.Column="1" MaximumHeightRequest="32" MaximumWidthRequest="32" Padding="0,0,0,0" Margin="5,0,0,0" BackgroundColor="{StaticResource Gray500}"></Button>
</Grid>-->
</VerticalStackLayout> </VerticalStackLayout>

@ -64,6 +64,12 @@
<Compile Update="DetailledPage - Copier.xaml.cs"> <Compile Update="DetailledPage - Copier.xaml.cs">
<DependentUpon>%(Filename)</DependentUpon> <DependentUpon>%(Filename)</DependentUpon>
</Compile> </Compile>
<Compile Update="LoginPage.xaml.cs">
<DependentUpon>LoginPage.xaml</DependentUpon>
</Compile>
<Compile Update="Create.xaml.cs">
<DependentUpon>Create.xaml</DependentUpon>
</Compile>
<Compile Update="UserInfo.xaml.cs"> <Compile Update="UserInfo.xaml.cs">
<DependentUpon>UserInfo.xaml</DependentUpon> <DependentUpon>UserInfo.xaml</DependentUpon>
</Compile> </Compile>
@ -79,6 +85,12 @@
<MauiXaml Update="DetailledPage.xaml"> <MauiXaml Update="DetailledPage.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>
<MauiXaml Update="LoginPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Create.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="UserInfo.xaml"> <MauiXaml Update="UserInfo.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>

@ -45,12 +45,14 @@ namespace StimStub
public void SaveUser(List<User> users) public void SaveUser(List<User> users)
{ {
foreach (User user in users) if (!users.Contains(user)) users.Add(user);
} }
public List<User> LoadUser() public List<User> LoadUser()
{ {
return null; List<User> tmp = new();
return tmp;
} }
} }
} }
Loading…
Cancel
Save