rename PasswordManager to PasswordSHA256 to distinguish corrctly the strategy. + add some doc

pull/48/head
Alexandre AGOSTINHO 2 years ago
parent 8c85fee64d
commit 3039a0b74e

@ -49,7 +49,7 @@ namespace DataPersistence
typeof(User),
typeof(Ingredient),
typeof(Quantity),
typeof(PasswordManager)
typeof(PasswordSHA256)
},
PreserveObjectReferences = true
};

@ -9,14 +9,38 @@ using System.Threading.Tasks;
namespace Model.Managers
{
/// <summary>
/// The Main manager of the model.
/// </summary>
public class MasterManager
{
#region Attributes & Properties
/// <summary>
/// The currently connected user. 'null' if no user is connected.
/// </summary>
public User? CurrentConnectedUser { get; private set; }
/// <summary>
/// The collection of all recipes loaded.
/// </summary>
public RecipeCollection Recipes { get; private set; }
/// <summary>
/// The collection of all users loaded.
/// </summary>
public List<User> Users { get; private set; }
/// <summary>
/// The data manager for load, save, export and import data.
/// </summary>
public DataManager DataMgr { get; private set; }
#endregion
#region Constructors
/// <summary>
/// Constructor of the MasterManager.
/// </summary>
/// <param name="dataManager">The serializer for the data.</param>
public MasterManager(IDataManager dataManager)
{
DataMgr = new DataManager(dataManager);
@ -24,7 +48,16 @@ namespace Model.Managers
Recipes = DataMgr.GetRecipes("all recipes");
Users = DataMgr.GetUsers();
}
#endregion
#region Methods
/// <summary>
/// Log in an user. Test if the log in information are correct then connect the user.
/// </summary>
/// <param name="mail">The user's mail</param>
/// <param name="password">The user's password.</param>
/// <returns>True if the user was correctly connected, false if there is something wrong.</returns>
/// <exception cref="ArgumentNullException"></exception>
public bool Login(string mail, string password)
{
if (Users is null || Users.Count == 0)
@ -45,6 +78,10 @@ namespace Model.Managers
return true;
}
/// <summary>
/// Log out an user.
/// </summary>
/// <returns>True if the user is correctly diconnected, false otherwise.</returns>
public bool Logout()
{
if (CurrentConnectedUser is null)
@ -54,6 +91,11 @@ namespace Model.Managers
return true;
}
/// <summary>
/// Register an user.
/// </summary>
/// <param name="newuser">The new user to add in the database.</param>
/// <returns>False if there is a problem with the registerement, true otherwise.</returns>
public bool Register(User newuser)
{
try
@ -71,14 +113,23 @@ namespace Model.Managers
return true;
}
/// <summary>
/// Add a recipe to the database.
/// </summary>
/// <param name="recipe">The recipe to add.</param>
public void AddRecipe(Recipe recipe)
{
DataMgr.Data[nameof(Recipe)].Add(recipe);
Recipes = DataMgr.GetRecipes();
}
/// <summary>
/// Get the current connected user's personal recipes.
/// </summary>
/// <returns>The current connected user's personal recipes.</returns>
public RecipeCollection GetCurrentUserRecipes()
=> new RecipeCollection("User recipes",
DataMgr.GetRecipes().FindAll(r => r.AuthorMail == CurrentConnectedUser?.Mail).ToArray());
}
#endregion
}

@ -10,21 +10,34 @@ using System.Xml.Linq;
namespace Model
{
/// <summary>
/// Define a Review of a recipe.
/// </summary>
[DataContract(Name = "review")]
public class Review : IEquatable<Review>
{
#region Attributes & Properties
[DataMember(Name = "stars")]
private int _stars;
[DataMember(Name = "content")]
private string _content = "";
/// <summary>
/// The Id of the review.
/// </summary>
[DataMember(Name = "id")]
public int Id { get; init; }
/// <summary>
/// The mail of the author of the review.
/// </summary>
[DataMember(Name = "authorMail")]
public string AuthorMail { get; private set; }
/// <summary>
/// The number of stars the review give.
/// </summary>
public int Stars
{
get => _stars;
@ -35,6 +48,9 @@ namespace Model
}
}
/// <summary>
/// The comment in the review.
/// </summary>
public string Content
{
get => _content;
@ -44,7 +60,16 @@ namespace Model
else _content = value;
}
}
#endregion
#region Constructors
/// <summary>
/// Constructor of a review.
/// </summary>
/// <param name="authorMail">The review's author's mail.</param>
/// <param name="id">The id of the review.</param>
/// <param name="stars">The mark to give for the recipe.</param>
/// <param name="content">A comment about the recipe.</param>
public Review(string authorMail, int? id, int stars, string content)
{
if (id == null)
@ -61,16 +86,24 @@ namespace Model
Content = content;
}
/// <summary>
/// <inheritdoc/>
/// </summary>
public Review(string authorMail, int stars, string content)
: this(authorMail, null, stars, content)
{
}
/// <summary>
/// <inheritdoc/>
/// </summary>
public Review(int stars, string content)
: this("admin@mctg.fr", null, stars, content)
{
}
#endregion
#region Methods
public override string ToString()
{
return $"{AuthorMail}: [ {Stars} stars ]\n{Content}";
@ -95,5 +128,6 @@ namespace Model
{
return Id.GetHashCode();
}
#endregion
}
}

@ -9,7 +9,7 @@ using System.Threading.Tasks;
namespace Model
{
[DataContract(Name = "passmgr")]
public class PasswordManager : IPasswordManager
public class PasswordSHA256 : IPasswordManager
{
public string HashPassword(string password)
{

@ -1,12 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using System.Text;
using System.Runtime.Serialization;
using System.ComponentModel;
@ -178,7 +171,7 @@ namespace Model
/// <inheritdoc cref="User.User"/>
/// </summary>
public User(string name, string surname, string mail, string password)
: this(name, surname,mail, password, new PasswordManager())
: this(name, surname,mail, password, new PasswordSHA256())
{
}
@ -210,4 +203,3 @@ namespace Model
#endregion
}
}

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

Loading…
Cancel
Save