aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-01-19 00:30:23 +0200
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-01-19 00:30:23 +0200
commitb9c104e259ca24d2ae7ca82387209779fefddd34 (patch)
tree2da044a8b7ebe835363145a739ed09561e5460bd
parent6ec4f8acc13384edb04b96c01c3e87b7681304d7 (diff)
downloadTango-b9c104e259ca24d2ae7ca82387209779fefddd34.tar.gz
Tango-b9c104e259ca24d2ae7ca82387209779fefddd34.zip
Implemented machine studio connection via access token WORKING!.
Implemented machine studio login method selection.
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Tango.MachineStudio.Storage_yjpbed13_wpftmp.csproj154
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/IAuthenticationProvider.cs2
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/MachineStudioSettings.cs6
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj3
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LoginMethod.cs17
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LoginRequest.cs1
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs3
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/active_directory.pngbin0 -> 15300 bytes
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/login.pngbin0 -> 6401 bytes
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/machinestudio_login.pngbin0 -> 21788 bytes
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj5
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs29
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/LoginView.xaml76
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml2
-rw-r--r--Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs24
-rw-r--r--Software/Visual_Studio/Tango.Web/SQLServer/SQLServerManager.cs1
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs181
17 files changed, 395 insertions, 109 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Tango.MachineStudio.Storage_yjpbed13_wpftmp.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Tango.MachineStudio.Storage_yjpbed13_wpftmp.csproj
new file mode 100644
index 000000000..698c6fe82
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Tango.MachineStudio.Storage_yjpbed13_wpftmp.csproj
@@ -0,0 +1,154 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProjectGuid>{5991F6B5-EA4E-41E9-A4F6-7D3A50010FD6}</ProjectGuid>
+ <OutputType>library</OutputType>
+ <RootNamespace>Tango.MachineStudio.Storage</RootNamespace>
+ <AssemblyName>Tango.MachineStudio.Storage</AssemblyName>
+ <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <WarningLevel>4</WarningLevel>
+ <Deterministic>true</Deterministic>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>..\..\..\Build\Machine Studio\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>..\..\..\Build\Machine Studio\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="..\..\..\Versioning\GlobalVersionInfo.cs">
+ <Link>GlobalVersionInfo.cs</Link>
+ </Compile>
+ <Compile Include="Converters\StorageItemToImageConverter.cs" />
+ <Compile Include="Helpers\FileIconHelper.cs" />
+ <Compile Include="Models\StorageFileHandlerModel.cs" />
+ <Compile Include="Models\StorageFileHandlerType.cs" />
+ <Compile Include="StorageModule.cs" />
+ <Compile Include="ViewModelLocator.cs" />
+ <Compile Include="ViewModels\MainViewVM.cs" />
+ <Compile Include="Views\MainView.xaml.cs">
+ <DependentUpon>MainView.xaml</DependentUpon>
+ </Compile>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Properties\AssemblyInfo.cs">
+ <SubType>Code</SubType>
+ </Compile>
+ <Compile Include="Properties\Resources.Designer.cs">
+ <AutoGen>True</AutoGen>
+ <DesignTime>True</DesignTime>
+ <DependentUpon>Resources.resx</DependentUpon>
+ </Compile>
+ <Compile Include="Properties\Settings.Designer.cs">
+ <AutoGen>True</AutoGen>
+ <DependentUpon>Settings.settings</DependentUpon>
+ <DesignTimeSharedInput>True</DesignTimeSharedInput>
+ </Compile>
+ <EmbeddedResource Include="Properties\Resources.resx">
+ <Generator>ResXFileCodeGenerator</Generator>
+ <LastGenOutput>Resources.Designer.cs</LastGenOutput>
+ </EmbeddedResource>
+ <None Include="app.config" />
+ <None Include="packages.config" />
+ <None Include="Properties\Settings.settings">
+ <Generator>SettingsSingleFileGenerator</Generator>
+ <LastGenOutput>Settings.Designer.cs</LastGenOutput>
+ </None>
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\..\..\Tango.BL\Tango.BL.csproj">
+ <Project>{f441feee-322a-4943-b566-110e12fd3b72}</Project>
+ <Name>Tango.BL</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\..\..\Tango.Core\Tango.Core.csproj">
+ <Project>{a34ee0f0-649d-41c8-8489-b6f1cc6924ee}</Project>
+ <Name>Tango.Core</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\..\..\Tango.Integration\Tango.Integration.csproj">
+ <Project>{4206ac58-3b57-4699-8835-90bf6db01a61}</Project>
+ <Name>Tango.Integration</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\..\..\Tango.Logging\Tango.Logging.csproj">
+ <Project>{bc932dbd-7cdb-488c-99e4-f02cf441f55e}</Project>
+ <Name>Tango.Logging</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\..\..\Tango.SharedUI\Tango.SharedUI.csproj">
+ <Project>{8491d07b-c1f6-4b62-a412-41b9fd2d6538}</Project>
+ <Name>Tango.SharedUI</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\..\..\Tango.Transport\Tango.Transport.csproj">
+ <Project>{74e700b0-1156-4126-be40-ee450d3c3026}</Project>
+ <Name>Tango.Transport</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\..\..\Utilities\Tango.FirmwarePackageGenerator\Tango.FirmwarePackageGenerator.csproj">
+ <Project>{43135fb9-41db-4f87-9771-cf2c762027c0}</Project>
+ <Name>Tango.FirmwarePackageGenerator</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\..\Tango.MachineStudio.Common\Tango.MachineStudio.Common.csproj">
+ <Project>{cb0b0aa2-bb24-4bca-a720-45e397684e12}</Project>
+ <Name>Tango.MachineStudio.Common</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ </ItemGroup>
+ <ItemGroup>
+ </ItemGroup>
+ <ItemGroup>
+ </ItemGroup>
+ <ItemGroup />
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <ItemGroup>
+ <ReferencePath Include="C:\DATA\Development\Tango\Software\Visual_Studio\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll" />
+ <ReferencePath Include="C:\DATA\Development\Tango\Software\Visual_Studio\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll" />
+ <ReferencePath Include="C:\DATA\Development\Tango\Software\Visual_Studio\Build\Utilities\Debug\fpgen.exe" />
+ <ReferencePath Include="C:\DATA\Development\Tango\Software\Visual_Studio\packages\MahApps.Metro.1.5.0\lib\net45\MahApps.Metro.dll" />
+ <ReferencePath Include="C:\DATA\Development\Tango\Software\Visual_Studio\packages\MaterialDesignColors.1.1.2\lib\net45\MaterialDesignColors.dll" />
+ <ReferencePath Include="C:\DATA\Development\Tango\Software\Visual_Studio\packages\MaterialDesignThemes.2.3.1.953\lib\net45\MaterialDesignThemes.Wpf.dll" />
+ <ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Microsoft.CSharp.dll" />
+ <ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\mscorlib.dll" />
+ <ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\PresentationCore.dll" />
+ <ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\PresentationFramework.dll" />
+ <ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.ComponentModel.DataAnnotations.dll" />
+ <ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Core.dll" />
+ <ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Data.DataSetExtensions.dll" />
+ <ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Data.dll" />
+ <ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.dll" />
+ <ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Drawing.dll" />
+ <ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Net.Http.dll" />
+ <ReferencePath Include="C:\DATA\Development\Tango\Software\Visual_Studio\packages\MahApps.Metro.1.5.0\lib\net45\System.Windows.Interactivity.dll" />
+ <ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Xaml.dll" />
+ <ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Xml.dll" />
+ <ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Xml.Linq.dll" />
+ <ReferencePath Include="C:\DATA\Development\Tango\Software\Visual_Studio\Build\Core\Debug\Tango.BL.dll" />
+ <ReferencePath Include="C:\DATA\Development\Tango\Software\Visual_Studio\Build\Core\Debug\Tango.Core.dll" />
+ <ReferencePath Include="C:\DATA\Development\Tango\Software\Visual_Studio\Build\Core\Debug\Tango.Integration.dll" />
+ <ReferencePath Include="C:\DATA\Development\Tango\Software\Visual_Studio\Build\Core\Debug\Tango.Logging.dll" />
+ <ReferencePath Include="C:\DATA\Development\Tango\Software\Visual_Studio\Build\Machine Studio\Debug\Tango.MachineStudio.Common.dll" />
+ <ReferencePath Include="C:\DATA\Development\Tango\Software\Visual_Studio\Build\Core\Debug\Tango.SharedUI.dll" />
+ <ReferencePath Include="C:\DATA\Development\Tango\Software\Visual_Studio\Build\Core\Debug\Tango.Transport.dll" />
+ <ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\WindowsBase.dll" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="C:\DATA\Development\Tango\Software\Visual_Studio\MachineStudio\Modules\Tango.MachineStudio.Storage\obj\Debug\App.g.cs" />
+ <Compile Include="C:\DATA\Development\Tango\Software\Visual_Studio\MachineStudio\Modules\Tango.MachineStudio.Storage\obj\Debug\Views\MainView.g.cs" />
+ <Compile Include="C:\DATA\Development\Tango\Software\Visual_Studio\MachineStudio\Modules\Tango.MachineStudio.Storage\obj\Debug\GeneratedInternalTypeHelper.g.cs" />
+ </ItemGroup>
+</Project> \ No newline at end of file
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/IAuthenticationProvider.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/IAuthenticationProvider.cs
index 74969fd27..cb231fa05 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/IAuthenticationProvider.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/IAuthenticationProvider.cs
@@ -29,7 +29,7 @@ namespace Tango.MachineStudio.Common.Authentication
/// <param name="email">The email.</param>
/// <param name="password">The password.</param>
/// <returns></returns>
- AuthenticationLoginResult Login(String email, String password, bool bypassVersionCheck = false);
+ AuthenticationLoginResult Login(String email, String password, LoginMethod method, bool bypassVersionCheck = false);
/// <summary>
/// Logs-out the current logged-in user.
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/MachineStudioSettings.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/MachineStudioSettings.cs
index 6ab26028f..91eaa857d 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/MachineStudioSettings.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/MachineStudioSettings.cs
@@ -8,6 +8,7 @@ using System.Windows;
using Tango.BL;
using Tango.Integration.Operation;
using Tango.Logging;
+using Tango.MachineStudio.Common.Web;
using Tango.PMR.Printing;
using Tango.Settings;
using Tango.Web;
@@ -40,6 +41,11 @@ namespace Tango.MachineStudio.Common
public String LastLoginPassword { get; set; }
/// <summary>
+ /// Gets or sets the last login method.
+ /// </summary>
+ public LoginMethod LastLoginMethod { get; set; }
+
+ /// <summary>
/// Gets or sets a value indicating whether to save the user credentials.
/// </summary>
public bool RememberMe { get; set; }
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj
index 5e874add1..2df984c7c 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj
@@ -105,6 +105,7 @@
<Compile Include="Tup\TupFileBuilderProgressEventArgs.cs" />
<Compile Include="Web\DownloadLatestPPCVersionRequest.cs" />
<Compile Include="Web\DownloadLatestPPCVersionResponse.cs" />
+ <Compile Include="Web\LoginMethod.cs" />
<Compile Include="Web\LoginRequest.cs" />
<Compile Include="Web\LoginResponse.cs" />
<Compile Include="AutoComplete\MachinesProvider.cs" />
@@ -426,7 +427,7 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
- <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" />
+ <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" />
</VisualStudio>
</ProjectExtensions>
</Project> \ No newline at end of file
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LoginMethod.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LoginMethod.cs
new file mode 100644
index 000000000..83f1c0850
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LoginMethod.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.MachineStudio.Common.Web
+{
+ public enum LoginMethod
+ {
+ [Description("Active Directory")]
+ ActiveDirectory,
+ [Description("Standard User")]
+ StandardUser,
+ }
+}
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LoginRequest.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LoginRequest.cs
index 577f5e208..1727a2c6e 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LoginRequest.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LoginRequest.cs
@@ -12,5 +12,6 @@ namespace Tango.MachineStudio.Common.Web
public String Version { get; set; }
public String Email { get; set; }
public String Password { get; set; }
+ public LoginMethod Method { get; set; }
}
}
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 c992d0768..209b26505 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs
@@ -90,7 +90,7 @@ namespace Tango.MachineStudio.UI.Authentication
/// <param name="password">The password.</param>
/// <returns></returns>
/// <exception cref="AuthenticationException">Login failed for user " + email</exception>
- public AuthenticationLoginResult Login(string email, string password, bool bypassVersionCheck = false)
+ public AuthenticationLoginResult Login(string email, string password, LoginMethod method, bool bypassVersionCheck = false)
{
_refreshTokenTimer.Stop();
@@ -118,6 +118,7 @@ namespace Tango.MachineStudio.UI.Authentication
Email = email,
Password = password,
Version = appVersion,
+ Method = method,
}).Result;
}
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/active_directory.png b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/active_directory.png
new file mode 100644
index 000000000..4cced33e0
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/active_directory.png
Binary files differ
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/login.png b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/login.png
new file mode 100644
index 000000000..9f7d0b9ba
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/login.png
Binary files differ
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/machinestudio_login.png b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/machinestudio_login.png
new file mode 100644
index 000000000..98f1b286a
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/machinestudio_login.png
Binary files differ
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj
index 565489f0b..efe8fc6b1 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj
@@ -363,6 +363,9 @@
<Link>TCC\template.bmp</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
+ <Resource Include="Images\login.png" />
+ <Resource Include="Images\active_directory.png" />
+ <Resource Include="Images\machinestudio_login.png" />
<Resource Include="Images\external-bridge-signalr.png" />
<Resource Include="machine_new_small.ico" />
<Resource Include="Images\Statuses\dyeing.png" />
@@ -676,7 +679,7 @@ if $(ConfigurationName) == Release RD /S /Q "$(TargetDir)Roslyn\"</PostBuildEven
</Target>
<ProjectExtensions>
<VisualStudio>
- <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_BuildVersioningStyle="None.None.Increment.DeltaBaseYearDayOfYear" BuildVersion_UpdateFileVersion="True" BuildVersion_DetectChanges="True" BuildVersion_UseGlobalSettings="False" />
+ <UserProperties BuildVersion_UseGlobalSettings="False" BuildVersion_DetectChanges="True" BuildVersion_UpdateFileVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.DeltaBaseYearDayOfYear" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_StartDate="2000/1/1" />
</VisualStudio>
</ProjectExtensions>
</Project> \ No newline at end of file
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs
index cf34764d9..9c2367f93 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs
@@ -102,6 +102,21 @@ namespace Tango.MachineStudio.UI.ViewModels
set { _enableSlotSelection = value; RaisePropertyChangedAuto(); }
}
+ private bool _isActiveDirectory;
+ public bool IsActiveDirectory
+ {
+ get { return _isActiveDirectory; }
+ set { _isActiveDirectory = value; RaisePropertyChangedAuto(); if (value) IsStandardUser = false; }
+ }
+
+ private bool _isStandardUser;
+ public bool IsStandardUser
+ {
+ get { return _isStandardUser; }
+ set { _isStandardUser = value; RaisePropertyChangedAuto(); if (value) IsActiveDirectory = false; }
+ }
+
+
/// <summary>
/// Gets or sets the login command.
@@ -131,6 +146,15 @@ namespace Tango.MachineStudio.UI.ViewModels
Email = _settings.LastLoginEmail;
DeploymentSlot = _settings.DeploymentSlot;
RememberMe = _settings.RememberMe;
+
+ if (_settings.LastLoginMethod == LoginMethod.ActiveDirectory)
+ {
+ IsActiveDirectory = true;
+ }
+ else
+ {
+ IsStandardUser = true;
+ }
try
{
@@ -154,11 +178,13 @@ namespace Tango.MachineStudio.UI.ViewModels
IsLogging = true;
InvalidateRelayCommands();
+ LoginMethod loginMethod = IsActiveDirectory ? LoginMethod.ActiveDirectory : LoginMethod.StandardUser;
+
await Task.Factory.StartNew(() =>
{
_settings.DeploymentSlot = DeploymentSlot;
- LoginResponse result = _authenticationProvider.Login(Email, Password, _settings.ByPassEnvironmentVersionCheck).Response;
+ LoginResponse result = _authenticationProvider.Login(Email, Password, loginMethod, _settings.ByPassEnvironmentVersionCheck).Response;
if (result.VersionChangeRequired && !_settings.ByPassEnvironmentVersionCheck)
{
@@ -183,6 +209,7 @@ namespace Tango.MachineStudio.UI.ViewModels
_settings.LastLoginEmail = Email;
_settings.RememberMe = RememberMe;
+ _settings.LastLoginMethod = loginMethod;
_settings.LastLoginPassword = RememberMe ? cryptographer.Encrypt(Password) : null;
_settings.Save();
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/LoginView.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/LoginView.xaml
index d93dbc127..e7428dd28 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/LoginView.xaml
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/LoginView.xaml
@@ -45,35 +45,57 @@
<Image Source="{StaticResource MachineBig}" RenderOptions.BitmapScalingMode="Fant" Width="100"></Image>
<TextBlock Margin="20 0 0 0" VerticalAlignment="Center" FontSize="70" Foreground="{StaticResource AccentColorBrush}">Machine Studio</TextBlock>
</StackPanel>
- <DockPanel HorizontalAlignment="Center" VerticalAlignment="Center" Width="320" Margin="0 120 0 0" Height="510">
- <Button DockPanel.Dock="Bottom" AutomationProperties.AutomationId="{x:Static automation:UI.LoginButton}" Margin="25 20 0 0" Height="50" Command="{Binding LoginCommand}" Content="LOGIN"></Button>
+ <Grid>
+ <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Margin="-600 110 0 0" Visibility="{Binding IsLogging,Converter={StaticResource BooleanToVisibilityInverseConverter}}">
+ <RadioButton ToolTip="Login using your an active directory account" IsChecked="{Binding IsActiveDirectory}" FontSize="16" VerticalContentAlignment="Center" Padding="10 0 0 0">
+ <Image Source="/Images/active_directory.png" Stretch="Uniform" Height="80" RenderOptions.BitmapScalingMode="Fant" />
+ </RadioButton>
+ <RadioButton ToolTip="Login using a standard Machine Studio account" IsChecked="{Binding IsStandardUser}" FontSize="16" Margin="0 20 0 0" VerticalContentAlignment="Center" Padding="10 0 0 0">
+ <Image Source="/Images/machinestudio_login.png" Stretch="Uniform" Height="55" RenderOptions.BitmapScalingMode="Fant" />
+ </RadioButton>
+ </StackPanel>
+ <DockPanel HorizontalAlignment="Center" VerticalAlignment="Center" Width="320" Margin="0 120 0 0" Height="510">
- <Grid>
- <StackPanel Visibility="{Binding IsLogging,Converter={StaticResource BooleanToVisibilityInverseConverter}}">
- <TextBlock HorizontalAlignment="Center" FontSize="24">Login to your account</TextBlock>
- <Image Source="/Images/account.png" RenderOptions.BitmapScalingMode="Fant" Width="100" Margin="0 20 0 0"></Image>
- <DockPanel Margin="0 20 0 0">
- <materialDesign:PackIcon Margin="0 0 0 0" Width="20" Height="20" VerticalAlignment="Top" Foreground="{Binding ElementName=txtEmail, Path=BorderBrush}" Kind="EmailOutline" />
- <TextBox x:Name="txtEmail" IsTabStop="True" Margin="5 0 0 0" materialDesign:HintAssist.FloatingScale="0.50" materialDesign:HintAssist.Hint="Email" materialDesign:TextFieldAssist.TextBoxViewMargin="1 0 1 0" FontSize="20" Style="{StaticResource MaterialDesignFloatingHintTextBox}" Text="{Binding Email,UpdateSourceTrigger=PropertyChanged,ValidatesOnNotifyDataErrors=True}" AutomationProperties.IsRequiredForForm="True" />
- </DockPanel>
- <DockPanel Margin="0 20 0 0">
- <materialDesign:PackIcon Margin="0 0 0 0" Width="20" Height="20" VerticalAlignment="Top" Foreground="{Binding ElementName=txtPass, Path=BorderBrush}" Kind="Key" />
- <PasswordBox x:Name="txtPass" helpers:PasswordHelper.Attach="True" helpers:PasswordHelper.Password="{Binding Password,Mode=TwoWay}" Margin="5 0 0 0" materialDesign:HintAssist.FloatingScale="0.50" materialDesign:HintAssist.Hint="Password" materialDesign:TextFieldAssist.TextBoxViewMargin="1 0 1 0" FontSize="20" Style="{StaticResource MaterialDesignFloatingHintPasswordBox}" AutomationProperties.IsRequiredForForm="True" />
- </DockPanel>
- <DockPanel Margin="0 40 0 0" IsEnabled="{Binding EnableSlotSelection}">
- <materialDesign:PackIcon Margin="0 0 0 0" Width="20" Height="20" VerticalAlignment="Top" Foreground="{Binding ElementName=combo, Path=BorderBrush}" Kind="Settings" />
- <ComboBox x:Name="combo" ItemsSource="{Binding Source={x:Type web:DeploymentSlot},Converter={StaticResource EnumToItemsSourceConverter}}" SelectedValue="{Binding DeploymentSlot}" SelectedValuePath="Value" DisplayMemberPath="DisplayName" Margin="5 0 0 0" materialDesign:HintAssist.FloatingScale="0.50" materialDesign:HintAssist.Hint="Environment" materialDesign:TextFieldAssist.TextBoxViewMargin="1 0 1 0" FontSize="20" />
- </DockPanel>
- <TextBlock Visibility="{Binding EnableSlotSelection,Converter={StaticResource BooleanToVisibilityInverseConverter}}" Margin="25 0 0 0" FontSize="10" Foreground="Gray">Environment selection requires restarting the application</TextBlock>
- <CheckBox Margin="25 20 0 0" IsChecked="{Binding RememberMe}">Remember me</CheckBox>
- </StackPanel>
+ <Button DockPanel.Dock="Bottom" AutomationProperties.AutomationId="{x:Static automation:UI.LoginButton}" Margin="25 20 0 0" Height="50" Command="{Binding LoginCommand}" Content="LOGIN"></Button>
- <StackPanel Visibility="{Binding IsLogging,Converter={StaticResource BooleanToVisibilityConverter}}" VerticalAlignment="Center">
- <mahapps:ProgressRing Width="80" Height="80" IsActive="{Binding IsLogging}"></mahapps:ProgressRing>
- <TextBlock HorizontalAlignment="Center" Margin="0 30 0 0" FontSize="18" FontStyle="Italic">Logging you in...</TextBlock>
- </StackPanel>
- </Grid>
- </DockPanel>
+ <Grid>
+ <StackPanel Visibility="{Binding IsLogging,Converter={StaticResource BooleanToVisibilityInverseConverter}}">
+ <TextBlock HorizontalAlignment="Center" FontSize="24">Login to your account</TextBlock>
+ <Image Source="/Images/login.png" RenderOptions.BitmapScalingMode="Fant" Width="100" Margin="0 20 0 0"></Image>
+ <DockPanel Margin="0 20 0 0">
+ <materialDesign:PackIcon Margin="0 0 0 0" Width="20" Height="20" VerticalAlignment="Top" Foreground="{Binding ElementName=txtEmail, Path=BorderBrush}" Kind="EmailOutline" />
+ <TextBox x:Name="txtEmail" IsTabStop="True" Margin="5 0 0 0" materialDesign:HintAssist.FloatingScale="0.50" materialDesign:TextFieldAssist.TextBoxViewMargin="1 0 1 0" FontSize="20" Text="{Binding Email,UpdateSourceTrigger=PropertyChanged,ValidatesOnNotifyDataErrors=True}" AutomationProperties.IsRequiredForForm="True">
+ <TextBox.Style>
+ <Style TargetType="TextBox" BasedOn="{StaticResource MaterialDesignFloatingHintTextBox}">
+ <Setter Property="materialDesign:HintAssist.Hint" Value="Active Directory Email"></Setter>
+ <Style.Triggers>
+ <DataTrigger Binding="{Binding IsStandardUser}" Value="True">
+ <Setter Property="materialDesign:HintAssist.Hint" Value="Machine Studio Email"></Setter>
+ </DataTrigger>
+ </Style.Triggers>
+ </Style>
+ </TextBox.Style>
+ </TextBox>
+ </DockPanel>
+ <DockPanel Margin="0 20 0 0">
+ <materialDesign:PackIcon Margin="0 0 0 0" Width="20" Height="20" VerticalAlignment="Top" Foreground="{Binding ElementName=txtPass, Path=BorderBrush}" Kind="Key" />
+ <PasswordBox x:Name="txtPass" helpers:PasswordHelper.Attach="True" helpers:PasswordHelper.Password="{Binding Password,Mode=TwoWay}" Margin="5 0 0 0" materialDesign:HintAssist.FloatingScale="0.50" materialDesign:HintAssist.Hint="Password" materialDesign:TextFieldAssist.TextBoxViewMargin="1 0 1 0" FontSize="20" Style="{StaticResource MaterialDesignFloatingHintPasswordBox}" AutomationProperties.IsRequiredForForm="True" />
+ </DockPanel>
+ <DockPanel Margin="0 40 0 0" IsEnabled="{Binding EnableSlotSelection}">
+ <materialDesign:PackIcon Margin="0 0 0 0" Width="20" Height="20" VerticalAlignment="Top" Foreground="{Binding ElementName=combo, Path=BorderBrush}" Kind="Settings" />
+ <ComboBox x:Name="combo" ItemsSource="{Binding Source={x:Type web:DeploymentSlot},Converter={StaticResource EnumToItemsSourceConverter}}" SelectedValue="{Binding DeploymentSlot}" SelectedValuePath="Value" DisplayMemberPath="DisplayName" Margin="5 0 0 0" materialDesign:HintAssist.FloatingScale="0.50" materialDesign:HintAssist.Hint="Environment" materialDesign:TextFieldAssist.TextBoxViewMargin="1 0 1 0" FontSize="20" />
+ </DockPanel>
+ <TextBlock Visibility="{Binding EnableSlotSelection,Converter={StaticResource BooleanToVisibilityInverseConverter}}" Margin="25 0 0 0" FontSize="10" Foreground="Gray">Environment selection requires restarting the application</TextBlock>
+ <CheckBox Margin="25 20 0 0" IsChecked="{Binding RememberMe}">Remember me</CheckBox>
+ </StackPanel>
+
+ <StackPanel Visibility="{Binding IsLogging,Converter={StaticResource BooleanToVisibilityConverter}}" VerticalAlignment="Center">
+ <mahapps:ProgressRing Width="80" Height="80" IsActive="{Binding IsLogging}"></mahapps:ProgressRing>
+ <TextBlock HorizontalAlignment="Center" Margin="0 30 0 0" FontSize="18" FontStyle="Italic">Logging you in...</TextBlock>
+ </StackPanel>
+ </Grid>
+ </DockPanel>
+ </Grid>
</Grid>
</UserControl>
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml
index 020343ba0..48f7b46d3 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml
@@ -55,7 +55,7 @@
IsChecked="{Binding Source={x:Reference MenuToggleButton}, Path=IsChecked, Mode=TwoWay}" />
<StackPanel Margin="5 0 0 0" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center">
- <Image Source="/Images/account.png" RenderOptions.BitmapScalingMode="Fant" VerticalAlignment="Center" Width="50" Height="50"></Image>
+ <Image Source="/Images/login.png" RenderOptions.BitmapScalingMode="Fant" VerticalAlignment="Center" Width="50" Height="50"></Image>
<StackPanel Margin="0 5 0 0">
<TextBlock FontSize="16" TextTrimming="CharacterEllipsis" MaxWidth="170" FontStyle="Italic" FontWeight="Bold" Margin="10 0 0 0" VerticalAlignment="Center" Text="{Binding AuthenticationProvider.CurrentUser.Contact.FullName}"></TextBlock>
<TextBlock FontSize="12" TextTrimming="CharacterEllipsis" MaxWidth="170" FontStyle="Italic" Margin="10 5 0 0" VerticalAlignment="Center">
diff --git a/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs b/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs
index 263574f68..3d330b797 100644
--- a/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs
+++ b/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs
@@ -5,6 +5,7 @@ using System.Collections.ObjectModel;
using System.Data.Entity;
using System.Data.Entity.Core.Objects;
using System.Data.Entity.Infrastructure;
+using System.Data.SqlClient;
using System.Data.SQLite;
using System.IO;
using System.Linq;
@@ -25,6 +26,7 @@ namespace Tango.BL
private ObservablesContextAdapter _adapter;
private static DataSource _override_datasource;
private DataSource _dataSource;
+ private static List<ObservablesContext> _open_contexts;
/// <summary>
/// Gets a value indicating whether this instance is disposed.
@@ -32,11 +34,19 @@ namespace Tango.BL
public bool IsDisposed { get; private set; }
/// <summary>
+ /// Initializes the <see cref="ObservablesContext"/> class.
+ /// </summary>
+ static ObservablesContext()
+ {
+ _open_contexts = new List<ObservablesContext>();
+ }
+
+ /// <summary>
/// Initializes a new instance of the <see cref="ObservablesContext"/> class.
/// </summary>
public ObservablesContext()
{
-
+ _open_contexts.Add(this);
}
/// <summary>
@@ -46,6 +56,7 @@ namespace Tango.BL
/// <param name="isFile">if set to <c>true</c> will try to connect to an .mdf file.</param>
public ObservablesContext(DataSource dataSource) : base(dataSource.ToConnection(), true)
{
+ _open_contexts.Add(this);
_dataSource = dataSource;
Database.SetInitializer<ObservablesContext>(null);
Configuration.LazyLoadingEnabled = false;
@@ -286,6 +297,7 @@ namespace Tango.BL
/// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
protected override void Dispose(bool disposing)
{
+ _open_contexts.Remove(this);
base.Dispose(disposing);
IsDisposed = true;
}
@@ -296,6 +308,16 @@ namespace Tango.BL
{
_override_datasource.AccessToken = accessToken;
_override_datasource.AccessTokenExpiration = expiration;
+
+ foreach (var context in _open_contexts.Where(x => x._dataSource.Type == DataSourceType.AccessToken))
+ {
+ context._dataSource = _override_datasource;
+ var connection = context.Database.Connection as SqlConnection;
+ if (connection != null)
+ {
+ connection.AccessToken = context._dataSource.AccessToken;
+ }
+ }
}
}
}
diff --git a/Software/Visual_Studio/Tango.Web/SQLServer/SQLServerManager.cs b/Software/Visual_Studio/Tango.Web/SQLServer/SQLServerManager.cs
index ce83d387c..8bc84f7b5 100644
--- a/Software/Visual_Studio/Tango.Web/SQLServer/SQLServerManager.cs
+++ b/Software/Visual_Studio/Tango.Web/SQLServer/SQLServerManager.cs
@@ -15,6 +15,7 @@ namespace Tango.Web.SQLServer
public AuthenticationResult GetAccessToken()
{
var authContext = new AuthenticationContext(_service_root);
+ authContext.TokenCache.Clear();
ClientCredential clientCredentials = new ClientCredential(WebConfig.CLIENT_ID, WebConfig.APP_SECRET);
AuthenticationResult authResult = authContext.AcquireTokenAsync("https://database.windows.net/", clientCredentials).Result;
return authResult;
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs
index da5ce16f7..0fd116361 100644
--- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs
+++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs
@@ -286,20 +286,9 @@ namespace Tango.MachineService.Controllers
public LoginResponse Login(LoginRequest request)
{
AuthenticationResult authResult = null;
-
- try
- {
- authResult = _ad_manager.ValidateUserCredentials(request.Email, request.Password);
- }
- catch (Exception ex)
- {
- throw new AuthenticationException(ex.FlattenMessage());
- }
-
- if (!_ad_manager.CanUserAccessCurrentEnvironment(request.Email))
- {
- throw new AuthenticationException($"You do not have permissions to access the {MachineServiceConfig.DEPLOYMENT_SLOT.ToDescription()} environment.");
- }
+ User user = null;
+ DataSource dataSource = null;
+ IHashGenerator hash = new BasicHashGenerator();
Version client_version;
@@ -310,84 +299,122 @@ namespace Tango.MachineService.Controllers
bool versionChangeRequired = false;
String requiredVersion = null;
+ bool isPasswordOK = false;
- User user = null;
-
- using (ObservablesContext db = ObservablesContextHelper.CreateContext())
+ try
{
- db.Roles.ToList();
- db.Permissions.ToList();
- db.UsersRoles.ToList();
- db.RolesPermissions.ToList();
+ authResult = _ad_manager.ValidateUserCredentials(request.Email, request.Password);
+ isPasswordOK = true;
+ }
+ catch {}
- user = new UserBuilder(db).Set(x => x.Email.ToLower() == request.Email.ToLower()).WithRolesAndPermissions().WithDeleted().Build();
+ //Login via Active Directory
+ if (request.Method == LoginMethod.ActiveDirectory)
+ {
+ try
+ {
+ authResult = _ad_manager.ValidateUserCredentials(request.Email, request.Password);
+ }
+ catch (Exception ex)
+ {
+ throw new AuthenticationException(ex.FlattenMessage());
+ }
- IHashGenerator g = new BasicHashGenerator();
+ if (!_ad_manager.CanUserAccessCurrentEnvironment(request.Email))
+ {
+ throw new AuthenticationException($"You do not have permissions to access the {MachineServiceConfig.DEPLOYMENT_SLOT.ToDescription()} environment.");
+ }
- if (user == null)
+ using (ObservablesContext db = ObservablesContextHelper.CreateContext())
{
- //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,
- };
+ db.Roles.ToList();
+ db.Permissions.ToList();
+ db.UsersRoles.ToList();
+ db.RolesPermissions.ToList();
- db.UsersRoles.Add(new UsersRole()
- {
- User = new_user,
- Role = db.Roles.Single(x => (Roles)x.Code == Roles.User),
- });
+ user = new UserBuilder(db).Set(x => x.Email.ToLower() == request.Email.ToLower()).WithRolesAndPermissions().WithDeleted().Build();
- db.UsersRoles.Add(new UsersRole()
+ if (user == null)
{
- User = new_user,
- Role = db.Roles.Single(x => (Roles)x.Code == Roles.MachineStudioUser),
- });
+ user = new User();
+ user.Email = request.Email;
+ user.Password = hash.Encrypt(request.Password);
+ user.Organization = db.Organizations.Include(x => x.Address).Single(x => x.Name == "Twine");
+ user.Address = user.Organization.Address.Clone();
+ user.Contact = new Contact()
+ {
+ FirstName = authResult.UserInfo.GivenName,
+ LastName = authResult.UserInfo.FamilyName,
+ FullName = authResult.UserInfo.GivenName + " " + authResult.UserInfo.FamilyName,
+ Email = request.Email,
+ };
- new_user.LastLogin = DateTime.UtcNow;
- db.Users.Add(new_user);
- }
- else
- {
- if (user.Deleted)
+ db.UsersRoles.Add(new UsersRole()
+ {
+ User = user,
+ Role = db.Roles.Single(x => (Roles)x.Code == Roles.User),
+ });
+
+ db.UsersRoles.Add(new UsersRole()
+ {
+ User = user,
+ Role = db.Roles.Single(x => (Roles)x.Code == Roles.MachineStudioUser),
+ });
+
+ user.Password = hash.Encrypt(request.Password);
+
+ db.Users.Add(user);
+ }
+ else
{
- throw new AuthenticationException("Your account has been disabled. Please contact your administrator.");
+ if (user.Deleted)
+ {
+ throw new AuthenticationException("Your account has been disabled. Please contact your administrator.");
+ }
}
user.LastLogin = DateTime.UtcNow;
- user.Password = g.Encrypt(request.Password);
+
+ db.SaveChanges();
}
- db.SaveChanges();
+ dataSource = new DataSource()
+ {
+ Address = MachineServiceConfig.DB_ADDRESS,
+ Catalog = MachineServiceConfig.DB_CATALOG,
+ Type = Core.DataSourceType.Azure,
+ IntegratedSecurity = false,
+ UserName = request.Email,
+ Password = request.Password,
+ };
+ }
+ //Login via Database standard user
+ else
+ {
+ var password = hash.Encrypt(request.Password);
- if (MachineServiceConfig.ENFORCE_MACHINE_STUDIO_VERSION)
+ using (var db = ObservablesContextHelper.CreateContext())
{
- var latest_version = db.MachineStudioVersions.ToList().OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault();
+ user = new UserBuilder(db).Set(x => x.Email.ToLower() == request.Email.ToLower() && (isPasswordOK || x.Password == password)).WithRolesAndPermissions().WithDeleted().Build();
- if (latest_version != null && Version.Parse(latest_version.Version) != client_version)
+ if (user == null)
{
- versionChangeRequired = true;
- requiredVersion = latest_version.Version;
+ throw new AuthenticationException("Invalid email or password.");
}
- }
- }
- Core.DataSource dataSource = null;
+ if (user.Deleted)
+ {
+ throw new AuthenticationException("Your account has been disabled. Please contact your administrator.");
+ }
+
+ user.LastLogin = DateTime.UtcNow;
+ db.SaveChanges();
+ }
- if (MachineServiceConfig.USE_DB_ACCESS_TOKENS)
- {
SQLServerManager sqlServer = new SQLServerManager();
var accessToken = sqlServer.GetAccessToken();
- dataSource = new Core.DataSource()
+ dataSource = new DataSource()
{
Address = MachineServiceConfig.DB_ADDRESS,
Catalog = MachineServiceConfig.DB_CATALOG,
@@ -397,19 +424,23 @@ namespace Tango.MachineService.Controllers
AccessTokenExpiration = accessToken.ExpiresOn.UtcDateTime
};
}
- else
+
+ //Enforce Machine Studio Version ?
+ if (MachineServiceConfig.ENFORCE_MACHINE_STUDIO_VERSION)
{
- dataSource = new Core.DataSource()
+ using (var db = ObservablesContextHelper.CreateContext())
{
- Address = MachineServiceConfig.DB_ADDRESS,
- Catalog = MachineServiceConfig.DB_CATALOG,
- Type = Core.DataSourceType.Azure,
- IntegratedSecurity = false,
- UserName = request.Email,
- Password = request.Password,
- };
+ 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,