diff options
Diffstat (limited to 'Software/Visual_Studio/FSE/Tango.FSE.UI/Authentication/DefaultAuthenticationProvider.cs')
| -rw-r--r-- | Software/Visual_Studio/FSE/Tango.FSE.UI/Authentication/DefaultAuthenticationProvider.cs | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/Software/Visual_Studio/FSE/Tango.FSE.UI/Authentication/DefaultAuthenticationProvider.cs b/Software/Visual_Studio/FSE/Tango.FSE.UI/Authentication/DefaultAuthenticationProvider.cs index 0433a2d01..176a7eefa 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.UI/Authentication/DefaultAuthenticationProvider.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.UI/Authentication/DefaultAuthenticationProvider.cs @@ -73,12 +73,14 @@ namespace Tango.FSE.UI.Authentication /// <param name="password">The password.</param> /// <param name="environment">The environment.</param> /// <returns></returns> - public Task<AuthenticationResult> Login(String email, String password, EnvironmentConfiguration environment) + public Task<AuthenticationResult> Login(String email, String password, EnvironmentConfiguration environment, Action<String> onStatusChanged = null) { return Task.Factory.StartNew<AuthenticationResult>(() => { LogManager.Log($"Logging in user {email}..."); + onStatusChanged?.Invoke($"Logging in user {email}..."); + var settings = SettingsManager.Default.GetOrCreate<FSESettings>(); settings.MachineServiceAddress = environment.MachineServiceAddress; @@ -102,6 +104,8 @@ namespace Tango.FSE.UI.Authentication try { + onStatusChanged?.Invoke($"Contacting machine service on '{_webClient.Address}'..."); + response = _webClient.Login(new LoginRequest() { @@ -128,23 +132,34 @@ namespace Tango.FSE.UI.Authentication return new AuthenticationResult() { Response = response }; } + User user = null; + using (var db = ObservablesContext.CreateDefault()) { - CurrentUser = new UserBuilder(db).Set(x => x.Email.ToLower() == email.ToLower()) + user = new UserBuilder(db).Set(x => x.Email.ToLower() == email.ToLower()) .WithOrganization() .WithRolesAndPermissions() .Build(); } - if (CurrentUser != null) + if (user != null) { - LogManager.Log($"Current user is now: {CurrentUser.Contact.FullName}."); + LogManager.Log($"Current user is now: {user.Contact.FullName}."); } else { throw new AuthenticationException("Login failed for some strange reason."); } + onStatusChanged?.Invoke("Loading static collections..."); + + ObservablesStaticCollections.Instance.Initialize((msg) => + { + onStatusChanged?.Invoke(msg); + }); + + CurrentUser = user; + settings.Save(); CurrentUserChanged?.Invoke(this, CurrentUser); |
