connection 1st ver. + view profile 1st ver. - error on login

pull/48/head
Alexandre AGOSTINHO 2 years ago
parent 04192a2ef2
commit 6116578585

@ -4,22 +4,47 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ConsoleApp.Menu.Core; using ConsoleApp.Menu.Core;
using Model.Managers;
namespace ConsoleApp.Menu namespace ConsoleApp.Menu
{ {
internal class ConnectionMenu : Entry internal class ConnectionMenu : Entry
{ {
public ConnectionMenu() private MasterManager _masterMgr;
private bool _wrongInput = false;
public ConnectionMenu(MasterManager masterManager)
: base("Connection", : base("Connection",
new Entry.EntryStep("Username: ", typeof(string)), new Entry.EntryStep("Mail: ", typeof(string)),
new Entry.EntryStep("Password: ", typeof(string))) new Entry.EntryStep("Password: ", typeof(string), true))
{ } {
_masterMgr = masterManager;
}
public override void Display()
{
base.Display();
if (_wrongInput)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Wrong input...");
Console.ResetColor();
}
}
public override IMenu? Return() public override IMenu? Return()
{ {
string username = _selectList[0].Item.Input; string mail = _selectList[0].Item.Input;
string password = _selectList[1].Item.Input; string password = _selectList[1].Item.Input;
return new PlainText($"User: {username} connected with password: {password}");
if (!_masterMgr.Login(mail, password))
{
_wrongInput = true;
return this;
}
else
return null;
} }
} }
} }

@ -25,6 +25,11 @@ namespace ConsoleApp.Menu.Core
/// Contain the input gave by the menu. /// Contain the input gave by the menu.
/// </summary> /// </summary>
public string Input { get; internal set; } public string Input { get; internal set; }
/// <summary>
/// Define whether the input need to be hidden. Useful for password.
/// </summary>
public bool Hidden { get; private set; }
#endregion #endregion
#region Constructors #region Constructors
@ -33,11 +38,12 @@ namespace ConsoleApp.Menu.Core
/// </summary> /// </summary>
/// <param name="description">The text generally placed before the input in the menu.</param> /// <param name="description">The text generally placed before the input in the menu.</param>
/// <param name="type">The type of the returned input.</param> /// <param name="type">The type of the returned input.</param>
public EntryStep(string description, Type type) public EntryStep(string description, Type type, bool hidden = false)
{ {
Description = description; Description = description;
Input = ""; Input = "";
_entryType = type; _entryType = type;
Hidden = hidden;
} }
#endregion #endregion

@ -23,7 +23,8 @@ namespace ConsoleApp.Menu.Core
/// </summary> /// </summary>
/// <param name="title">The title of this menu.</param> /// <param name="title">The title of this menu.</param>
/// <param name="entrySteps">All the entries of this menu.</param> /// <param name="entrySteps">All the entries of this menu.</param>
protected Entry(string title, params EntryStep[] entrySteps) : base(title) protected Entry(string title, params EntryStep[] entrySteps)
: base(title)
{ {
_steps = entrySteps.ToList(); _steps = entrySteps.ToList();
_allSelectors = ConvertEntryStepsInSelector(); _allSelectors = ConvertEntryStepsInSelector();
@ -71,6 +72,9 @@ namespace ConsoleApp.Menu.Core
return; return;
} }
if (CurrentSelected is not null && CurrentSelected.Hidden)
InputStr.Append('*');
else
InputStr.Append(cki.KeyChar); InputStr.Append(cki.KeyChar);
} }
} }

@ -22,8 +22,8 @@ namespace ConsoleApp.Menu
new SearcherRecipe(masterManager.DataMgr.GetRecipes("search")), "Recipe search")); new SearcherRecipe(masterManager.DataMgr.GetRecipes("search")), "Recipe search"));
_allSelectors.Add(MasterManager.CurrentConnectedUser is null ? _allSelectors.Add(MasterManager.CurrentConnectedUser is null ?
new Selector<IMenu>(new ConnectionMenu(), "Connection") new Selector<IMenu>(new ConnectionMenu(masterManager), "Connection")
: new Selector<IMenu>(new PlainText("User profile"), "User profile")); : new Selector<IMenu>(new ProfileMenu(masterManager), "User profile"));
} }
protected override List<Selector<IMenu>> SearchInSelection() protected override List<Selector<IMenu>> SearchInSelection()

@ -0,0 +1,24 @@
using ConsoleApp.Menu.Core;
using Model.Managers;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp.Menu
{
internal class ProfileMenu : Menu<IMenu>
{
public ProfileMenu(MasterManager masterManager)
: base("Profile")
{
_allSelectors.Add(new Selector<IMenu>(
new SearcherRecipe(new RecipeCollection("My recipes",
masterManager.DataMgr.GetRecipes().Where(r => r.Author == MasterManager.CurrentConnectedUser).ToArray())),
"My recipes"));
}
}
}

@ -9,8 +9,8 @@ using Model.Managers;
Console.WriteLine("Hello, World!\n\n"); Console.WriteLine("Hello, World!\n\n");
MasterManager masterMgr = new MasterManager(new Stubs()); MasterManager masterMgr = new MasterManager(new Stubs());
//MasterMgr masterMgr = new MasterMgr(new DataContractXML()); //_masterMgr masterMgr = new _masterMgr(new DataContractXML());
//MasterMgr masterMgr = new MasterMgr(new DataContractJSON()); //_masterMgr masterMgr = new _masterMgr(new DataContractJSON());
masterMgr.DataMgr.Serializer = new DataContractXML(); masterMgr.DataMgr.Serializer = new DataContractXML();
//masterMgr.Serializer = new DataContractJSON(); //masterMgr.Serializer = new DataContractJSON();

Loading…
Cancel
Save