aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs
diff options
context:
space:
mode:
authorShlomo Hecht <shlomo@twine-s.com>2019-02-20 16:49:00 +0200
committerShlomo Hecht <shlomo@twine-s.com>2019-02-20 16:49:00 +0200
commitcb13435931b24d6c156804f70fcfdb78865e4c11 (patch)
tree83c9893fbb2a0e25b374ab09780bd6c946bce08f /Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs
parent232cfcfd6388681f7b9a3f1eedead28dbdab9e70 (diff)
parent1767535a1e6ecbdb05ffe62dda85c9fb78e6718f (diff)
downloadTango-cb13435931b24d6c156804f70fcfdb78865e4c11.tar.gz
Tango-cb13435931b24d6c156804f70fcfdb78865e4c11.zip
merge
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.cs35
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; }
}
}