aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication')
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs43
1 files changed, 29 insertions, 14 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 fd68ed8d1..ccaedb359 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs
@@ -10,6 +10,9 @@ using Tango.MachineStudio.Common.Authentication;
using Tango.BL;
using Tango.BL.Enumerations;
using System.Data.Entity;
+using Tango.Transport.Web;
+using Tango.Settings;
+using Tango.MachineStudio.Common;
namespace Tango.MachineStudio.UI.Authentication
{
@@ -49,11 +52,29 @@ namespace Tango.MachineStudio.UI.Authentication
/// <exception cref="AuthenticationException">Login failed for user " + email</exception>
public User Login(string email, string password)
{
- using (ObservablesContext db = ObservablesContext.CreateDefault())
+ var settings = SettingsManager.Default.GetOrCreate<MachineStudioSettings>();
+
+
+ IWebTransportClient service = new WebTransportClient();
+ var response = service.PostJson<LoginRequest, LoginResponse>(settings.GetMachineServiceAddress() + "/api/MachineStudio/Login", new LoginRequest()
+ {
+
+ Email = email,
+ Password = password,
+
+ }).Result;
+
+ AccessToken = response.Token;
+
+ if (settings.Environment == MachineStudioSettings.WorkingEnvironment.Remote)
{
+ ObservablesContext.OverrideSettingsDataSource(response.DataSource);
+ }
- String hash = User.GetPasswordHash(password);
+ ObservablesStaticCollections.Instance.Initialize();
+ using (ObservablesContext db = ObservablesContext.CreateDefault())
+ {
db.Roles.Load();
db.Permissions.Load();
db.RolesPermissions.Load();
@@ -62,24 +83,13 @@ namespace Tango.MachineStudio.UI.Authentication
.Include(x => x.UsersRoles)
.Include(x => x.Contact)
.Include(x => x.Address)
- .Include(x => x.Organization).SingleOrDefault(x => x.Email.ToLower() == email.ToLower() && x.Password == hash);
+ .Include(x => x.Organization).SingleOrDefault(x => x.Email.ToLower() == email.ToLower());
if (user == null)
{
throw new AuthenticationException("Invalid credentials for " + email);
}
- if (!user.HasPermission(Permissions.RunMachineStudio))
- {
- throw new AuthenticationException("It seems like you do not have sufficient privileges to run Machine Studio. Please contact your administrator.");
- }
-
- if (user != null)
- {
- user.LastLogin = DateTime.UtcNow;
- db.SaveChanges();
- }
-
CurrentUser = user;
return user;
}
@@ -92,5 +102,10 @@ 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; }
}
}