fix conflicts

pull/48/head
Alexandre AGOSTINHO 2 years ago
commit 31fec8e200

@ -1,16 +1,14 @@
// See https://aka.ms/new-console-template for more information using ConsoleApp;
using Model;
using ConsoleApp;
using ConsoleApp.Menu; using ConsoleApp.Menu;
using DataPersistence; using DataPersistence;
using Model;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
Console.WriteLine("Hello, World!\n\n");
Console.WriteLine("Hello, World!\n\n");
// TESTS:
DataManager dataMgr = new DataManager(new Stubs()); DataManager dataMgr = new DataManager(new Stubs());
//DataManager dataMgr = new DataManager(new DataContractXML()); //DataManager dataMgr = new DataManager(new DataContractXML());
//DataManager dataMgr = new DataManager(new DataContractJSON()); //DataManager dataMgr = new DataManager(new DataContractJSON());
@ -39,10 +37,10 @@ User user = dataMgr.GetUsers().Last();
//rc[1].AddReview(new Review(user, 2, "Mais celle-ci oui !")); //rc[1].AddReview(new Review(user, 2, "Mais celle-ci oui !"));
dataMgr.Save(); dataMgr.Save();
MenuManager menuMgr = new MenuManager(dataMgr); MenuManager menuMgr = new MenuManager(dataMgr);
menuMgr.Loop(); menuMgr.Loop();
Console.WriteLine(passwordManager.VerifyPassword(user.Password, "pamigos"));
Console.ReadKey(); Console.ReadKey();

@ -14,8 +14,6 @@ namespace DataPersistence
{ {
public Dictionary<string, List<object>> Load() public Dictionary<string, List<object>> Load()
{ {
PasswordManager passwordManager = new PasswordManager();
Dictionary<string, List<object>> data = new Dictionary<string, List<object>> Dictionary<string, List<object>> data = new Dictionary<string, List<object>>
{ {
{ {
@ -93,45 +91,46 @@ namespace DataPersistence
}) })
}) })
#endregion #endregion
}, },
{ {
#region Data: User #region Data: User
nameof(User), nameof(User),
new List<object>(new[] new List<object>(new[]
{ {
new User( new User(
name: "Admin", name: "Admin",
surname: "Admin", surname: "Admin",
mail: "admin@mctg.fr", mail: "admin@mctg.fr",
password: passwordManager.HashPassword("admin")), password: "admin"),
new User( new User(
name: "Pedros", name: "Pedros",
surname: "Amigos", surname: "Amigos",
mail: "pedrosamigos@hotmail.com", mail: "pedrosamigos@hotmail.com",
password: passwordManager.HashPassword("pamigos")) password: "pamigos")
}) })
#endregion #endregion
} }
}; };
return data; return data;
} }
#region Not supported methods #region Not supported methods
public void Save(Dictionary<string, List<object>> elements) public void Save(Dictionary<string, List<object>> elements)
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }
public void Export<T>(T obj, string pathToExport) where T : class public void Export<T>(T obj, string pathToExport) where T : class
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }
public KeyValuePair<string, T> Import<T>(string pathToImport) where T : class public KeyValuePair<string, T> Import<T>(string pathToImport) where T : class
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }
#endregion #endregion
} }
} }

@ -66,8 +66,7 @@ namespace Model
} }
public Review(int stars, string content) public Review(int stars, string content)
: this(new User("admin", "admin", "admin@mctg.fr", new PasswordManager().HashPassword("admin")), : this(new User(), null, stars, content)
null, stars, content)
{ {
} }

