aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Web/Tango.MachineService
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/Web/Tango.MachineService')
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEController.cs113
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs2
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs2
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj7
4 files changed, 121 insertions, 3 deletions
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEController.cs
new file mode 100644
index 000000000..abcd1c41f
--- /dev/null
+++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEController.cs
@@ -0,0 +1,113 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Net.Http;
+using System.Security.Authentication;
+using System.Web.Http;
+using Tango.BL.Builders;
+using Tango.BL.Entities;
+using Tango.Core;
+using Tango.Core.Cryptography;
+using Tango.FSE.Web.Messages;
+using Tango.Web.Controllers;
+using Tango.Web.Helpers;
+using Tango.Web.Security;
+using Tango.Web.SQLServer;
+
+namespace Tango.MachineService.Controllers
+{
+ public class FSEController : TangoController
+ {
+ public class TokenObject
+ {
+ public String UserGuid { get; set; }
+ }
+
+ /// <summary>
+ /// Login to the service.
+ /// </summary>
+ /// <param name="request">The request.</param>
+ /// <returns></returns>
+ /// <exception cref="AuthenticationException"></exception>
+ [HttpPost]
+ public LoginResponse Login(LoginRequest request)
+ {
+ User user = null;
+ DataSource dataSource = null;
+ IHashGenerator hash = new BasicHashGenerator();
+
+ Version client_version;
+
+ if (!Version.TryParse(request.Version, out client_version))
+ {
+ client_version = new Version("1.0.0.0");
+ }
+
+ bool versionChangeRequired = false;
+ String requiredVersion = null;
+
+ var password = hash.Encrypt(request.Password);
+
+ using (var db = ObservablesContextHelper.CreateContext())
+ {
+ user = new UserBuilder(db).Set(x => x.Email.ToLower() == request.Email.ToLower() && x.Password == password).WithRolesAndPermissions().WithDeleted().Build();
+
+ if (user == null)
+ {
+ throw new AuthenticationException("Invalid email or password.");
+ }
+
+ if (user.Deleted)
+ {
+ throw new AuthenticationException("Your account has been disabled. Please contact your administrator.");
+ }
+
+ user.LastLogin = DateTime.UtcNow;
+ db.SaveChanges();
+ }
+
+ SQLServerManager sqlServer = new SQLServerManager();
+ var accessToken = sqlServer.GetAccessToken();
+
+ dataSource = new DataSource()
+ {
+ Address = MachineServiceConfig.DB_ADDRESS,
+ Catalog = MachineServiceConfig.DB_CATALOG,
+ Type = DataSourceType.AccessToken,
+ IntegratedSecurity = false,
+ AccessToken = accessToken.AccessToken,
+ AccessTokenExpiration = accessToken.ExpiresOn.UtcDateTime
+ };
+
+
+ //Enforce Machine Studio Version ?
+ //if (MachineServiceConfig.ENFORCE_MACHINE_STUDIO_VERSION)
+ //{
+ // using (var db = ObservablesContextHelper.CreateContext())
+ // {
+ // var latest_version = db.MachineStudioVersions.ToList().OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault();
+
+ // if (latest_version != null && Version.Parse(latest_version.Version) != client_version)
+ // {
+ // versionChangeRequired = true;
+ // requiredVersion = latest_version.Version;
+ // }
+ // }
+ //}
+
+ //Return data source
+ return new LoginResponse()
+ {
+ DataSource = dataSource,
+ AccessToken = WebToken<TokenObject>.CreateNew(MachineServiceConfig.JWT_TOKEN_SECRET, new TokenObject()
+ {
+ UserGuid = user.Guid,
+ }, DateTime.UtcNow.AddDays(1)).AccessToken,
+ VersionChangeRequired = versionChangeRequired,
+ RequiredVersion = requiredVersion,
+ PasswordChangeRequired = user.PasswordChangeRequired
+ };
+ }
+ }
+}
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs
index 1be2a5de8..f508fea15 100644
--- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs
+++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs
@@ -89,7 +89,7 @@ namespace Tango.MachineService.Controllers
String comments = String.Join(Environment.NewLine, versions.OrderBy(x => Version.Parse(x.Version)).Where(x => Version.Parse(x.Version) > currentVersion).Select(x => x.Comments));
- if (latestVersion != null && Version.Parse(latestVersion.Version) > currentVersion)
+ if (latestVersion != null && Version.Parse(latestVersion.Version) != currentVersion)
{
var manager = new BlobStorageManager();
var container = manager.GetContainer(MachineServiceConfig.MACHINE_STUDIO_VERSIONS_CONTAINER);
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs
index 6ac2e3657..b132a4c48 100644
--- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs
+++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs
@@ -317,7 +317,7 @@ namespace Tango.MachineService.Controllers
var latest_machine_version = db.TangoVersions.Where(x => x.MachineVersionGuid == machine_version.Guid).ToList().OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault();
- if (Version.Parse(latest_machine_version.Version) > Version.Parse(request.Version))
+ if (Version.Parse(latest_machine_version.Version) != Version.Parse(request.Version))
{
response.IsUpdateAvailable = true;
}
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj b/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj
index e916f01e6..a05fee42f 100644
--- a/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj
+++ b/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj
@@ -306,6 +306,7 @@
<Compile Include="App_Start\FilterConfig.cs" />
<Compile Include="Controllers\DownloadsController.cs" />
<Compile Include="Controllers\AccountController.cs" />
+ <Compile Include="Controllers\FSEController.cs" />
<Compile Include="Filters\JwtTokenFilter.cs" />
<Compile Include="Hubs\ExternalBridgeHub.cs" />
<Compile Include="MachineServiceConfig.cs" />
@@ -372,6 +373,10 @@
<Content Include="packages.config" />
</ItemGroup>
<ItemGroup>
+ <ProjectReference Include="..\..\FSE\Tango.FSE.Web\Tango.FSE.Web.csproj">
+ <Project>{d6f7d31d-7f8c-45e2-ae0a-fbbd1f5f9d5f}</Project>
+ <Name>Tango.FSE.Web</Name>
+ </ProjectReference>
<ProjectReference Include="..\..\MachineStudio\Tango.MachineStudio.Common\Tango.MachineStudio.Common.csproj">
<Project>{CB0B0AA2-BB24-4BCA-A720-45E397684E12}</Project>
<Name>Tango.MachineStudio.Common</Name>
@@ -456,7 +461,7 @@
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>
</FlavorProperties>
- <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" />
+ <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" />
</VisualStudio>
</ProjectExtensions>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">