feature/18-model-user merged on dev
continuous-integration/drone/push Build is failing Details

pull/44/head^2
Roxane ROSSETTO 2 years ago
commit 190e35b54b

@ -23,6 +23,8 @@ dataMgr.Serializer = new DataContractJSON();
//dataMgr.Export(rc[2], "C:\\Users\\alex6\\Downloads\\recipe2.json"); //dataMgr.Export(rc[2], "C:\\Users\\alex6\\Downloads\\recipe2.json");
//dataMgr.Import<Recipe>("C:\\Users\\alex6\\Downloads\\recipe2.json"); //dataMgr.Import<Recipe>("C:\\Users\\alex6\\Downloads\\recipe2.json");
Stub stub = new Stub();
PasswordManager passwordManager = new PasswordManager();
RecipeCollection rc = new RecipeCollection("All recipes", dataMgr.Data[nameof(Recipe)].Cast<Recipe>().ToArray()); RecipeCollection rc = new RecipeCollection("All recipes", dataMgr.Data[nameof(Recipe)].Cast<Recipe>().ToArray());
dataMgr.Save(); dataMgr.Save();
@ -31,5 +33,12 @@ MenuManager menuMgr = new MenuManager(dataMgr);
menuMgr.Loop(); menuMgr.Loop();
// press any key to quit foreach (RecipeCollection r in recipeCollections)
//Console.ReadKey(); Console.WriteLine(r);
List<User> users = stub.ConstrucList();
foreach (User u in users)
Console.WriteLine(u);
bool isPassCorrect = stub.VerifPass();
Console.WriteLine(isPassCorrect);

@ -0,0 +1,79 @@
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp
{
internal struct Stub
{
private IPasswordManager passwordManager = new PasswordManager();
public List<Recipe> LoadRecipes()
{
List<Recipe> stub = new List<Recipe>();
stub.AddRange(new[]
{
new Recipe(),
new Recipe("Cookies"),
new Recipe("Cookies", 23),
new Recipe("Cookies", null),
new Recipe("", null),
new Recipe("", 24),
new Recipe("Cookies", 24,
new PreparationStep(1)),
new Recipe("Cookies", 26,
new PreparationStep(1),
new PreparationStep(2, "Faire cuire."))
});
return stub;
}
public List<RecipeCollection> LoadRecipeCollection()
{
List<RecipeCollection> stub = new List<RecipeCollection>();
stub.AddRange(new[]
{
new RecipeCollection("All", LoadRecipes().ToArray()),
new RecipeCollection("Starters", LoadRecipes().FindAll(x => x.Id.Equals(23)).ToArray()),
new RecipeCollection("Dishies", LoadRecipes().FindAll(x => x.Id.Equals(24)).ToArray()),
new RecipeCollection("Desserts", LoadRecipes().FindAll(x => x.Id.Equals(26)).ToArray()),
});
return stub;
}
public List<User> ConstrucList()
{
List<User> Users = new List<User>();
User Roger = new User("Roger", "Rabbit", "carotte@mail.fr",passwordManager.HashPassword("password"));
User Dylan = new User("d", "r", "dr@mail.fr", passwordManager.HashPassword("dede"));
User Val = new User("V", "entin", "Valentin@mail.fr", passwordManager.HashPassword("valentin"));
Users.Add(Roger);
Users.Add(Dylan);
Users.Add(Val);
return Users;
}
public bool VerifPass()
{
User John = new User("John", "Doe", "JD@gmail.com", passwordManager.HashPassword("GIJD"));
string entryPass = "GIJD";
User Val = new User("V", "entin", "Valentin@mail.fr", passwordManager.HashPassword("valentin"));
Val.Password = passwordManager.HashPassword("jeChange");
bool isPasswordCorrect = passwordManager.VerifyPassword(John.Password, entryPass);
return isPasswordCorrect;
}
public Stub()
{
}
}
}

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.Ingredient
{
internal class Ingredient
{
}
}

@ -8,9 +8,8 @@ namespace Model
{ {
public interface IPasswordManager public interface IPasswordManager
{ {
public void changePassword(User user, string newPassword); public int HashPassword(string password);
public string HashPassword(User user); public bool VerifyPassword(int hashedPassword,string password);
public bool VerifyPassword(string hashedPassword);
} }
} }

