From f3fc87dd10b3d55591a84ecbfb0612769f0c09b9 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Tue, 28 Aug 2018 16:35:16 +0300 Subject: Working on BL Builders ! Working on making PPC work with builders.. --- .../DefaultAuthenticationProvider.cs | 41 ++++++++++++++-------- 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/Authentication') diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Authentication/DefaultAuthenticationProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Authentication/DefaultAuthenticationProvider.cs index 3dae9d05a..23761eb9b 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Authentication/DefaultAuthenticationProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Authentication/DefaultAuthenticationProvider.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.BL; +using Tango.BL.Builders; using Tango.BL.Entities; using Tango.Core; using Tango.Core.DI; @@ -50,24 +51,34 @@ namespace Tango.PPC.UI.Authentication /// The email. /// The password. /// - public User Login(string email, string password) + public Task Login(string email, string password) { - String hash = User.GetPasswordHash(password); - - LogManager.Log($"Logging in user {email}..."); - CurrentUser = ObservablesStaticCollections.Instance.Users.SingleOrDefault(x => x.Email.ToLower() == email && x.Password == hash); - - if (CurrentUser != null) - { - LogManager.Log($"Current user is now: {CurrentUser.Contact.FullName}."); - } - else + return Task.Factory.StartNew(() => { - LogManager.Log("Login failed!"); - } + String hash = User.GetPasswordHash(password); - CurrentUserChanged?.Invoke(this, CurrentUser); - return CurrentUser; + LogManager.Log($"Logging in user {email}..."); + + using (var db = ObservablesContext.CreateDefault()) + { + CurrentUser = new UserBuilder(db).Set(x => x.Email.ToLower() == email && x.Password == hash) + .WithOrganization() + .WithRolesAndPermissions() + .Build(); + } + + if (CurrentUser != null) + { + LogManager.Log($"Current user is now: {CurrentUser.Contact.FullName}."); + } + else + { + LogManager.Log("Login failed!"); + } + + CurrentUserChanged?.Invoke(this, CurrentUser); + return CurrentUser; + }); } /// -- cgit v1.3.1