diff options
| author | Avi Levkovich <avi@twine-s.com> | 2019-02-20 12:22:27 +0200 |
|---|---|---|
| committer | Avi Levkovich <avi@twine-s.com> | 2019-02-20 12:22:27 +0200 |
| commit | a576283d2a9288938796491582dd9f575f3ff571 (patch) | |
| tree | bba67d4b69f337fa209b5050fb69378e28e6f4eb /Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs | |
| parent | b30e6dc276f95c9db3d500d267a273b6486e0dac (diff) | |
| parent | 9646611a494ed9e1ef0673c881ffc66b997f7bb9 (diff) | |
| download | Tango-a576283d2a9288938796491582dd9f575f3ff571.tar.gz Tango-a576283d2a9288938796491582dd9f575f3ff571.zip | |
Merge branch 'master' of https://twinetfs.visualstudio.com/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs index 9be938fb7..d6fb50a8c 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs @@ -15,6 +15,8 @@ using Tango.Settings; using Tango.MachineStudio.Common; using Tango.MachineStudio.Common.StudioApplication; using Tango.Core.Helpers; +using Tango.MachineStudio.Common.Web; +using Tango.BL.Builders; namespace Tango.MachineStudio.UI.Authentication { @@ -25,6 +27,8 @@ namespace Tango.MachineStudio.UI.Authentication /// <seealso cref="Tango.MachineStudio.Common.Authentication.IAuthenticationProvider" /> public class DefaultAuthenticationProvider : ExtendedObject, IAuthenticationProvider { + private MachineStudioWebClient _client; + private User _currentUser; /// <summary> /// Gets the current logged-in user. @@ -46,6 +50,15 @@ namespace Tango.MachineStudio.UI.Authentication public event EventHandler<User> CurrentUserChanged; /// <summary> + /// Initializes a new instance of the <see cref="DefaultAuthenticationProvider"/> class. + /// </summary> + /// <param name="machineStudioWebClient">The machine studio web client.</param> + public DefaultAuthenticationProvider(MachineStudioWebClient machineStudioWebClient) + { + _client = machineStudioWebClient; + } + + /// <summary> /// Performs a user login by the specified email and password. /// </summary> /// <param name="email">The email.</param> @@ -56,9 +69,8 @@ namespace Tango.MachineStudio.UI.Authentication { var settings = SettingsManager.Default.GetOrCreate<MachineStudioSettings>(); - - IWebTransportClient service = new WebTransportClient(); - var response = service.PostJson<LoginRequest, LoginResponse>(settings.GetMachineServiceAddress() + "/api/MachineStudio/Login", new LoginRequest() + _client.Environment = settings.DeploymentSlot; + var response = _client.Login(new LoginRequest() { Email = email, @@ -67,8 +79,6 @@ namespace Tango.MachineStudio.UI.Authentication }).Result; - AccessToken = response.Token; - if (settings.Environment == MachineStudioSettings.WorkingEnvironment.Remote) { ObservablesContext.OverrideSettingsDataSource(response.DataSource); @@ -78,15 +88,7 @@ namespace Tango.MachineStudio.UI.Authentication using (ObservablesContext db = ObservablesContext.CreateDefault()) { - db.Roles.Load(); - db.Permissions.Load(); - db.RolesPermissions.Load(); - - User user = db.Users - .Include(x => x.UsersRoles) - .Include(x => x.Contact) - .Include(x => x.Address) - .Include(x => x.Organization).SingleOrDefault(x => x.Email.ToLower() == email.ToLower()); + User user = new UserBuilder(db).Set(x => x.Email.ToLower() == email.ToLower()).WithRolesAndPermissions().WithOrganization().Build(); if (user == null) { @@ -113,10 +115,5 @@ namespace Tango.MachineStudio.UI.Authentication { CurrentUser = null; } - - /// <summary> - /// Gets the access token that was retrieved at the last login. - /// </summary> - public string AccessToken { get; private set; } } } |