@ -8,19 +8,20 @@ namespace Model
{ {
public class PasswordManager : IPasswordManager public class PasswordManager : IPasswordManager
{ {
public void changePassword(User user, string newPassword)
{
throw new NotImplementedException();
}
public string HashPassword(User user) public int HashPassword(string password)
{ {
throw new NotImplementedException(); int hashedPassword = password.GetHashCode();
return hashedPassword;
} }
public bool VerifyPassword(string hashedPassword) public bool VerifyPassword(int hashedPassword, string passwordEntered )
{ {
throw new NotImplementedException(); int passwordEnteredHashed = passwordEntered.GetHashCode();
if ( passwordEnteredHashed == hashedPassword)
return true;
else return false;
} }
} }
} }

@ -5,6 +5,7 @@ using System.Collections.ObjectModel;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Text;
namespace Model namespace Model
{ {
@ -20,8 +21,7 @@ namespace Model
private string surname=""; private string surname="";
private string mail = ""; private string mail = "";
private string picture = ""; private string picture = "";
private string password = ""; private int password ;
//private string defaultUserSavePath = "";
private List<Priority> priorities; private List<Priority> priorities;
#endregion #endregion
@ -79,16 +79,14 @@ namespace Model
} }
} }
///<summary> public int Password
/// Property to initiate password, change it, and
/// </summary>
public string Password
{ {
get { return password; } get => password;
set => password = value;
set { password = value; }
} }
/// <summary> /// <summary>
/// For now, we define the ProfilPict as a string which is "PhotoParDefaut" /// For now, we define the ProfilPict as a string which is "PhotoParDefaut"
/// when the value is null. /// when the value is null.
@ -111,15 +109,16 @@ namespace Model
set=> priorities = value; set=> priorities = value;
} }
public override bool Equals(object? obj) public override bool Equals(object? other)
{ {
if (obj == null) return false; if (other == null) return false;
if (obj == this) return true; if (other == this) return true;
return Equals(obj); return Equals(other);
} }
public bool Equals(User? other) public bool Equals(User? other)
{ {
if (other == null ) return false; if (other == null) return false;
return Name.Equals(other.Name) && Surname.Equals(other.Surname) && Mail.Equals(other.Mail); return Name.Equals(other.Name) && Surname.Equals(other.Surname) && Mail.Equals(other.Mail);
} }
@ -135,11 +134,12 @@ namespace Model
/// <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) public User(string name, string surname, string mail, int password)
{ {
Name = name; Name = name;
Surname = surname; Surname = surname;
Mail = mail; Mail = mail;
Password = password;
priorities = new List<Priority> { priorities = new List<Priority> {
Priority.Gourmet, Priority.Gourmet,
Priority.Economic, Priority.Economic,

@ -0,0 +1,31 @@
<<<<<<< HEAD
<Project Sdk="Microsoft.NET.Sdk">
=======
<Project Sdk="Microsoft.NET.Sdk">
>>>>>>> feature/18-model-user
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<Configurations>Debug;Release;CI</Configurations>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Model\Model.csproj" />
<ProjectReference Include="..\..\DataPersistence\DataPersistence.csproj" />
</ItemGroup>
</Project>

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net7.0</TargetFramework> <TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>

@ -12,8 +12,13 @@ namespace Model_UnitTests
[Fact] [Fact]
public void TestConstructUser() public void TestConstructUser()
{ {
User? user = new User("Bob","Dylan", "bd@gmail.com"); PasswordManager passwordManager = new PasswordManager();
Assert.NotNull(user); User user = new User("Bob", "Dylan", "bd@gmail.com", passwordManager.HashPassword("bobby"));
Assert.Equal("Bob", user.Name);
Assert.Equal("Dylan", user.Surname);
Assert.Equal("bd@gmail.com", user.Mail);
Assert.Equal(passwordManager.HashPassword("bobby"), user.Password);
Assert.NotNull(user.Priorities);
} }
} }
} }

Loading…
Cancel
Save