@ -1,3 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections; using System.Collections;
@ -7,6 +8,7 @@ using System.Runtime.CompilerServices;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Text; using System.Text;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using System.ComponentModel;
namespace Model namespace Model
{ {
@ -15,7 +17,7 @@ namespace Model
/// This user can login with an Id and a password /// This user can login with an Id and a password
/// </summary> /// </summary>
[DataContract(Name = "user")] [DataContract(Name = "user")]
public class User : IEquatable<User> public class User : IEquatable<User> , INotifyPropertyChanged
{ {
#region Private Attributes #region Private Attributes
@ -25,6 +27,8 @@ namespace Model
[DataMember] private string picture = ""; [DataMember] private string picture = "";
[DataMember] private int password ; [DataMember] private int password ;
[DataMember] private List<Priority> priorities; [DataMember] private List<Priority> priorities;
public event PropertyChangedEventHandler? PropertyChanged;
#endregion #endregion
#region Properties #region Properties
@ -36,13 +40,11 @@ namespace Model
public string Name public string Name
{ {
get { return name; } get { return name; }
private set set
{ {
if (string.IsNullOrWhiteSpace(value))
{
throw new ArgumentException("Impossible d'avoir un champ Nom vide!");
}
name = value; name = value;
OnPropertyChanged();
} }
} }
@ -53,13 +55,11 @@ namespace Model
public string Surname public string Surname
{ {
get { return surname; } get { return surname; }
private set set
{ {
if (string.IsNullOrWhiteSpace(value))
{
throw new ArgumentException("Impossible d'avoir un champ Prénom vide!");
}
surname = value; surname = value;
OnPropertyChanged();
} }
} }
@ -129,6 +129,21 @@ namespace Model
throw new NotImplementedException(); throw new NotImplementedException();
} }
protected void OnPropertyChanged ([CallerMemberName] string? propertyName = null)
{
if (PropertyChanged != null)
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public override string ToString()
{
return $"{Name} {Surname}";
}
public IPasswordManager psswMgr { get; private set; }
#endregion #endregion
#region Constructors #region Constructors
@ -136,15 +151,18 @@ namespace Model
/// <summary> /// <summary>
/// Construtors of user. /// Construtors of user.
/// </summary> /// </summary>
/// <param _name="name">The _name of the user</param> /// <param name="name">The name of the user</param>
/// <param _name="surname">The surname of the user</param> /// <param name="surname">The surname of the user</param>
/// <param _name="mail">The user needs an email to login. </param> /// <param name="mail">The user needs an email to login.</param>
public User(string name, string surname, string mail, int password) /// <param name="password">The password of the new user.</param>
/// <param name="passwordManager">The password manager to manage the user password.</param>
public User(string name, string surname, string mail, string password, IPasswordManager passwordManager )
{ {
Name = name; Name = name;
Surname = surname; Surname = surname;
Mail = mail; Mail = mail;
Password = password; psswMgr = passwordManager;
Password = psswMgr.HashPassword(password);
priorities = new List<Priority> { priorities = new List<Priority> {
Priority.Gourmet, Priority.Gourmet,
Priority.Economic, Priority.Economic,
@ -155,8 +173,40 @@ namespace Model
} }
/// <summary>
/// <inheritdoc cref="User.User"/>
/// </summary>
public User(string name, string surname, string mail, string password)
: this(name, surname,mail, password, new PasswordManager())
{
}
/// <summary>
/// <inheritdoc cref="User.User"/>
/// </summary>
public User()
: this("John", "Doe", "truc@gmail.com", "mdp")
{
}
/// <summary>
/// <inheritdoc cref="User.User"/>
/// </summary>
public User (User user)
{
Name = user.Name;
Surname = user.Surname;
Mail = user.Mail;
psswMgr = user.psswMgr;
Password = user.Password;
priorities = user.Priorities;
ProfilPict = user.ProfilPict;
}
#endregion #endregion
} }
} }

@ -13,7 +13,7 @@ namespace Model_UnitTests
public void TestConstructUser() public void TestConstructUser()
{ {
PasswordManager passwordManager = new PasswordManager(); PasswordManager passwordManager = new PasswordManager();
User user = new User("Bob", "Dylan", "bd@gmail.com", passwordManager.HashPassword("bobby")); User user = new User("Bob", "Dylan", "bd@gmail.com", "bobby");
Assert.Equal("Bob", user.Name); Assert.Equal("Bob", user.Name);
Assert.Equal("Dylan", user.Surname); Assert.Equal("Dylan", user.Surname);
Assert.Equal("bd@gmail.com", user.Mail); Assert.Equal("bd@gmail.com", user.Mail);

@ -1,38 +1,44 @@
#if WINDOWS #if WINDOWS
using Microsoft.UI; using Microsoft.UI;
using Microsoft.UI.Windowing; using Microsoft.UI.Windowing;
using Windows.Graphics; using Windows.Graphics;
#endif #endif
namespace Views using DataPersistence;
{ using Model;
public partial class App : Application
{ namespace Views
const int WindowWidth = 1200; {
const int WindowHeight = 800; public partial class App : Application
{
public App() public DataManager DataMgr { get; private set; } = new DataManager(new Stubs());
{ public User user { get; set; }
InitializeComponent(); const int WindowWidth = 1200;
const int WindowHeight = 800;
Microsoft.Maui.Handlers.WindowHandler.Mapper.AppendToMapping(nameof(IWindow), (handler, view) =>
{ public App()
#if WINDOWS {
var mauiWindow = handler.VirtualView; user = DataMgr.Data[nameof(User)].Cast<User>().Last();
var nativeWindow = handler.PlatformView; InitializeComponent();
nativeWindow.Activate();
IntPtr windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(nativeWindow); Microsoft.Maui.Handlers.WindowHandler.Mapper.AppendToMapping(nameof(IWindow), (handler, view) =>
WindowId windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(windowHandle); {
AppWindow appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId); #if WINDOWS
appWindow.Resize(new SizeInt32(WindowWidth, WindowHeight)); var mauiWindow = handler.VirtualView;
#endif var nativeWindow = handler.PlatformView;
}); nativeWindow.Activate();
IntPtr windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(nativeWindow);
WindowId windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(windowHandle);
/* - Comment(ctrl-k + ctrl-c)/Uncomment(ctrl-k + ctrl-u) to change page - */ AppWindow appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId);
UserAppTheme = AppTheme.Light; appWindow.Resize(new SizeInt32(WindowWidth, WindowHeight));
MainPage = new MyProfil(); #endif
//MainPage = new MyPosts(); });
}
}
} /* - Comment(ctrl-k + ctrl-c)/Uncomment(ctrl-k + ctrl-u) to change page - */
UserAppTheme = AppTheme.Light;
MainPage = new AddRecipe();
//MainPage = new MyPosts();
}
}
}

@ -28,11 +28,19 @@
Style="{StaticResource button2}" Style="{StaticResource button2}"
IsVisible="{Binding IsNotConnected, Source={x:Reference fl}}" IsVisible="{Binding IsNotConnected, Source={x:Reference fl}}"
IsEnabled="{Binding IsNotConnected, Source={x:Reference fl}}"/> IsEnabled="{Binding IsNotConnected, Source={x:Reference fl}}"/>
<Label Text="Jean-Baptiste De La Fontaine" <StackLayout BindingContext="{Binding user}">
HorizontalOptions="Center" Margin="15" <Label Text="{Binding Name}"
HorizontalOptions="Center" Margin="0,15"
FontSize="20" FontAttributes="Bold" HorizontalTextAlignment="Center" FontSize="20" FontAttributes="Bold" HorizontalTextAlignment="Center"
TextColor="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource White}}" TextColor="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource White}}"
IsVisible="{Binding IsNotConnected, Converter={toolkit:InvertedBoolConverter} ,Source={x:Reference fl}}"/> IsVisible="{Binding IsNotConnected, Converter={toolkit:InvertedBoolConverter} ,Source={x:Reference fl}}"/>
<Label Text="{Binding Surname}"
HorizontalOptions="Center"
FontSize="20" FontAttributes="Bold" HorizontalTextAlignment="Center"
TextColor="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource White}}"
IsVisible="{Binding IsNotConnected, Converter={toolkit:InvertedBoolConverter} ,Source={x:Reference fl}}"/>
</StackLayout>
</VerticalStackLayout> </VerticalStackLayout>

@ -1,39 +1,49 @@
namespace Views; using DataPersistence;
using Model;
public partial class ContainerFlyout : ContentView
{ namespace Views;
public ContainerFlyout()
{ public partial class ContainerFlyout : ContentView
InitializeComponent(); {
} public DataManager DataMgr => (App.Current as App).DataMgr;
public User user => (App.Current as App).user;
// Bind MyFlyoutContent
public static readonly BindableProperty MyFlyoutContentProperty =
BindableProperty.Create("MyFlyoutContent", typeof(View), typeof(ContainerFlyout), new Grid()); public ContainerFlyout()
{
public View MyFlyoutContent InitializeComponent();
{ BindingContext = this;
get => (View)GetValue(MyFlyoutContentProperty);
set => SetValue(MyFlyoutContentProperty, value);
} }
// Bind IsNotConnected // Bind MyFlyoutContent
public static readonly BindableProperty IsNotConnectedProperty = public static readonly BindableProperty MyFlyoutContentProperty =
BindableProperty.Create("IsNotConnected", typeof(bool), typeof(Button), true); BindableProperty.Create("MyFlyoutContent", typeof(View), typeof(ContainerFlyout), new Grid());
public bool IsNotConnected public View MyFlyoutContent
{ {
get => (bool)GetValue(IsNotConnectedProperty); get => (View)GetValue(MyFlyoutContentProperty);
set => SetValue(IsNotConnectedProperty, value); set => SetValue(MyFlyoutContentProperty, value);
} }
// bind NeedReturn // Bind IsNotConnected
public static readonly BindableProperty NeedReturnProperty = public static readonly BindableProperty IsNotConnectedProperty =
BindableProperty.Create("NeedReturn", typeof(bool), typeof(Border), false); BindableProperty.Create("IsNotConnected", typeof(bool), typeof(Button), true);
public bool NeedReturn public bool IsNotConnected
{ {
get => (bool)GetValue(NeedReturnProperty); get => (bool)GetValue(IsNotConnectedProperty);
set => SetValue(NeedReturnProperty, value); set => SetValue(IsNotConnectedProperty, value);
} }
}
// bind NeedReturn
public static readonly BindableProperty NeedReturnProperty =
BindableProperty.Create("NeedReturn", typeof(bool), typeof(Border), false);
public bool NeedReturn
{
get => (bool)GetValue(NeedReturnProperty);
set => SetValue(NeedReturnProperty, value);
}
}

@ -14,8 +14,8 @@
<Grid RowDefinitions="250, *, *" VerticalOptions="Fill"> <Grid RowDefinitions="250, *, *" VerticalOptions="Fill">
<VerticalStackLayout Grid.Row="1"> <VerticalStackLayout Grid.Row="1">
<Button Text="Mes informations" ImageSource="person_default.png" Style="{StaticResource button1}" Grid.Row="1"/> <Button Text="Mes Recettes" ImageSource="person_default.png" Style="{StaticResource button1}" Grid.Row="1"/>
<Button Text="Modifier" ImageSource="settings_icon.png" Style="{StaticResource button1}" Grid.Row="2"/> <Button Text="Ajouter Recette" ImageSource="settings_icon.png" Style="{StaticResource button1}" Grid.Row="2"/>
</VerticalStackLayout> </VerticalStackLayout>
</Grid> </Grid>
@ -24,7 +24,8 @@
<local:ContainerBase.MyContent> <local:ContainerBase.MyContent>
<ScrollView> <ScrollView>
<StackLayout BindingContext="User"><!--Attention debut de binding--> <StackLayout >
<!--user's informations-->
<Label Text="Mon profil" TextColor="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource Gray100}}" <Label Text="Mon profil" TextColor="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource Gray100}}"
FontAttributes="Bold" FontAttributes="Bold"
FontSize="24" Padding="15, 15, 20, 5"/> FontSize="24" Padding="15, 15, 20, 5"/>
@ -36,30 +37,28 @@
Padding="50,0,0,0" Padding="50,0,0,0"
FontSize="18"/> FontSize="18"/>
<Entry BackgroundColor="#D1E8E2" <Entry BackgroundColor="#D1E8E2"
Margin="50,10,0,20"/> Margin="50,10,0,20"
Text="{Binding userBis.Name}"/>
<Label Text="Prénom :" <Label Text="Prénom :"
Padding="50,0,0,0" Padding="50,0,0,0"
FontSize="18"/> FontSize="18"/>
<Entry BackgroundColor="#D1E8E2" <Entry BackgroundColor="#D1E8E2"
Margin="50,10,0,20"/> Margin="50,10,0,20"
Text="{Binding userBis.Surname} "/>
<Label Text="Mail :" <Label Text="Mail :"
Padding="50,0,0,0" Padding="50,0,0,0"
FontSize="18"/> FontSize="18"/>
<Entry BackgroundColor="#D1E8E2" <Entry BackgroundColor="#D1E8E2"
Margin="50,10,0,20"/> Margin="50,10,0,20"
<Label Text="Pseudo :" IsEnabled="False"
Padding="50,0,0,0" Text="{Binding user.Mail}"/>
FontSize="18"/>
<Entry BackgroundColor="#D1E8E2"
Margin="50,10,0,50"/>
<Button BackgroundColor="#bdf5bd" <Button BackgroundColor="#bdf5bd"
Text="Valider" Text="Modifier"
Margin="40,0,0,0" Margin="40,0,0,0"
TextColor="Black" TextColor="Black"
MaximumWidthRequest="100"/> MaximumWidthRequest="100"
Clicked="Validation_Click"/>
<!--liste drag and drop-->
</VerticalStackLayout> </VerticalStackLayout>
<VerticalStackLayout Padding="100,0,0,0"> <VerticalStackLayout Padding="100,0,0,0">
<Label Text="Priorités du compte : " TextColor="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource Gray100}}" <Label Text="Priorités du compte : " TextColor="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource Gray100}}"
@ -67,44 +66,34 @@
<Grid BackgroundColor="#D1E8E2" <Grid BackgroundColor="#D1E8E2"
MinimumHeightRequest="300" MinimumHeightRequest="300"
Padding="20"> Padding="20">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Label Text="Recettes économiques" Grid.Row="0" Padding="5,0,0,0"/> <Label Text="Recettes économiques" Grid.Row="0" Padding="5,0,0,0"/>
<BoxView Color="Black" HeightRequest="1" Margin="10,10,10,10" Grid.Row="1" /> <BoxView Color="Black" HeightRequest="1" Margin="10,10,10,10" Grid.Row="1" />
<Label Text="Recettes rapides" Grid.Row="2"/> <Label Text="Recettes rapides" Grid.Row="2"/>
<BoxView Color="Black" HeightRequest="1" Margin="10,10,10,10" Grid.Row="3" /> <BoxView Color="Black" HeightRequest="1" Margin="10,10,10,10" Grid.Row="3" />
<Label Text="Recettes simples" Grid.Row="4"/> <Label Text="Recettes simples" Grid.Row="4"/>
<BoxView Color="Black" HeightRequest="1" Margin="10,10,10,10" Grid.Row="5" /> <BoxView Color="Black" HeightRequest="1" Margin="10,10,10,10" Grid.Row="5" />
<Label Text="Recettes légères" Grid.Row="6"/> <Label Text="Recettes légères" Grid.Row="6"/>
<BoxView Color="Black" HeightRequest="1" Margin="10,10,10,10" Grid.Row="7" /> <BoxView Color="Black" HeightRequest="1" Margin="10,10,10,10" Grid.Row="7" />
<Label Text="Recettes gourmandes" Grid.Row="8"/> <Label Text="Recettes gourmandes" Grid.Row="8"/>
</Grid> </Grid>
</VerticalStackLayout> </VerticalStackLayout>
</HorizontalStackLayout> </HorizontalStackLayout>
</StackLayout> </StackLayout>
</ScrollView> </ScrollView>
</local:ContainerBase.MyContent> </local:ContainerBase.MyContent>
</local:ContainerBase> </local:ContainerBase>
</ContentPage> </ContentPage>

@ -1,9 +1,31 @@
namespace Views; using CommunityToolkit.Maui.Behaviors;
using DataPersistence;
public partial class MyProfil : ContentPage using Model;
{ using System.Diagnostics;
public MyProfil()
{ namespace Views;
InitializeComponent();
} public partial class MyProfil : ContentPage
{
public DataManager DataMgr => (App.Current as App).DataMgr;
public User user => (App.Current as App).user;
public User userBis {get; set; }
public MyProfil()
{
userBis = new User(user);
InitializeComponent();
BindingContext = this;
}
public void Validation_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(userBis.Name) || String.IsNullOrEmpty(userBis.Surname)){
return;
}
user.Name = userBis.Name;
user.Surname = userBis.Surname;
}
} }

@ -57,10 +57,14 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\DataPersistence\DataPersistence.csproj" />
<ProjectReference Include="..\Model\Model.csproj" /> <ProjectReference Include="..\Model\Model.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<MauiXaml Update="AddRecipe.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="ContainerBase.xaml"> <MauiXaml Update="ContainerBase.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>

Loading…
Cancel
Save