aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Web/Tango.MachineService/Controllers
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/Web/Tango.MachineService/Controllers')
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs69
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs40
2 files changed, 97 insertions, 12 deletions
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs
index 245c18b9b..8485cd67d 100644
--- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs
+++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs
@@ -1,4 +1,5 @@
-using System;
+using Microsoft.IdentityModel.Clients.ActiveDirectory;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
@@ -6,10 +7,14 @@ using System.Net.Http;
using System.Security.Authentication;
using System.Web.Http;
using Tango.BL;
+using Tango.BL.Builders;
using Tango.BL.Entities;
using Tango.BL.Enumerations;
+using Tango.Core.Cryptography;
using Tango.MachineService.Helpers;
using Tango.MachineService.Models;
+using Tango.MachineStudio.Common.Authentication;
+using System.Data.Entity;
using Tango.MachineStudio.Common.Update;
namespace Tango.MachineService.Controllers
@@ -23,6 +28,8 @@ namespace Tango.MachineService.Controllers
_pendingUploads = new List<MachineStudioPendingUpload>();
}
+ #region Update
+
[HttpPost]
public CheckForUpdatesResponse CheckForUpdates(CheckForUpdatesRequest request)
{
@@ -100,7 +107,7 @@ namespace Tango.MachineService.Controllers
var user = db.Users.SingleOrDefault(x => x.Email.ToLower() == request.Email.ToLower() && x.Password == request.Password);
- if (user != null && user.HasPermission(Permissions.PublishMachineStudioVersion))
+ if (user != null && user.HasPermission(Permissions.PublishMachineStudioVersions))
{
var latestVersion = db.MachineStudioVersions.ToList().OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault();
Version currentVersion = Version.Parse(request.Version);
@@ -182,5 +189,63 @@ namespace Tango.MachineService.Controllers
return new LatestVersionResponse() { Version = version != null ? version.Version : "0.0.0.0" };
}
}
+
+ #endregion
+
+ [HttpPost]
+ public LoginResponse Login(LoginRequest request)
+ {
+ AuthenticationResult authResult = AzureDirectoryHelper.AuthenticateUser(request.Email, request.Password);
+
+ using (ObservablesContext db = ObservablesContextHelper.CreateContext())
+ {
+ db.Roles.ToList();
+ db.Permissions.ToList();
+ db.UsersRoles.ToList();
+ db.RolesPermissions.ToList();
+
+ var user = db.Users.SingleOrDefault(x => x.Email.ToLower() == request.Email.ToLower());
+
+ IHashGenerator g = new BasicHashGenerator();
+
+ if (user == null)
+ {
+ //Than add the user !!
+ User new_user = new User();
+ new_user.Email = request.Email;
+ new_user.Password = g.Encrypt(request.Password);
+ new_user.Organization = db.Organizations.Include(x => x.Address).Single(x => x.Name == "Twine");
+ new_user.Address = new_user.Organization.Address.Clone();
+ new_user.Contact = new Contact()
+ {
+ FirstName = authResult.UserInfo.GivenName,
+ LastName = authResult.UserInfo.FamilyName,
+ FullName = authResult.UserInfo.GivenName + " " + authResult.UserInfo.FamilyName,
+ Email = request.Email,
+ };
+ new_user.Roles.Add(db.Roles.Single(x => (Roles)x.Code == Roles.User));
+ }
+ else
+ {
+ user.Password = g.Encrypt(request.Password);
+ }
+
+ db.SaveChanges();
+ }
+
+ return new LoginResponse()
+ {
+ DataSource = new Core.DataSource()
+ {
+ Address = Config.DB_ADDRESS,
+ Catalog = Config.DB_CATALOG,
+ Type = Core.DataSourceType.Azure,
+ IntegratedSecurity = false,
+ UserName = request.Email,
+ Password = request.Password,
+ }
+ };
+ }
+
}
}
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs
index 9ce22bbb0..68f597fcc 100644
--- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs
+++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs
@@ -18,6 +18,7 @@ using Tango.BL;
using Tango.BL.Builders;
using Tango.BL.Entities;
using Tango.BL.Enumerations;
+using Tango.Core;
using Tango.Core.DB;
using Tango.Core.Helpers;
using Tango.Core.IO;
@@ -101,9 +102,16 @@ namespace Tango.MachineService.Controllers
});
}
- response.DbAddress = Config.DB_ADDRESS;
- response.DbUserName = credentials.UserName;
- response.DbPassword = credentials.Password;
+ response.DataSource = new DataSource()
+ {
+ Address = Config.DB_ADDRESS,
+ Catalog = Config.DB_CATALOG,
+ UserName = credentials.UserName,
+ Password = credentials.Password,
+ IntegratedSecurity = false,
+ Type = DataSourceType.SQLServer,
+ };
+
response.OSKey = machine.OsKey;
response.SetupActivation = machine.SetupActivation;
response.SetupRemoteAssistance = machine.SetupRemoteAssistance;
@@ -160,9 +168,15 @@ namespace Tango.MachineService.Controllers
});
}
- response.DbAddress = Config.DB_ADDRESS;
- response.DbUserName = credentials.UserName;
- response.DbPassword = credentials.Password;
+ response.DataSource = new DataSource()
+ {
+ Address = Config.DB_ADDRESS,
+ Catalog = Config.DB_CATALOG,
+ UserName = credentials.UserName,
+ Password = credentials.Password,
+ IntegratedSecurity = false,
+ Type = DataSourceType.SQLServer,
+ };
}
return response;
@@ -231,9 +245,15 @@ namespace Tango.MachineService.Controllers
});
}
- response.DbAddress = Config.DB_ADDRESS;
- response.DbUserName = credentials.UserName;
- response.DbPassword = credentials.Password;
+ response.DataSource = new DataSource()
+ {
+ Address = Config.DB_ADDRESS,
+ Catalog = Config.DB_CATALOG,
+ UserName = credentials.UserName,
+ Password = credentials.Password,
+ IntegratedSecurity = false,
+ Type = DataSourceType.SQLServer,
+ };
}
return response;
@@ -290,7 +310,7 @@ namespace Tango.MachineService.Controllers
var user = db.Users.SingleOrDefault(x => x.Email.ToLower() == request.Email.ToLower() && x.Password == request.Password);
- if (user != null && user.HasPermission(Permissions.PublishMachineStudioVersion))
+ if (user != null && user.HasPermission(Permissions.PublishPPCVersions))
{
var versions = db.TangoVersions.ToList().Where(x => x.MachineVersionGuid == request.MachineVersionGuid).OrderByDescending(x => Version.Parse(x.Version)).ToList();