Authentication and Personalization for web and desktop. Active directory and local
This commit is contained in:
@@ -200,10 +200,10 @@ namespace Xylem.Common.CommonCore.Configuration
|
||||
= "http://sla12iis01.emea.sensus.net/MeterProcessState/api/CordonelPressureSensorTest/GetTestResults/{0}";
|
||||
|
||||
public const string LaaProductionAPI
|
||||
#if DEBUG == false
|
||||
= "http://localhost:59768/";
|
||||
#if DEBUG
|
||||
= "http://localhost:59768";
|
||||
#else
|
||||
= "http://sla12iis01.emea.sensus.net/";
|
||||
= "http://sla12iis01.emea.sensus.net";
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -1,45 +1,45 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<section name="Xylem.Common.Ui.GenesisToolBox.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
|
||||
<section name="Xylem.Common.Ui.GenesisToolBox.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
|
||||
</sectionGroup>
|
||||
</configSections>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
|
||||
</startup>
|
||||
<userSettings>
|
||||
<Xylem.Common.Ui.GenesisToolBox.Properties.Settings>
|
||||
<setting name="InitialBinaryPath" serializeAs="String">
|
||||
<value/>
|
||||
<value />
|
||||
</setting>
|
||||
<setting name="InitialPackageFile" serializeAs="String">
|
||||
<value/>
|
||||
<value />
|
||||
</setting>
|
||||
</Xylem.Common.Ui.GenesisToolBox.Properties.Settings>
|
||||
</userSettings>
|
||||
<appSettings>
|
||||
<add key="AdminName" value="My Name"/>
|
||||
<add key="AdminEMail" value="MyEMailAddress"/>
|
||||
<add key="ClientSettingsProvider.ServiceUri" value=""/>
|
||||
<add key="AdminName" value="My Name" />
|
||||
<add key="AdminEMail" value="MyEMailAddress" />
|
||||
<add key="ClientSettingsProvider.ServiceUri" value="" />
|
||||
</appSettings>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0"/>
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
<system.web>
|
||||
<membership defaultProvider="ClientAuthenticationMembershipProvider">
|
||||
<providers>
|
||||
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri=""/>
|
||||
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
|
||||
</providers>
|
||||
</membership>
|
||||
<roleManager defaultProvider="ClientRoleProvider" enabled="true">
|
||||
<providers>
|
||||
<add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400"/>
|
||||
<add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
|
||||
</providers>
|
||||
</roleManager>
|
||||
</system.web>
|
||||
|
||||
@@ -154,11 +154,11 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Newtonsoft.Json.12.0.3\lib\net40\Newtonsoft.Json.dll</HintPath>
|
||||
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\NLog.4.6.7\lib\net40-client\NLog.dll</HintPath>
|
||||
<Reference Include="NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\NLog.5.2.0\lib\net46\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
@@ -171,8 +171,12 @@
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.DirectoryServices" />
|
||||
<Reference Include="System.DirectoryServices.AccountManagement" />
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.Security.Principal.Windows, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\System.Security.Principal.Windows.5.0.0\lib\net461\System.Security.Principal.Windows.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.ServiceModel" />
|
||||
<Reference Include="System.Transactions" />
|
||||
<Reference Include="System.Web.Extensions" />
|
||||
@@ -412,10 +416,12 @@
|
||||
<Compile Include="FrmTempMeter.Designer.cs">
|
||||
<DependentUpon>FrmTempMeter.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Infrastructure\ApplicationHttp.cs" />
|
||||
<Compile Include="Infrastructure\ApplicationState.cs" />
|
||||
<Compile Include="Infrastructure\ApplicationVersion.cs" />
|
||||
<Compile Include="Infrastructure\ADLoginModel.cs" />
|
||||
<Compile Include="Infrastructure\Software.cs" />
|
||||
<Compile Include="Infrastructure\SoftwareUser.cs" />
|
||||
<Compile Include="Infrastructure\SoftwareVersion.cs" />
|
||||
<Compile Include="Infrastructure\SoftwareFunctions.cs" />
|
||||
<Compile Include="Infrastructure\UserLoginModel.cs" />
|
||||
<Compile Include="ProccessConfig.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace Xylem.Common.Ui.GenesisToolBox.Infrastructure
|
||||
{
|
||||
internal class ADLoginModel
|
||||
{
|
||||
public string Assembly { get; set; }
|
||||
|
||||
public int MajorV { get; set; }
|
||||
|
||||
public int MinorV { get; set; }
|
||||
|
||||
public int BuildV { get; set; }
|
||||
|
||||
public int EmployeeId { get; set; }
|
||||
|
||||
public string FirstName { get; set; }
|
||||
|
||||
public string LastName { get; set; }
|
||||
|
||||
public string Username { get; set; }
|
||||
|
||||
public string Phone { get; set; }
|
||||
|
||||
public string Email { get; set; }
|
||||
|
||||
public string DomainName { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,142 +0,0 @@
|
||||
namespace Xylem.Common.Ui.GenesisToolBox.Infrastructure
|
||||
{
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Xylem.Common.CommonCore.Configuration;
|
||||
|
||||
internal class ApplicationHttp
|
||||
{
|
||||
const string APPLICATION_JSON = "application/json";
|
||||
|
||||
private static readonly HttpClient httpClient = new HttpClient()
|
||||
{
|
||||
BaseAddress = new Uri(ServiceUrls.LaaProductionAPI)
|
||||
};
|
||||
|
||||
internal static int ApplicationId(string software, params string[] functions)
|
||||
=> Task
|
||||
.Run(async () =>
|
||||
{
|
||||
var applicationId = default(int);
|
||||
|
||||
try
|
||||
{
|
||||
using (var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "/LaaProductionWeb/api/software/appid"))
|
||||
{
|
||||
httpRequestMessage.Content = new StringContent(
|
||||
mediaType: APPLICATION_JSON,
|
||||
encoding: Encoding.UTF8,
|
||||
content: JsonConvert.SerializeObject(new
|
||||
{
|
||||
windowsUser = Environment.UserName,
|
||||
software,
|
||||
functions
|
||||
}));
|
||||
|
||||
using (var httpResponseMessage = await httpClient.SendAsync(httpRequestMessage))
|
||||
{
|
||||
if (httpResponseMessage.Content != null)
|
||||
{
|
||||
var httpResponseContent = await httpResponseMessage.Content.ReadAsStringAsync();
|
||||
|
||||
_ = int.TryParse(httpResponseContent, out applicationId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// TODO: Log the error message.
|
||||
}
|
||||
|
||||
return applicationId;
|
||||
})
|
||||
.ConfigureAwait(true)
|
||||
.GetAwaiter()
|
||||
.GetResult();
|
||||
|
||||
internal static IEnumerable<SoftwareFunctions> GetSoftwareFunction<T>(int appId, string username, string password)
|
||||
=> Task
|
||||
.Run(async () =>
|
||||
{
|
||||
var functions = default(IEnumerable<SoftwareFunctions>);
|
||||
|
||||
try
|
||||
{
|
||||
using (var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "/LaaProductionWeb/api/software/functions"))
|
||||
{
|
||||
httpRequestMessage.Content = new StringContent(
|
||||
mediaType: APPLICATION_JSON,
|
||||
encoding: Encoding.UTF8,
|
||||
content: JsonConvert.SerializeObject(new
|
||||
{
|
||||
appId,
|
||||
username,
|
||||
password,
|
||||
windowsUser = Environment.UserName,
|
||||
}));
|
||||
|
||||
using (var httpResponseMessage = await httpClient.SendAsync(httpRequestMessage))
|
||||
{
|
||||
if (httpResponseMessage.IsSuccessStatusCode && httpResponseMessage.Content != null)
|
||||
{
|
||||
var httpResponseContent = await httpResponseMessage.Content.ReadAsStringAsync();
|
||||
|
||||
functions = JsonConvert
|
||||
.DeserializeObject<string[]>(httpResponseContent)
|
||||
.Select(x => Enum.TryParse($"{x}", out SoftwareFunctions f) ? f : SoftwareFunctions.DEV_FILE_CONTROL)
|
||||
.Distinct();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// TODO: Log the error message.
|
||||
}
|
||||
|
||||
return functions;
|
||||
})
|
||||
.ConfigureAwait(true)
|
||||
.GetAwaiter()
|
||||
.GetResult();
|
||||
|
||||
internal static void LogAction(string buttonText, string buttonTag, string user, int appId)
|
||||
=> Task
|
||||
.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var httpRequestMessage = new HttpRequestMessage(HttpMethod.Put, "/LaaProductionWeb/api/software/functions"))
|
||||
{
|
||||
httpRequestMessage.Content = new StringContent(
|
||||
mediaType: APPLICATION_JSON,
|
||||
encoding: Encoding.UTF8,
|
||||
content: JsonConvert.SerializeObject(new
|
||||
{
|
||||
WindowsUser = Environment.UserName,
|
||||
Action = "ACCESS",
|
||||
AppId = appId,
|
||||
Message = $"User '{user}' accessed '{buttonText}' with Tag: {buttonTag}"
|
||||
}));
|
||||
|
||||
_ = await httpClient.SendAsync(httpRequestMessage);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// TODO: Log the error message.
|
||||
}
|
||||
})
|
||||
.ConfigureAwait(true)
|
||||
.GetAwaiter()
|
||||
.GetResult();
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
namespace Xylem.Common.Ui.GenesisToolBox.Infrastructure
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
internal class ApplicationState
|
||||
{
|
||||
internal const string UNAVAILABLE = "Genesis Toolbox is currently not available.";
|
||||
|
||||
private static IEnumerable<SoftwareFunctions> softwareFunctions;
|
||||
|
||||
internal static int Id { get; private set; }
|
||||
|
||||
internal static string User { get; private set; }
|
||||
|
||||
internal static bool IsAuthorized { get; private set; }
|
||||
|
||||
internal static bool Initialized { get; private set; }
|
||||
|
||||
internal static ApplicationVersion Version { get; private set; }
|
||||
= ApplicationVersion.Current;
|
||||
|
||||
internal static void Initialize()
|
||||
{
|
||||
Id = ApplicationHttp.ApplicationId(
|
||||
software: Version.Assembly.Name,
|
||||
functions: Enum.GetNames(typeof(SoftwareFunctions)));
|
||||
Initialized = Id > 0;
|
||||
}
|
||||
|
||||
internal static bool Authorize(string username, string password, out string error)
|
||||
{
|
||||
error = default(string);
|
||||
|
||||
if (Id <= 0)
|
||||
{
|
||||
error = "Genesis Toolbox is currently not available.";
|
||||
}
|
||||
else
|
||||
{
|
||||
softwareFunctions = ApplicationHttp.GetSoftwareFunction<SoftwareFunctions>(Id, username, password);
|
||||
IsAuthorized = softwareFunctions != null;
|
||||
User = username;
|
||||
|
||||
if (!IsAuthorized)
|
||||
{
|
||||
error = "Genesis Toolbox is currently not available.";
|
||||
softwareFunctions = Array.Empty<SoftwareFunctions>();
|
||||
}
|
||||
}
|
||||
|
||||
return IsAuthorized;
|
||||
}
|
||||
|
||||
internal static Boolean IsEnabled(SoftwareFunctions softwareFunction)
|
||||
=> softwareFunctions.Contains(softwareFunction);
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
namespace Xylem.Common.Ui.GenesisToolBox.Infrastructure
|
||||
{
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
internal struct ApplicationVersion
|
||||
{
|
||||
private ApplicationVersion(bool initialize)
|
||||
{
|
||||
if (initialize)
|
||||
{
|
||||
this.Assembly = System.Reflection.Assembly
|
||||
.GetExecutingAssembly()
|
||||
.GetName();
|
||||
this.Major = this.Assembly.Version.Major;
|
||||
this.Minor = this.Assembly.Version.Minor;
|
||||
this.Build = this.Assembly.Version.Build;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Major = default(int);
|
||||
this.Minor = default(int);
|
||||
this.Build = default(int);
|
||||
this.Assembly = default(AssemblyName);
|
||||
}
|
||||
}
|
||||
|
||||
public int Major { get; }
|
||||
|
||||
public int Minor { get; }
|
||||
|
||||
public int Build { get; }
|
||||
|
||||
public AssemblyName Assembly { get; }
|
||||
|
||||
public override string ToString()
|
||||
=> $"{nameof(Version)}: {this.Major}.{this.Minor}.{this.Build}";
|
||||
|
||||
public static ApplicationVersion Current => new ApplicationVersion(true);
|
||||
|
||||
public static implicit operator string(ApplicationVersion assemblyVersion)
|
||||
=> assemblyVersion.ToString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
namespace Xylem.Common.Ui.GenesisToolBox.Infrastructure
|
||||
{
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using Xylem.Common.CommonCore.Configuration;
|
||||
using Xylem.Common.Logic.SoftwareAccessHelper;
|
||||
|
||||
/// <summary>
|
||||
/// Holds informations over current software and logged in user.
|
||||
/// </summary>
|
||||
internal class Software
|
||||
{
|
||||
private static string bearer;
|
||||
private static IEnumerable<SoftwareFunctions> softwareFunctions = Array.Empty<SoftwareFunctions>();
|
||||
|
||||
public static Boolean HasUser => !string.IsNullOrWhiteSpace(bearer);
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
var version = SoftwareVersion.Current;
|
||||
var user = new SoftwareUser();
|
||||
|
||||
Login(new ADLoginModel
|
||||
{
|
||||
Assembly = version.AssemblyName.Name,
|
||||
Email = user.Email,
|
||||
EmployeeId = user.EmployeeId,
|
||||
FirstName = user.FirstName,
|
||||
LastName = user.LastName,
|
||||
Phone = user.Phone,
|
||||
Username = user.Username,
|
||||
MajorV = version.MajorV,
|
||||
MinorV = version.MinorV,
|
||||
BuildV = version.BuildV,
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends login request and obtains an bearer authorization token.
|
||||
/// </summary>
|
||||
/// <param name="model"><see cref="ADLoginModel"/> - containing all software and user info required for authentication.</param>
|
||||
public static void Login(ADLoginModel model)
|
||||
{
|
||||
var authenticationResponse = LocalWebRequest.PostRequestAndGetResponseAsync(
|
||||
url: $"{ServiceUrls.LaaProductionAPI}/LaaProductionWeb/API/Login/AD",
|
||||
json: model);
|
||||
|
||||
bearer = authenticationResponse.Content;
|
||||
softwareFunctions = GetFunctions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends login request and obtains an bearer authorization token.
|
||||
/// </summary>
|
||||
public static bool Login(string username, string password)
|
||||
{
|
||||
var authenticationResponse = LocalWebRequest.PostRequestAndGetResponseAsync(
|
||||
url: $"{ServiceUrls.LaaProductionAPI}/LaaProductionWeb/API/Login/Local",
|
||||
json: new UserLoginModel
|
||||
{
|
||||
Username = username,
|
||||
Password = password,
|
||||
Assembly = SoftwareVersion.Current.Name,
|
||||
MajorV = SoftwareVersion.Current.MajorV,
|
||||
MinorV = SoftwareVersion.Current.MinorV,
|
||||
BuildV = SoftwareVersion.Current.BuildV,
|
||||
});
|
||||
|
||||
bearer = authenticationResponse.Content;
|
||||
softwareFunctions = GetFunctions();
|
||||
|
||||
return HasUser;
|
||||
}
|
||||
|
||||
public static IEnumerable<SoftwareFunctions> GetFunctions()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(bearer))
|
||||
{
|
||||
return Array.Empty<SoftwareFunctions>();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var functionsResponse = LocalWebRequest.GetRequest(
|
||||
timeoutMs: 1200,
|
||||
url: $"{ServiceUrls.LaaProductionAPI}/LaaProductionWeb/API/Personalization/Software/Access",
|
||||
header: new Dictionary<string, string> { { "Authorization", $"Bearer {bearer}" } });
|
||||
|
||||
return JsonConvert
|
||||
.DeserializeObject<IEnumerable<string>>(functionsResponse)
|
||||
?.Select(x => Enum.TryParse($"{x}", out SoftwareFunctions f) ? f : default(SoftwareFunctions))
|
||||
?? Array.Empty<SoftwareFunctions>();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
|
||||
return Array.Empty<SoftwareFunctions>();
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsEnabled(SoftwareFunctions softwareFunction)
|
||||
=> softwareFunction != SoftwareFunctions.NONE && softwareFunctions.Contains(softwareFunction);
|
||||
|
||||
public static void Logout()
|
||||
{
|
||||
bearer = default(string);
|
||||
softwareFunctions = Array.Empty<SoftwareFunctions>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
{
|
||||
internal enum SoftwareFunctions
|
||||
{
|
||||
NONE,
|
||||
|
||||
DEV_FILE_CONTROL,
|
||||
DEV_FILE_SPLIT,
|
||||
DEV_LEGACY_TEST_APP,
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
namespace Xylem.Common.Ui.GenesisToolBox.Infrastructure
|
||||
{
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.DirectoryServices;
|
||||
using System.DirectoryServices.AccountManagement;
|
||||
|
||||
internal class SoftwareUser
|
||||
{
|
||||
public SoftwareUser()
|
||||
=> this.InitializeSoftwareUser();
|
||||
|
||||
public int EmployeeId { get; private set; }
|
||||
|
||||
public string FirstName { get; private set; }
|
||||
|
||||
public string LastName { get; private set; }
|
||||
|
||||
public string Username { get; private set; }
|
||||
|
||||
public string Phone { get; private set; }
|
||||
|
||||
public string Email { get; private set; }
|
||||
|
||||
private void InitializeSoftwareUser()
|
||||
{
|
||||
try
|
||||
{
|
||||
var currentUser = UserPrincipal.Current;
|
||||
|
||||
using (var directoryEntry = new DirectoryEntry($"LDAP://{currentUser.DistinguishedName}"))
|
||||
{
|
||||
using (var directorySearcher = new DirectorySearcher(directoryEntry))
|
||||
{
|
||||
var searchResult = directorySearcher.FindOne();
|
||||
|
||||
foreach (DictionaryEntry dictionaryEntry in searchResult.Properties)
|
||||
{
|
||||
if (dictionaryEntry.Key is string property)
|
||||
{
|
||||
if (property.Equals("employeeid", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (dictionaryEntry.Value is ResultPropertyValueCollection dictionaryEntryValues)
|
||||
{
|
||||
if (dictionaryEntryValues.Count > 0 && dictionaryEntryValues[0] is string value)
|
||||
{
|
||||
if (int.TryParse(value, out int employeeId))
|
||||
{
|
||||
this.EmployeeId = employeeId;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (property.Equals("givenname", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (dictionaryEntry.Value is ResultPropertyValueCollection dictionaryEntryValues)
|
||||
{
|
||||
if (dictionaryEntryValues.Count > 0 && dictionaryEntryValues[0] is string firstName)
|
||||
{
|
||||
this.FirstName = firstName;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (property.Equals("sn", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (dictionaryEntry.Value is ResultPropertyValueCollection dictionaryEntryValues)
|
||||
{
|
||||
if (dictionaryEntryValues.Count > 0 && dictionaryEntryValues[0] is string lastName)
|
||||
{
|
||||
this.LastName = lastName;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (property.Equals("mail", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (dictionaryEntry.Value is ResultPropertyValueCollection dictionaryEntryValues)
|
||||
{
|
||||
if (dictionaryEntryValues.Count > 0 && dictionaryEntryValues[0] is string email)
|
||||
{
|
||||
this.Email = email;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (property.Equals("telephonenumber", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (dictionaryEntry.Value is ResultPropertyValueCollection dictionaryEntryValues)
|
||||
{
|
||||
if (dictionaryEntryValues.Count > 0 && dictionaryEntryValues[0] is string phone)
|
||||
{
|
||||
this.Phone = phone;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (property.Equals("samaccountname", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (dictionaryEntry.Value is ResultPropertyValueCollection dictionaryEntryValues)
|
||||
{
|
||||
if (dictionaryEntryValues.Count > 0 && dictionaryEntryValues[0] is string username)
|
||||
{
|
||||
this.Username = username.ToLower();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
namespace Xylem.Common.Ui.GenesisToolBox.Infrastructure
|
||||
{
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
internal struct SoftwareVersion
|
||||
{
|
||||
private SoftwareVersion(bool initialize)
|
||||
{
|
||||
this.AssemblyName = Assembly
|
||||
.GetExecutingAssembly()
|
||||
.GetName();
|
||||
this.Name = this.AssemblyName.Name;
|
||||
|
||||
var version = this.AssemblyName.Version;
|
||||
|
||||
this.MajorV = version.Major;
|
||||
this.MinorV = version.Minor;
|
||||
this.BuildV = version.Build;
|
||||
this.VersionString = $"{this.MajorV}.{this.MinorV}.{this.BuildV}";
|
||||
}
|
||||
|
||||
public string Name { get; internal set; }
|
||||
|
||||
public int MajorV { get; internal set; }
|
||||
|
||||
public int MinorV { get; internal set; }
|
||||
|
||||
public int BuildV { get; internal set; }
|
||||
|
||||
public string VersionString { get; }
|
||||
|
||||
public AssemblyName AssemblyName { get; }
|
||||
|
||||
public override string ToString()
|
||||
=> $"{nameof(Version)}: {this.VersionString}";
|
||||
|
||||
public static SoftwareVersion Current = new SoftwareVersion(true);
|
||||
|
||||
public static implicit operator string(SoftwareVersion assemblyVersion)
|
||||
=> assemblyVersion.ToString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace Xylem.Common.Ui.GenesisToolBox.Infrastructure
|
||||
{
|
||||
internal class UserLoginModel
|
||||
{
|
||||
public string Assembly { get; set; }
|
||||
|
||||
public int MajorV { get; set; }
|
||||
|
||||
public int MinorV { get; set; }
|
||||
|
||||
public int BuildV { get; set; }
|
||||
|
||||
public string Username { get; set; }
|
||||
|
||||
public string Password { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
internal static void Main()
|
||||
{
|
||||
// Initializes application state for the hole application as static properties and methods.
|
||||
ApplicationState.Initialize();
|
||||
Software.Initialize();
|
||||
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
|
||||
+80
-44
@@ -50,10 +50,14 @@
|
||||
this.BtnFileSplit = new System.Windows.Forms.Button();
|
||||
this.btnFiles = new System.Windows.Forms.Button();
|
||||
this.btnLegacyTestApp = new System.Windows.Forms.Button();
|
||||
this.lblVersionNumber = new System.Windows.Forms.Label();
|
||||
this.menu = new System.Windows.Forms.MenuStrip();
|
||||
this.loginToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.loginToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.logoutMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.gpGerneral.SuspendLayout();
|
||||
this.gpLAA.SuspendLayout();
|
||||
this.gbDeveloper.SuspendLayout();
|
||||
this.menu.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// gpGerneral
|
||||
@@ -69,9 +73,9 @@
|
||||
this.gpGerneral.Controls.Add(this.btnAlarm);
|
||||
this.gpGerneral.Controls.Add(this.btnSetup);
|
||||
this.gpGerneral.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.gpGerneral.Location = new System.Drawing.Point(18, 37);
|
||||
this.gpGerneral.Location = new System.Drawing.Point(7, 27);
|
||||
this.gpGerneral.Name = "gpGerneral";
|
||||
this.gpGerneral.Size = new System.Drawing.Size(181, 459);
|
||||
this.gpGerneral.Size = new System.Drawing.Size(175, 459);
|
||||
this.gpGerneral.TabIndex = 19;
|
||||
this.gpGerneral.TabStop = false;
|
||||
this.gpGerneral.Text = "General";
|
||||
@@ -81,7 +85,7 @@
|
||||
this.button1.Enabled = false;
|
||||
this.button1.Location = new System.Drawing.Point(5, 413);
|
||||
this.button1.Name = "button1";
|
||||
this.button1.Size = new System.Drawing.Size(152, 40);
|
||||
this.button1.Size = new System.Drawing.Size(164, 40);
|
||||
this.button1.TabIndex = 19;
|
||||
this.button1.Text = "Pulse Config";
|
||||
this.button1.UseVisualStyleBackColor = true;
|
||||
@@ -92,7 +96,7 @@
|
||||
this.button4.Enabled = false;
|
||||
this.button4.Location = new System.Drawing.Point(6, 324);
|
||||
this.button4.Name = "button4";
|
||||
this.button4.Size = new System.Drawing.Size(151, 39);
|
||||
this.button4.Size = new System.Drawing.Size(163, 39);
|
||||
this.button4.TabIndex = 18;
|
||||
this.button4.Text = "LUT Managment";
|
||||
this.button4.UseVisualStyleBackColor = true;
|
||||
@@ -102,7 +106,7 @@
|
||||
//
|
||||
this.btnLutUpdate.Location = new System.Drawing.Point(7, 279);
|
||||
this.btnLutUpdate.Name = "btnLutUpdate";
|
||||
this.btnLutUpdate.Size = new System.Drawing.Size(151, 39);
|
||||
this.btnLutUpdate.Size = new System.Drawing.Size(162, 39);
|
||||
this.btnLutUpdate.TabIndex = 17;
|
||||
this.btnLutUpdate.Text = "LUT Update";
|
||||
this.btnLutUpdate.UseVisualStyleBackColor = true;
|
||||
@@ -113,7 +117,7 @@
|
||||
this.btnPressure.Enabled = false;
|
||||
this.btnPressure.Location = new System.Drawing.Point(6, 369);
|
||||
this.btnPressure.Name = "btnPressure";
|
||||
this.btnPressure.Size = new System.Drawing.Size(152, 40);
|
||||
this.btnPressure.Size = new System.Drawing.Size(163, 40);
|
||||
this.btnPressure.TabIndex = 15;
|
||||
this.btnPressure.Text = "Pressure Log";
|
||||
this.btnPressure.UseVisualStyleBackColor = true;
|
||||
@@ -123,7 +127,7 @@
|
||||
//
|
||||
this.btnFwUpdate.Location = new System.Drawing.Point(6, 235);
|
||||
this.btnFwUpdate.Name = "btnFwUpdate";
|
||||
this.btnFwUpdate.Size = new System.Drawing.Size(151, 39);
|
||||
this.btnFwUpdate.Size = new System.Drawing.Size(163, 39);
|
||||
this.btnFwUpdate.TabIndex = 12;
|
||||
this.btnFwUpdate.Text = "Firmware Update";
|
||||
this.btnFwUpdate.UseVisualStyleBackColor = true;
|
||||
@@ -133,7 +137,7 @@
|
||||
//
|
||||
this.btnStreamingQuality.Location = new System.Drawing.Point(6, 191);
|
||||
this.btnStreamingQuality.Name = "btnStreamingQuality";
|
||||
this.btnStreamingQuality.Size = new System.Drawing.Size(152, 40);
|
||||
this.btnStreamingQuality.Size = new System.Drawing.Size(163, 40);
|
||||
this.btnStreamingQuality.TabIndex = 11;
|
||||
this.btnStreamingQuality.Text = "StreamingQuality";
|
||||
this.btnStreamingQuality.UseVisualStyleBackColor = true;
|
||||
@@ -144,7 +148,7 @@
|
||||
this.btnTempLogger.Enabled = false;
|
||||
this.btnTempLogger.Location = new System.Drawing.Point(6, 147);
|
||||
this.btnTempLogger.Name = "btnTempLogger";
|
||||
this.btnTempLogger.Size = new System.Drawing.Size(152, 40);
|
||||
this.btnTempLogger.Size = new System.Drawing.Size(163, 40);
|
||||
this.btnTempLogger.TabIndex = 10;
|
||||
this.btnTempLogger.Text = "Temp Meter";
|
||||
this.btnTempLogger.UseVisualStyleBackColor = true;
|
||||
@@ -155,7 +159,7 @@
|
||||
this.btnRegisterStore.Enabled = false;
|
||||
this.btnRegisterStore.Location = new System.Drawing.Point(6, 103);
|
||||
this.btnRegisterStore.Name = "btnRegisterStore";
|
||||
this.btnRegisterStore.Size = new System.Drawing.Size(152, 40);
|
||||
this.btnRegisterStore.Size = new System.Drawing.Size(163, 40);
|
||||
this.btnRegisterStore.TabIndex = 9;
|
||||
this.btnRegisterStore.Text = "RegisterStore";
|
||||
this.btnRegisterStore.UseVisualStyleBackColor = true;
|
||||
@@ -166,7 +170,7 @@
|
||||
this.btnAlarm.Enabled = false;
|
||||
this.btnAlarm.Location = new System.Drawing.Point(6, 59);
|
||||
this.btnAlarm.Name = "btnAlarm";
|
||||
this.btnAlarm.Size = new System.Drawing.Size(152, 40);
|
||||
this.btnAlarm.Size = new System.Drawing.Size(163, 40);
|
||||
this.btnAlarm.TabIndex = 8;
|
||||
this.btnAlarm.Text = "Alarm";
|
||||
this.btnAlarm.UseVisualStyleBackColor = true;
|
||||
@@ -176,7 +180,7 @@
|
||||
//
|
||||
this.btnSetup.Location = new System.Drawing.Point(6, 15);
|
||||
this.btnSetup.Name = "btnSetup";
|
||||
this.btnSetup.Size = new System.Drawing.Size(152, 40);
|
||||
this.btnSetup.Size = new System.Drawing.Size(163, 40);
|
||||
this.btnSetup.TabIndex = 1;
|
||||
this.btnSetup.Text = "Setup";
|
||||
this.btnSetup.UseVisualStyleBackColor = true;
|
||||
@@ -190,9 +194,9 @@
|
||||
this.gpLAA.Controls.Add(this.btnRegHistory);
|
||||
this.gpLAA.Controls.Add(this.btnPassword);
|
||||
this.gpLAA.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.gpLAA.Location = new System.Drawing.Point(201, 37);
|
||||
this.gpLAA.Location = new System.Drawing.Point(186, 27);
|
||||
this.gpLAA.Name = "gpLAA";
|
||||
this.gpLAA.Size = new System.Drawing.Size(181, 240);
|
||||
this.gpLAA.Size = new System.Drawing.Size(168, 235);
|
||||
this.gpLAA.TabIndex = 20;
|
||||
this.gpLAA.TabStop = false;
|
||||
this.gpLAA.Text = "Production LAA";
|
||||
@@ -202,7 +206,7 @@
|
||||
this.button5.Enabled = false;
|
||||
this.button5.Location = new System.Drawing.Point(4, 191);
|
||||
this.button5.Name = "button5";
|
||||
this.button5.Size = new System.Drawing.Size(152, 40);
|
||||
this.button5.Size = new System.Drawing.Size(157, 40);
|
||||
this.button5.TabIndex = 21;
|
||||
this.button5.Text = "Mapping NA";
|
||||
this.button5.UseMnemonic = false;
|
||||
@@ -214,7 +218,7 @@
|
||||
this.button2.Enabled = false;
|
||||
this.button2.Location = new System.Drawing.Point(4, 147);
|
||||
this.button2.Name = "button2";
|
||||
this.button2.Size = new System.Drawing.Size(152, 40);
|
||||
this.button2.Size = new System.Drawing.Size(157, 40);
|
||||
this.button2.TabIndex = 20;
|
||||
this.button2.Text = "Process Parameter";
|
||||
this.button2.UseMnemonic = false;
|
||||
@@ -226,7 +230,7 @@
|
||||
this.btnPara.Enabled = false;
|
||||
this.btnPara.Location = new System.Drawing.Point(5, 103);
|
||||
this.btnPara.Name = "btnPara";
|
||||
this.btnPara.Size = new System.Drawing.Size(152, 40);
|
||||
this.btnPara.Size = new System.Drawing.Size(156, 40);
|
||||
this.btnPara.TabIndex = 19;
|
||||
this.btnPara.Text = "Parameterization";
|
||||
this.btnPara.UseMnemonic = false;
|
||||
@@ -238,7 +242,7 @@
|
||||
this.btnRegHistory.Enabled = false;
|
||||
this.btnRegHistory.Location = new System.Drawing.Point(5, 59);
|
||||
this.btnRegHistory.Name = "btnRegHistory";
|
||||
this.btnRegHistory.Size = new System.Drawing.Size(152, 40);
|
||||
this.btnRegHistory.Size = new System.Drawing.Size(156, 40);
|
||||
this.btnRegHistory.TabIndex = 17;
|
||||
this.btnRegHistory.Text = "Register History";
|
||||
this.btnRegHistory.UseVisualStyleBackColor = true;
|
||||
@@ -249,7 +253,7 @@
|
||||
this.btnPassword.Enabled = false;
|
||||
this.btnPassword.Location = new System.Drawing.Point(5, 15);
|
||||
this.btnPassword.Name = "btnPassword";
|
||||
this.btnPassword.Size = new System.Drawing.Size(152, 40);
|
||||
this.btnPassword.Size = new System.Drawing.Size(156, 40);
|
||||
this.btnPassword.TabIndex = 2;
|
||||
this.btnPassword.Text = "Password";
|
||||
this.btnPassword.UseVisualStyleBackColor = true;
|
||||
@@ -257,9 +261,9 @@
|
||||
//
|
||||
// btnLowLevelTools
|
||||
//
|
||||
this.btnLowLevelTools.Location = new System.Drawing.Point(4, 167);
|
||||
this.btnLowLevelTools.Location = new System.Drawing.Point(4, 158);
|
||||
this.btnLowLevelTools.Name = "btnLowLevelTools";
|
||||
this.btnLowLevelTools.Size = new System.Drawing.Size(152, 40);
|
||||
this.btnLowLevelTools.Size = new System.Drawing.Size(157, 40);
|
||||
this.btnLowLevelTools.TabIndex = 22;
|
||||
this.btnLowLevelTools.Text = "Low Level Tools";
|
||||
this.btnLowLevelTools.UseMnemonic = false;
|
||||
@@ -273,9 +277,9 @@
|
||||
this.gbDeveloper.Controls.Add(this.btnFiles);
|
||||
this.gbDeveloper.Controls.Add(this.btnLegacyTestApp);
|
||||
this.gbDeveloper.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.gbDeveloper.Location = new System.Drawing.Point(201, 283);
|
||||
this.gbDeveloper.Location = new System.Drawing.Point(186, 282);
|
||||
this.gbDeveloper.Name = "gbDeveloper";
|
||||
this.gbDeveloper.Size = new System.Drawing.Size(181, 213);
|
||||
this.gbDeveloper.Size = new System.Drawing.Size(168, 204);
|
||||
this.gbDeveloper.TabIndex = 21;
|
||||
this.gbDeveloper.TabStop = false;
|
||||
this.gbDeveloper.Text = "Developer";
|
||||
@@ -284,9 +288,9 @@
|
||||
// BtnFileSplit
|
||||
//
|
||||
this.BtnFileSplit.Enabled = false;
|
||||
this.BtnFileSplit.Location = new System.Drawing.Point(4, 123);
|
||||
this.BtnFileSplit.Location = new System.Drawing.Point(4, 114);
|
||||
this.BtnFileSplit.Name = "BtnFileSplit";
|
||||
this.BtnFileSplit.Size = new System.Drawing.Size(152, 40);
|
||||
this.BtnFileSplit.Size = new System.Drawing.Size(157, 40);
|
||||
this.BtnFileSplit.TabIndex = 18;
|
||||
this.BtnFileSplit.Text = "File Split";
|
||||
this.BtnFileSplit.UseMnemonic = false;
|
||||
@@ -296,9 +300,9 @@
|
||||
// btnFiles
|
||||
//
|
||||
this.btnFiles.Enabled = false;
|
||||
this.btnFiles.Location = new System.Drawing.Point(4, 77);
|
||||
this.btnFiles.Location = new System.Drawing.Point(4, 68);
|
||||
this.btnFiles.Name = "btnFiles";
|
||||
this.btnFiles.Size = new System.Drawing.Size(152, 40);
|
||||
this.btnFiles.Size = new System.Drawing.Size(157, 40);
|
||||
this.btnFiles.TabIndex = 16;
|
||||
this.btnFiles.Text = "FileControl";
|
||||
this.btnFiles.UseVisualStyleBackColor = true;
|
||||
@@ -307,36 +311,64 @@
|
||||
// btnLegacyTestApp
|
||||
//
|
||||
this.btnLegacyTestApp.Enabled = false;
|
||||
this.btnLegacyTestApp.Location = new System.Drawing.Point(4, 33);
|
||||
this.btnLegacyTestApp.Location = new System.Drawing.Point(4, 24);
|
||||
this.btnLegacyTestApp.Name = "btnLegacyTestApp";
|
||||
this.btnLegacyTestApp.Size = new System.Drawing.Size(151, 40);
|
||||
this.btnLegacyTestApp.Size = new System.Drawing.Size(157, 40);
|
||||
this.btnLegacyTestApp.TabIndex = 15;
|
||||
this.btnLegacyTestApp.Text = "LegacyTestApp";
|
||||
this.btnLegacyTestApp.UseVisualStyleBackColor = true;
|
||||
this.btnLegacyTestApp.Click += new System.EventHandler(this.btnLegacyTestApp_Click);
|
||||
//
|
||||
// lblVersionNumber
|
||||
// menu
|
||||
//
|
||||
this.lblVersionNumber.AutoSize = true;
|
||||
this.lblVersionNumber.Location = new System.Drawing.Point(22, 9);
|
||||
this.lblVersionNumber.Name = "lblVersionNumber";
|
||||
this.lblVersionNumber.Size = new System.Drawing.Size(37, 13);
|
||||
this.lblVersionNumber.TabIndex = 23;
|
||||
this.lblVersionNumber.Text = "----------";
|
||||
this.menu.AutoSize = false;
|
||||
this.menu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.loginToolStripMenuItem});
|
||||
this.menu.Location = new System.Drawing.Point(0, 0);
|
||||
this.menu.Name = "menu";
|
||||
this.menu.Size = new System.Drawing.Size(361, 24);
|
||||
this.menu.TabIndex = 24;
|
||||
this.menu.TextDirection = System.Windows.Forms.ToolStripTextDirection.Vertical90;
|
||||
//
|
||||
// loginToolStripMenuItem
|
||||
//
|
||||
this.loginToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.loginToolStripMenuItem1,
|
||||
this.logoutMenuItem});
|
||||
this.loginToolStripMenuItem.Name = "loginToolStripMenuItem";
|
||||
this.loginToolStripMenuItem.Size = new System.Drawing.Size(61, 20);
|
||||
this.loginToolStripMenuItem.Text = "Options";
|
||||
this.loginToolStripMenuItem.TextDirection = System.Windows.Forms.ToolStripTextDirection.Horizontal;
|
||||
//
|
||||
// loginToolStripMenuItem1
|
||||
//
|
||||
this.loginToolStripMenuItem1.Name = "loginToolStripMenuItem1";
|
||||
this.loginToolStripMenuItem1.Size = new System.Drawing.Size(180, 22);
|
||||
this.loginToolStripMenuItem1.Text = "Login";
|
||||
this.loginToolStripMenuItem1.Click += new System.EventHandler(this.OnLoginClick);
|
||||
//
|
||||
// logoutMenuItem
|
||||
//
|
||||
this.logoutMenuItem.Name = "logoutMenuItem";
|
||||
this.logoutMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.logoutMenuItem.Text = "Logout";
|
||||
this.logoutMenuItem.Click += new System.EventHandler(this.OnLogoutClick);
|
||||
//
|
||||
// FrmMainForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(390, 497);
|
||||
this.Controls.Add(this.lblVersionNumber);
|
||||
this.ClientSize = new System.Drawing.Size(361, 491);
|
||||
this.Controls.Add(this.gbDeveloper);
|
||||
this.Controls.Add(this.gpLAA);
|
||||
this.Controls.Add(this.gpGerneral);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
|
||||
this.Controls.Add(this.menu);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
|
||||
this.MainMenuStrip = this.menu;
|
||||
this.MaximizeBox = false;
|
||||
this.MaximumSize = new System.Drawing.Size(410, 540);
|
||||
this.MinimumSize = new System.Drawing.Size(410, 540);
|
||||
this.MaximumSize = new System.Drawing.Size(377, 530);
|
||||
this.MinimizeBox = false;
|
||||
this.MinimumSize = new System.Drawing.Size(377, 530);
|
||||
this.Name = "FrmMainForm";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "Genesis ToolBox";
|
||||
@@ -344,8 +376,9 @@
|
||||
this.gpGerneral.ResumeLayout(false);
|
||||
this.gpLAA.ResumeLayout(false);
|
||||
this.gbDeveloper.ResumeLayout(false);
|
||||
this.menu.ResumeLayout(false);
|
||||
this.menu.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
@@ -371,9 +404,12 @@
|
||||
private System.Windows.Forms.Button button2;
|
||||
private System.Windows.Forms.Button button4;
|
||||
private System.Windows.Forms.Button button5;
|
||||
private System.Windows.Forms.Label lblVersionNumber;
|
||||
private System.Windows.Forms.Button button1;
|
||||
private System.Windows.Forms.Button btnLowLevelTools;
|
||||
private System.Windows.Forms.MenuStrip menu;
|
||||
private System.Windows.Forms.ToolStripMenuItem loginToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem loginToolStripMenuItem1;
|
||||
private System.Windows.Forms.ToolStripMenuItem logoutMenuItem;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
namespace Xylem.Common.Ui.GenesisToolBox
|
||||
{
|
||||
using global::GenesisToolBox;
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
@@ -11,6 +12,8 @@
|
||||
using Xylem.Common.Ui.GenesisToolBox.Infrastructure;
|
||||
using Xylem.Common.Utils.Logging;
|
||||
|
||||
delegate void UpdateLayout();
|
||||
|
||||
/// <inheritdoc />
|
||||
public partial class FrmMainForm : Form
|
||||
{
|
||||
@@ -22,9 +25,9 @@
|
||||
this.InitializeComponent();
|
||||
this.InitializeFormState();
|
||||
|
||||
this.lblVersionNumber.Text = ApplicationVersion.Current;
|
||||
this.Text = $"{this.Text} {SoftwareVersion.Current.VersionString}";
|
||||
var logger = NLogHelper.CreateOrGetLogger("GenesisToolBox");
|
||||
logger.Info($"GenesisToolBox {ApplicationVersion.Current}");
|
||||
logger.Info($"GenesisToolBox {SoftwareVersion.Current}");
|
||||
|
||||
//bool valid = false;
|
||||
|
||||
@@ -69,11 +72,10 @@
|
||||
private void FrmMainForm_Load(Object sender, EventArgs e)
|
||||
{
|
||||
Boolean access;
|
||||
btnFiles.Enabled = true;
|
||||
|
||||
try
|
||||
{
|
||||
access = Logic.SoftwareAccessHelper.Access.HasAccess(ApplicationVersion.Current.Assembly);
|
||||
access = Logic.SoftwareAccessHelper.Access.HasAccess(SoftwareVersion.Current.AssemblyName);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -98,15 +100,15 @@
|
||||
{
|
||||
MessageBox.Show("GenesisToolBox\n\n" +
|
||||
"Your version licence has expired\n\n" +
|
||||
ApplicationVersion.Current);
|
||||
SoftwareVersion.Current);
|
||||
|
||||
Close();
|
||||
}
|
||||
|
||||
if (System.Diagnostics.Debugger.IsAttached)
|
||||
{
|
||||
btnFiles.Enabled = true;
|
||||
}
|
||||
//if (System.Diagnostics.Debugger.IsAttached)
|
||||
//{
|
||||
// btnFiles.Enabled = true;
|
||||
//}
|
||||
|
||||
CheckConfigs();
|
||||
|
||||
@@ -428,7 +430,7 @@
|
||||
this.Controls.Add(new Label()
|
||||
{
|
||||
Dock = DockStyle.Fill,
|
||||
Text = ApplicationState.UNAVAILABLE,
|
||||
Text = "Genesis toolbox is currently not available.",
|
||||
TextAlign = ContentAlignment.MiddleCenter,
|
||||
Font = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold),
|
||||
ForeColor = Color.DarkRed,
|
||||
@@ -436,28 +438,6 @@
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Callback method that is called when user enters valid username and password.
|
||||
/// </summary>
|
||||
/// <param name="username">Not null or empty string.</param>
|
||||
/// <param name="password">Not null or empty string.</param>
|
||||
/// <param name="sender">Is the LoginForm from whitch is this method called.</param>
|
||||
private void LoginFormSubmitted(string username, string password, object sender)
|
||||
{
|
||||
if (sender is LoginForm loginForm)
|
||||
{
|
||||
var errorMessage = default(string);
|
||||
|
||||
if (ApplicationState.Authorize(username, password, out errorMessage))
|
||||
{
|
||||
this.Controls.Remove(loginForm);
|
||||
this.ShowAvailableSoftwareFunctions();
|
||||
}
|
||||
|
||||
loginForm.ShowError(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows all UI controlls. Sets control enabled or disabled, having tag that is from type SoftwareFunctions.
|
||||
/// </summary>
|
||||
@@ -473,10 +453,8 @@
|
||||
{
|
||||
if (button.Tag is SoftwareFunctions softwareFunction)
|
||||
{
|
||||
button.Enabled = ApplicationState.IsEnabled(softwareFunction);
|
||||
button.Enabled = Software.IsEnabled(softwareFunction);
|
||||
}
|
||||
|
||||
button.Click += LogUserAction;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -485,19 +463,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tracks users interactions with the UI by sending it to the web service.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void LogUserAction(object sender, EventArgs e)
|
||||
{
|
||||
if (sender is Button button)
|
||||
{
|
||||
ApplicationHttp.LogAction(button.Text, $"{button.Tag}", ApplicationState.User, ApplicationState.Id);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hides all members but the login form if the app is initialized otherwise shows error message.
|
||||
/// In case that the app is initialized and user is authorized shows all buttons as enabled or disabled depending on the user permissions.
|
||||
@@ -506,18 +471,68 @@
|
||||
{
|
||||
this.HideContent();
|
||||
this.SetSoftwareFunctions();
|
||||
this.ShowAvailableSoftwareFunctions();
|
||||
}
|
||||
|
||||
if (!ApplicationState.Initialized)
|
||||
private void OnLogoutClick(Object sender, EventArgs e)
|
||||
{
|
||||
Software.Logout();
|
||||
|
||||
foreach (var control in this.Controls)
|
||||
{
|
||||
this.UINotAvailable();
|
||||
if (control is LoginForm loginForm)
|
||||
{
|
||||
this.Controls.Remove(loginForm);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (!ApplicationState.IsAuthorized)
|
||||
|
||||
this.ShowAvailableSoftwareFunctions();
|
||||
}
|
||||
|
||||
private void OnLoginClick(object sender, EventArgs args)
|
||||
{
|
||||
this.HideContent();
|
||||
|
||||
var hasLoginForm = false;
|
||||
|
||||
foreach (var control in this.Controls)
|
||||
{
|
||||
if (control is LoginForm loginForm)
|
||||
{
|
||||
hasLoginForm = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasLoginForm)
|
||||
{
|
||||
this.Controls.Add(new LoginForm(this.LoginFormSubmitted));
|
||||
}
|
||||
else
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Callback method that is called when user enters valid username and password.
|
||||
/// </summary>
|
||||
/// <param name="username">Not null or empty string.</param>
|
||||
/// <param name="password">Not null or empty string.</param>
|
||||
/// <param name="sender">Is the LoginForm from whitch is this method called.</param>
|
||||
private void LoginFormSubmitted(string username, string password, object sender)
|
||||
{
|
||||
if (sender is LoginForm loginForm)
|
||||
{
|
||||
this.ShowAvailableSoftwareFunctions();
|
||||
if (Software.Login(username, password))
|
||||
{
|
||||
this.Controls.Remove(loginForm);
|
||||
this.ShowAvailableSoftwareFunctions();
|
||||
this.Update();
|
||||
}
|
||||
else
|
||||
{
|
||||
loginForm.ShowError("Invalid login attempt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -117,4 +117,7 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="menu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
||||
@@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net40" requireReinstallation="true" />
|
||||
<package id="NLog" version="4.6.7" targetFramework="net40" requireReinstallation="true" />
|
||||
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" />
|
||||
<package id="NLog" version="5.2.0" targetFramework="net48" />
|
||||
<package id="QRCoder" version="1.4.3" targetFramework="net40" />
|
||||
<package id="System.DirectoryServices.AccountManagement" version="7.0.0" targetFramework="net48" />
|
||||
<package id="System.Security.Principal.Windows" version="5.0.0" targetFramework="net48" />
|
||||
</packages>
|
||||
+1
-1
@@ -33,7 +33,7 @@
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\LaaProduction.Personalization\</OutputPath>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
using LaaProduction.Personalization.Interfaces;
|
||||
using LaaProduction.Personalization.Models;
|
||||
using LaaProduction.Personalization.Repositories.Interfaces;
|
||||
using LaaProduction.SharedModels;
|
||||
using LaaProductionDI;
|
||||
|
||||
using System;
|
||||
@@ -94,6 +95,78 @@
|
||||
return new ClaimsPrincipal(claimsIdentity);
|
||||
}
|
||||
|
||||
public string Login(ADLoginModel model)
|
||||
{
|
||||
var softwareId = this.GetOrCreateSoftwareId(
|
||||
model.Assembly,
|
||||
model.MajorV,
|
||||
model.MinorV,
|
||||
model.BuildV);
|
||||
|
||||
if (softwareId <= 0)
|
||||
{
|
||||
return default(string);
|
||||
}
|
||||
|
||||
var employeeNr = this.employeesRepository.EmployeeId(model.EmployeeId);
|
||||
|
||||
if (employeeNr <= 0)
|
||||
{
|
||||
employeeNr = this.employeesRepository.Update(
|
||||
model.EmployeeId,
|
||||
model.FirstName,
|
||||
model.LastName,
|
||||
model.Phone,
|
||||
model.Username,
|
||||
model.Email);
|
||||
|
||||
if (employeeNr <= 0)
|
||||
{
|
||||
employeeNr = this.employeesRepository.Insert(
|
||||
model.EmployeeId,
|
||||
model.FirstName,
|
||||
model.LastName,
|
||||
model.Phone,
|
||||
model.Username,
|
||||
model.Email);
|
||||
}
|
||||
}
|
||||
|
||||
if (employeeNr <= 0)
|
||||
{
|
||||
return default(string);
|
||||
}
|
||||
|
||||
this.employeesRepository.CreateToken(softwareId, employeeNr);
|
||||
|
||||
return this.employeesRepository.GetToken(softwareId, employeeNr);
|
||||
}
|
||||
|
||||
public string Login(UserLoginModel model)
|
||||
{
|
||||
var softwareId = this.GetOrCreateSoftwareId(
|
||||
model.Assembly,
|
||||
model.MajorV,
|
||||
model.MinorV,
|
||||
model.BuildV);
|
||||
|
||||
if (softwareId <= 0)
|
||||
{
|
||||
return default(string);
|
||||
}
|
||||
|
||||
var employeeNr = this.employeesRepository.EmployeeId(model.Username, model.Password);
|
||||
|
||||
if (employeeNr <= 0)
|
||||
{
|
||||
return default(string);
|
||||
}
|
||||
|
||||
this.employeesRepository.CreateToken(softwareId, employeeNr);
|
||||
|
||||
return this.employeesRepository.GetToken(softwareId, employeeNr);
|
||||
}
|
||||
|
||||
public void ResetPassword(short employeeId)
|
||||
{
|
||||
this.employeesRepository.ResetPassword(employeeId);
|
||||
@@ -102,5 +175,17 @@
|
||||
|
||||
public void SetPassword(short employeeId, string password)
|
||||
=> this.employeesRepository.SetPassword(employeeId, password);
|
||||
|
||||
private short GetOrCreateSoftwareId(string assembly, int major, int minor, int build)
|
||||
{
|
||||
var softwareId = this.softwareRepository.SoftwareId(assembly, major, minor, build);
|
||||
|
||||
if (softwareId <= 0)
|
||||
{
|
||||
softwareId = this.softwareRepository.Insert(assembly, major, minor, build);
|
||||
}
|
||||
|
||||
return softwareId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
namespace LaaProduction.Personalization.Interfaces
|
||||
{
|
||||
using LaaProduction.SharedModels;
|
||||
|
||||
using System.Security.Principal;
|
||||
|
||||
public interface IAccountManager
|
||||
@@ -8,6 +10,10 @@
|
||||
|
||||
IPrincipal GetClaimsPrincipal(string token);
|
||||
|
||||
string Login(ADLoginModel model);
|
||||
|
||||
string Login(UserLoginModel model);
|
||||
|
||||
void ResetPassword(short employeeId);
|
||||
|
||||
void SetPassword(short employeeId, string password);
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
IEnumerable<string> GetFunctions();
|
||||
|
||||
IEnumerable<string> GetFunctions(short appId);
|
||||
IEnumerable<string> GetFunctions(string token);
|
||||
|
||||
IEnumerable<object> ListSoftwares();
|
||||
|
||||
|
||||
BIN
Binary file not shown.
@@ -92,6 +92,12 @@
|
||||
<None Include="packages.config" />
|
||||
<None Include="README.md" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\LaaProduction.SharedModels\LaaProduction.SharedModels.csproj">
|
||||
<Project>{0BF77588-2684-459D-8C71-DBBC6B05E9EE}</Project>
|
||||
<Name>LaaProduction.SharedModels</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>
|
||||
|
||||
@@ -50,13 +50,14 @@
|
||||
}, new EmployeeComparer())
|
||||
.Select(x =>
|
||||
{
|
||||
x.Key.Roles = x.Select(r => r.Role).Distinct();
|
||||
x.Key.Roles = x.Select(r => r.Role).Distinct().Where(r => !string.IsNullOrWhiteSpace(r));
|
||||
x.Key.RolesCount = x.Key.Roles.Count();
|
||||
x.Key.Functions = x.Select(f => f.Function).Distinct();
|
||||
x.Key.Functions = x.Select(f => f.Function).Distinct().Where(r => !string.IsNullOrWhiteSpace(r));
|
||||
x.Key.FunctionsCount = x.Key.Functions.Count();
|
||||
|
||||
return x.Key;
|
||||
});
|
||||
})
|
||||
.ToList();
|
||||
|
||||
public void CreateToken(short appId, short userId)
|
||||
=> this.sqlConnection
|
||||
@@ -70,6 +71,15 @@
|
||||
.SetParameter(nameof(userId), userId)
|
||||
.ExecuteNonQuery();
|
||||
|
||||
public short EmployeeId(int employeeId)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
SELECT [MitarbeiterNr]
|
||||
FROM [Mitarbeiter]
|
||||
WHERE [EmployeeId] = @{nameof(employeeId)}")
|
||||
.SetParameter(nameof(employeeId), employeeId)
|
||||
.FirstOrDefault(x => x.GetSmallint());
|
||||
|
||||
public short EmployeeId(string username, string password)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
@@ -153,6 +163,37 @@
|
||||
.SetParameter(nameof(token), token)
|
||||
.ExecuteReader(x => x.GetString());
|
||||
|
||||
public short Insert(int employeeId, string firstName, string lastName, string phone, string username, string email)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
INSERT INTO [Mitarbeiter] (
|
||||
[MitarbeiterNr]
|
||||
, [EmployeeId]
|
||||
, [Vorname]
|
||||
, [Name]
|
||||
, [Telefon]
|
||||
, [Benutzername]
|
||||
, [AnlageDatum]
|
||||
, [eMail]
|
||||
, [DomainUser])
|
||||
OUTPUT [inserted].[MitarbeiterNr]
|
||||
VALUES ((SELECT MAX([MitarbeiterNr]) + 1 FROM [Mitarbeiter])
|
||||
, @{nameof(employeeId)}
|
||||
, @{nameof(firstName)}
|
||||
, @{nameof(lastName)}
|
||||
, @{nameof(phone)}
|
||||
, @{nameof(username)}
|
||||
, GETDATE()
|
||||
, @{nameof(email)}
|
||||
, @{nameof(username)})")
|
||||
.SetParameter(nameof(employeeId), employeeId)
|
||||
.SetParameter(nameof(firstName), firstName)
|
||||
.SetParameter(nameof(lastName), lastName)
|
||||
.SetParameter(nameof(phone), phone)
|
||||
.SetParameter(nameof(username), username)
|
||||
.SetParameter(nameof(email), email)
|
||||
.ExecuteScalar(x => x.GetSmallint());
|
||||
|
||||
public void ResetPassword(short employeeId)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
@@ -179,5 +220,25 @@
|
||||
.SetParameter(nameof(employeeId), employeeId)
|
||||
.SetParameter(nameof(password), password)
|
||||
.ExecuteNonQuery();
|
||||
|
||||
public short Update(int employeeId, string firstName, string lastName, string phone, string username, string email)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
UPDATE [Mitarbeiter]
|
||||
SET [EmployeeId] = ISNULL(@{nameof(employeeId)}, [EmployeeId])
|
||||
, [eMail] = ISNULL(@{nameof(email)}, [eMail])
|
||||
, [Telefon] = ISNULL(@{nameof(phone)}, [Telefon])
|
||||
, [DomainUser] = ISNULL(@{nameof(username)}, [DomainUser])
|
||||
OUTPUT [inserted].[MitarbeiterNr]
|
||||
WHERE [Vorname] = @{nameof(firstName)}
|
||||
AND [Name] = @{nameof(lastName)}
|
||||
AND [DomainUser] IS NULL")
|
||||
.SetParameter(nameof(employeeId), employeeId)
|
||||
.SetParameter(nameof(firstName), firstName)
|
||||
.SetParameter(nameof(lastName), lastName)
|
||||
.SetParameter(nameof(phone), phone)
|
||||
.SetParameter(nameof(username), username)
|
||||
.SetParameter(nameof(email), email)
|
||||
.ExecuteScalar(x => x.GetSmallint());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +96,20 @@
|
||||
.SetParameter(nameof(functionId), functionId)
|
||||
.FirstOrDefault(x => x.GetInt() > 0);
|
||||
|
||||
public IEnumerable<string> Find(string token)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
SELECT [SF].[Function]
|
||||
FROM [UsersFunctions] AS [UF]
|
||||
JOIN [SoftwareFunctions] AS [SF]
|
||||
ON [SF].[Id] = [UF].[SoftwareFunctionId]
|
||||
JOIN [MitarbeiterTokens] AS [MT]
|
||||
ON [MT].[UserId] = [UF].[UserId]
|
||||
AND [MT].[AppId] = [SF].[AppId]
|
||||
AND [MT].[Token] = @{nameof(token)}")
|
||||
.SetParameter(nameof(token), token)
|
||||
.ExecuteReader(x => x.GetString());
|
||||
|
||||
public void Insert(short employeeId, IEnumerable<string> functions)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
|
||||
+6
@@ -10,6 +10,8 @@
|
||||
|
||||
void CreateToken(short appId, short userId);
|
||||
|
||||
short EmployeeId(int employeeId);
|
||||
|
||||
short EmployeeId(string username, string password);
|
||||
|
||||
Employee Find(short employeeId);
|
||||
@@ -22,10 +24,14 @@
|
||||
|
||||
IEnumerable<string> GetUserRoles(string token);
|
||||
|
||||
short Insert(int employeeId, string firstName, string lastName, string phone, string username, string email);
|
||||
|
||||
void ResetPassword(short employeeId);
|
||||
|
||||
void ResetTokens(short employeeId);
|
||||
|
||||
void SetPassword(short employeeId, string password);
|
||||
|
||||
short Update(int employeeId, string firstName, string lastName, string phone, string username, string email);
|
||||
}
|
||||
}
|
||||
|
||||
+2
@@ -22,6 +22,8 @@
|
||||
|
||||
bool Exists(int softwareId, int functionId);
|
||||
|
||||
IEnumerable<string> Find(string token);
|
||||
|
||||
void Insert(short employeeId, IEnumerable<string> functions);
|
||||
|
||||
void UpdateFunction(int functionId, string function);
|
||||
|
||||
+4
@@ -21,8 +21,12 @@
|
||||
|
||||
IEnumerable<string> GetSoftwareFunctions(string token);
|
||||
|
||||
short Insert(string assembly, int major, int minor, int build);
|
||||
|
||||
IEnumerable<SoftwareItem> List();
|
||||
|
||||
short SoftwareId(string assembly, int major, int minor, int build);
|
||||
|
||||
IEnumerable<SoftwareVersion> Versions(short softwareId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,6 +121,31 @@
|
||||
.SetParameter(nameof(token), token)
|
||||
.ExecuteReader(x => x.GetString());
|
||||
|
||||
public short Insert(string assembly, int major, int minor, int build)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
INSERT INTO [VersionSoftwareAccess] (
|
||||
[SoftwareAccess_Program]
|
||||
, [SoftwareAccess_MajorVersion]
|
||||
, [SoftwareAccess_MinorVersion]
|
||||
, [SoftwareAccess_BuildVersion]
|
||||
, [SoftwareAccess_VaildTo]
|
||||
, [SoftwareAccess_Desc]
|
||||
, [AppID])
|
||||
OUTPUT [inserted].[AppId]
|
||||
VALUES (@{nameof(assembly)}
|
||||
, @{nameof(major)}
|
||||
, @{nameof(minor)}
|
||||
, @{nameof(build)}
|
||||
, GETDATE()
|
||||
, 'Automatically created on first use.'
|
||||
, (SELECT MAX([AppId]) + 1 FROM [VersionSoftwareAccess]))")
|
||||
.SetParameter(nameof(assembly), assembly)
|
||||
.SetParameter(nameof(major), major)
|
||||
.SetParameter(nameof(minor), minor)
|
||||
.SetParameter(nameof(build), build)
|
||||
.ExecuteScalar(x => x.GetSmallint());
|
||||
|
||||
public IEnumerable<SoftwareItem> List()
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
@@ -157,6 +182,22 @@
|
||||
Description = x.GetString(),
|
||||
});
|
||||
|
||||
public short SoftwareId(string assembly, int major, int minor, int build)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
SELECT [AppId]
|
||||
FROM [VersionSoftwareAccess]
|
||||
WHERE [SoftwareAccess_Program] = @{nameof(assembly)}
|
||||
AND [SoftwareAccess_MajorVersion] = @{nameof(major)}
|
||||
AND [SoftwareAccess_MinorVersion] = @{nameof(minor)}
|
||||
AND [SoftwareAccess_BuildVersion] = @{nameof(build)}
|
||||
AND [SoftwareAccess_VaildTo] > GETDATE()")
|
||||
.SetParameter(nameof(assembly), assembly)
|
||||
.SetParameter(nameof(major), major)
|
||||
.SetParameter(nameof(minor), minor)
|
||||
.SetParameter(nameof(build), build)
|
||||
.FirstOrDefault(x => x.GetSmallint());
|
||||
|
||||
public IEnumerable<SoftwareVersion> Versions(short softwareId)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
|
||||
@@ -32,8 +32,8 @@
|
||||
=> this.functionsRepository.All()
|
||||
?? Array.Empty<string>();
|
||||
|
||||
public IEnumerable<string> GetFunctions(short appId)
|
||||
=> this.functionsRepository.All(appId)
|
||||
public IEnumerable<string> GetFunctions(string token)
|
||||
=> this.functionsRepository.Find(token)
|
||||
?? Array.Empty<string>();
|
||||
|
||||
public IEnumerable<object> ListSoftwares()
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace LaaProduction.SharedModels
|
||||
{
|
||||
public class ADLoginModel
|
||||
{
|
||||
public string Assembly { get; set; }
|
||||
|
||||
public int MajorV { get; set; }
|
||||
|
||||
public int MinorV { get; set; }
|
||||
|
||||
public int BuildV { get; set; }
|
||||
|
||||
public int EmployeeId { get; set; }
|
||||
|
||||
public string FirstName { get; set; }
|
||||
|
||||
public string LastName { get; set; }
|
||||
|
||||
public string Username { get; set; }
|
||||
|
||||
public string Phone { get; set; }
|
||||
|
||||
public string Email { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?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>{0BF77588-2684-459D-8C71-DBBC6B05E9EE}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>LaaProduction.SharedModels</RootNamespace>
|
||||
<AssemblyName>LaaProduction.SharedModels</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject />
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ADLoginModel.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="UserLoginModel.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("LaaProduction.SharedModels")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("LaaProduction.SharedModels")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2023")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("0bf77588-2684-459d-8c71-dbbc6b05e9ee")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace LaaProduction.SharedModels
|
||||
{
|
||||
public class UserLoginModel
|
||||
{
|
||||
public string Assembly { get; set; }
|
||||
|
||||
public int MajorV { get; set; }
|
||||
|
||||
public int MinorV { get; set; }
|
||||
|
||||
public int BuildV { get; set; }
|
||||
|
||||
public string Username { get; set; }
|
||||
|
||||
public string Password { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web.Http;
|
||||
using System.Web.Http.ModelBinding;
|
||||
using System.Web.Http.Results;
|
||||
|
||||
internal static class APIExtensions
|
||||
{
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
namespace LaaProduction.Web.API
|
||||
{
|
||||
using LaaProduction.Personalization.Interfaces;
|
||||
using LaaProduction.SharedModels;
|
||||
using LaaProductionDI;
|
||||
|
||||
using System.Web.Http;
|
||||
|
||||
[AllowAnonymous]
|
||||
[RoutePrefix("API/Login")]
|
||||
public class LoginController : ApiController
|
||||
{
|
||||
private readonly IAccountManager accountManager;
|
||||
|
||||
public LoginController()
|
||||
=> this.accountManager = LaaServiceProvider.GetService<IAccountManager>();
|
||||
|
||||
[HttpPost]
|
||||
[Route(nameof(AD))]
|
||||
public IHttpActionResult AD([FromBody] ADLoginModel model)
|
||||
{
|
||||
var bearer = this.accountManager.Login(model);
|
||||
|
||||
return this.Json(bearer);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route(nameof(Local))]
|
||||
public IHttpActionResult Local([FromBody] UserLoginModel model)
|
||||
{
|
||||
var bearer = this.accountManager.Login(model);
|
||||
|
||||
return this.Json(bearer);
|
||||
}
|
||||
|
||||
// TODO: remove app id and use software version id instead.
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
namespace LaaProduction.Web.API.Account
|
||||
{
|
||||
using LaaProduction.Personalization.Interfaces;
|
||||
using LaaProductionDI;
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Web.Http;
|
||||
|
||||
[RoutePrefix("api/Personalization/Login")]
|
||||
public class LoginController : ApiController
|
||||
{
|
||||
private readonly IAccountManager accountManagement;
|
||||
|
||||
public LoginController()
|
||||
=> this.accountManagement = LaaServiceProvider.GetService<IAccountManager>();
|
||||
|
||||
[HttpPost]
|
||||
public IHttpActionResult Post(LoginPostModel model)
|
||||
{
|
||||
if (this.ModelState.IsValid)
|
||||
{
|
||||
var token = this.accountManagement.GetAuthToken(model.Username, model.Password, model.Software);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(token))
|
||||
{
|
||||
return this.Json(token);
|
||||
}
|
||||
|
||||
this.ModelState.AddModelError("Error", "Invalid username or password.");
|
||||
}
|
||||
|
||||
return this.BadRequest(this.ModelState);
|
||||
}
|
||||
}
|
||||
|
||||
public class LoginPostModel
|
||||
{
|
||||
[Required]
|
||||
public string Username { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Password { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Software { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,16 @@
|
||||
return this.Json(employeeRoles);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route(nameof(Access))]
|
||||
public IHttpActionResult Access()
|
||||
{
|
||||
var bearer = this.User.GetNameIdentifier();
|
||||
var functions = this.softwareManager.GetFunctions(bearer);
|
||||
|
||||
return this.Json(functions);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route(nameof(List))]
|
||||
public IHttpActionResult List()
|
||||
@@ -111,9 +121,10 @@
|
||||
[Route(nameof(Login))]
|
||||
public IHttpActionResult Login([FromBody] SoftwareLoginModel model)
|
||||
{
|
||||
var softwareId = this.softwareManager.Login(model.Software, model.Functions);
|
||||
// TODO: Implement
|
||||
//var softwareId = this.softwareManager.Login(model.Software, model.Functions);
|
||||
|
||||
return this.Json(softwareId);
|
||||
return this.Json(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,9 @@
|
||||
{
|
||||
var accountManager = LaaServiceProvider.GetService<IAccountManager>();
|
||||
var bearer = actionContext.Request.Headers.Authorization.Parameter;
|
||||
var principal = accountManager.GetClaimsPrincipal(bearer);
|
||||
var principal = accountManager.GetClaimsPrincipal(bearer.Trim('"'));
|
||||
|
||||
actionContext.RequestContext.Principal = principal;
|
||||
|
||||
return principal.Identity.IsAuthenticated;
|
||||
}
|
||||
|
||||
@@ -42,6 +42,11 @@
|
||||
name: "DefaultApi",
|
||||
routeTemplate: "api/{controller}/{id}",
|
||||
defaults: new { id = RouteParameter.Optional });
|
||||
|
||||
config.Routes.MapHttpRoute(
|
||||
name: "DefaultActionsApi",
|
||||
routeTemplate: "api/{controller}/{action}/{id}",
|
||||
defaults: new { id = RouteParameter.Optional });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-2
@@ -32,8 +32,6 @@
|
||||
|
||||
if (employeesResponse.Succeeded)
|
||||
{
|
||||
var count = employeesResponse.Value.Count(x => x.RolesCount > 0);
|
||||
|
||||
employeeysModel.Employees = employeesResponse.Value ?? Array.Empty<Employee>();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -22,6 +22,11 @@
|
||||
[HttpPost]
|
||||
public IHttpActionResult Post([FromBody] FunctionsPostInputModel model)
|
||||
{
|
||||
if (model is null)
|
||||
{
|
||||
return this.BadRequest();
|
||||
}
|
||||
|
||||
var userId = this.accountService.Login(model.Username, model.Password);
|
||||
|
||||
if (userId <= 0)
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
namespace LaaProduction.Web.Controllers.API
|
||||
{
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Http.ModelBinding;
|
||||
|
||||
internal static class APIExtensions
|
||||
{
|
||||
public static string Content(this ModelStateDictionary modelStateDictionary)
|
||||
{
|
||||
var errors = new Dictionary<string, string>();
|
||||
|
||||
foreach (var error in modelStateDictionary)
|
||||
{
|
||||
var errorKey = error
|
||||
.Key
|
||||
?.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries)
|
||||
?.LastOrDefault();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(errorKey))
|
||||
{
|
||||
var errorMessage = error
|
||||
.Value
|
||||
.Errors
|
||||
.FirstOrDefault()
|
||||
.ErrorMessage;
|
||||
|
||||
errors[errorKey] = errorMessage;
|
||||
}
|
||||
}
|
||||
|
||||
return JsonConvert.SerializeObject(errors, Formatting.Indented);
|
||||
}
|
||||
}
|
||||
}
|
||||
-122
@@ -1,122 +0,0 @@
|
||||
namespace LaaProduction.Web.Controllers.API.Personalization
|
||||
{
|
||||
using LaaProduction.Personalization.Interfaces;
|
||||
using LaaProduction.Web.App_Infrastructure;
|
||||
using LaaProductionDI;
|
||||
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Web.Http;
|
||||
|
||||
[AuthorizeBearer]
|
||||
[RoutePrefix("api/Personalization/Employees")]
|
||||
public class EmployeesController : ApiController
|
||||
{
|
||||
private readonly IAccountManager accountManager;
|
||||
private readonly IEmployeesManager employeesManager;
|
||||
|
||||
public EmployeesController()
|
||||
{
|
||||
this.accountManager = LaaServiceProvider.GetService<IAccountManager>();
|
||||
this.employeesManager = LaaServiceProvider.GetService<IEmployeesManager>();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IHttpActionResult Get()
|
||||
{
|
||||
var employees = this.employeesManager.GetEmployees();
|
||||
|
||||
return this.Json(employees);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IHttpActionResult Find(short id)
|
||||
{
|
||||
var employee = this.employeesManager.GetEmployee(id);
|
||||
|
||||
return this.Json(employee);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route(nameof(EditRoles))]
|
||||
public IHttpActionResult EditRoles([FromBody] EditRolesModel model)
|
||||
{
|
||||
if (this.ModelState.IsValid)
|
||||
{
|
||||
this.employeesManager.UpdateEmployeeRoles(model.EmployeeId.Value, model.Roles);
|
||||
}
|
||||
|
||||
return this.Json(true);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route(nameof(EditFunctions))]
|
||||
public IHttpActionResult EditFunctions([FromBody] EditFunctionsModel model)
|
||||
{
|
||||
if (this.ModelState.IsValid)
|
||||
{
|
||||
this.employeesManager.UpdateEmployeeFunctions(model.EmployeeId.Value, model.Functions);
|
||||
}
|
||||
|
||||
return this.Json(true);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("ResetPassword/{id}")]
|
||||
public IHttpActionResult ResetPassword(short id)
|
||||
{
|
||||
if (this.ModelState.IsValid)
|
||||
{
|
||||
this.accountManager.ResetPassword(id);
|
||||
}
|
||||
|
||||
return this.Json(true);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route(nameof(SetPassword))]
|
||||
public IHttpActionResult SetPassword(PasswordModel model)
|
||||
{
|
||||
if (this.ModelState.IsValid)
|
||||
{
|
||||
this.accountManager.SetPassword(model.EmployeeId.Value, model.Password);
|
||||
}
|
||||
|
||||
return this.Json(true);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route(nameof(List))]
|
||||
public IHttpActionResult List()
|
||||
{
|
||||
var employees = this.employeesManager.ListEmployees();
|
||||
|
||||
return this.Json(employees);
|
||||
}
|
||||
}
|
||||
|
||||
public class EditRolesModel
|
||||
{
|
||||
[Required]
|
||||
public short? EmployeeId { get; set; }
|
||||
|
||||
public string[] Roles { get; set; } = Array.Empty<string>();
|
||||
}
|
||||
|
||||
public class EditFunctionsModel
|
||||
{
|
||||
[Required]
|
||||
public short? EmployeeId { get; set; }
|
||||
|
||||
public string[] Functions { get; set; } = Array.Empty<string>();
|
||||
}
|
||||
|
||||
public class PasswordModel
|
||||
{
|
||||
[Required]
|
||||
public short? EmployeeId { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Password { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
namespace LaaProduction.Web.Controllers.API.Account
|
||||
{
|
||||
using LaaProduction.Personalization.Interfaces;
|
||||
using LaaProductionDI;
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Web.Http;
|
||||
|
||||
[RoutePrefix("api/Personalization/Login")]
|
||||
public class LoginController : ApiController
|
||||
{
|
||||
private readonly IAccountManager accountManagement;
|
||||
|
||||
public LoginController()
|
||||
=> this.accountManagement = LaaServiceProvider.GetService<IAccountManager>();
|
||||
|
||||
[HttpPost]
|
||||
public IHttpActionResult Post(LoginPostModel model)
|
||||
{
|
||||
if (this.ModelState.IsValid)
|
||||
{
|
||||
var token = this.accountManagement.GetAuthToken(model.Username, model.Password, model.Software);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(token))
|
||||
{
|
||||
return this.Json(token);
|
||||
}
|
||||
|
||||
this.ModelState.AddModelError("Error", "Invalid username or password.");
|
||||
}
|
||||
|
||||
return this.BadRequest(this.ModelState);
|
||||
}
|
||||
}
|
||||
|
||||
public class LoginPostModel
|
||||
{
|
||||
[Required]
|
||||
public string Username { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Password { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Software { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
namespace LaaProduction.Web.Controllers.API.Personalization
|
||||
{
|
||||
using LaaProduction.Personalization.Interfaces;
|
||||
using LaaProduction.Web.App_Infrastructure;
|
||||
using LaaProductionDI;
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Web.Http;
|
||||
|
||||
[AuthorizeBearer]
|
||||
[RoutePrefix("api/Personalization/Roles")]
|
||||
public class RolesController : ApiController
|
||||
{
|
||||
private readonly IEmployeesManager employeesManager;
|
||||
|
||||
public RolesController()
|
||||
=> this.employeesManager = LaaServiceProvider.GetService<IEmployeesManager>();
|
||||
|
||||
[HttpGet]
|
||||
public IHttpActionResult Get()
|
||||
{
|
||||
var employeeRoles = this.employeesManager
|
||||
.GetRoles()
|
||||
.ToList();
|
||||
|
||||
return this.Json(employeeRoles);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IHttpActionResult Find(short id)
|
||||
{
|
||||
var employeeRoles = this.employeesManager.GetRoles(id);
|
||||
|
||||
return this.Json(employeeRoles);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route(nameof(Update))]
|
||||
public IHttpActionResult Update([FromBody] RoleUpdateModel model)
|
||||
{
|
||||
if (this.ModelState.IsValid)
|
||||
{
|
||||
this.employeesManager.UpdateRoleEmployees(model.Role, model.Employees);
|
||||
}
|
||||
|
||||
return this.Json(true);
|
||||
}
|
||||
}
|
||||
|
||||
public class RoleUpdateModel
|
||||
{
|
||||
[Required]
|
||||
public string Role { get; set; }
|
||||
|
||||
public short[] Employees { get; set; }
|
||||
}
|
||||
}
|
||||
-151
@@ -1,151 +0,0 @@
|
||||
namespace LaaProduction.Web.Controllers.API.Personalization
|
||||
{
|
||||
using LaaProduction.Personalization.Interfaces;
|
||||
using LaaProduction.Web.App_Infrastructure;
|
||||
using LaaProductionDI;
|
||||
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Web.Http;
|
||||
|
||||
[AuthorizeBearer]
|
||||
[RoutePrefix("api/Personalization/Software")]
|
||||
public class SoftwareController : ApiController
|
||||
{
|
||||
private readonly ISoftwareManager softwareManager;
|
||||
|
||||
public SoftwareController()
|
||||
=> this.softwareManager = LaaServiceProvider.GetService<ISoftwareManager>();
|
||||
|
||||
[HttpGet]
|
||||
[Route(nameof(Functions))]
|
||||
public IHttpActionResult Functions()
|
||||
{
|
||||
var employeeRoles = this.softwareManager.GetFunctions();
|
||||
|
||||
return this.Json(employeeRoles);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route(nameof(List))]
|
||||
public IHttpActionResult List()
|
||||
{
|
||||
var softwares = this.softwareManager.ListSoftwares();
|
||||
|
||||
return this.Json(softwares);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("Version/{id}")]
|
||||
public IHttpActionResult Version(int id)
|
||||
{
|
||||
var software = this.softwareManager.SoftwareDeteils(id);
|
||||
|
||||
return this.Json(software);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route(nameof(EditFunction))]
|
||||
public IHttpActionResult EditFunction([FromBody] EditFunctionModel model)
|
||||
{
|
||||
if (this.ModelState.IsValid)
|
||||
{
|
||||
this.softwareManager.UpdateFunction(
|
||||
model.SoftwareId.Value,
|
||||
model.FunctionId,
|
||||
model.Function,
|
||||
model.Employees);
|
||||
}
|
||||
|
||||
return this.Json(true);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route(nameof(AddVersion))]
|
||||
public IHttpActionResult AddVersion([FromBody] SoftwareAddModel model)
|
||||
{
|
||||
if (this.ModelState.IsValid)
|
||||
{
|
||||
this.softwareManager.AddVersion(
|
||||
model.SoftwareId.Value,
|
||||
model.AssemblyName,
|
||||
model.MajorV,
|
||||
model.MinorV,
|
||||
model.BuildV,
|
||||
model.ValidUntil.Value,
|
||||
model.Description);
|
||||
}
|
||||
|
||||
return this.Json(true);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route(nameof(EditVersion))]
|
||||
public IHttpActionResult EditVersion([FromBody] SoftwareEditModel model)
|
||||
{
|
||||
if (this.ModelState.IsValid)
|
||||
{
|
||||
this.softwareManager.EditVersion(
|
||||
model.VersionId.Value,
|
||||
model.ValidUntil,
|
||||
model.Description);
|
||||
}
|
||||
|
||||
return this.Json(true);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("DeleteVersion/{id}")]
|
||||
public IHttpActionResult DeleteVersion(int id)
|
||||
{
|
||||
if (this.ModelState.IsValid)
|
||||
{
|
||||
this.softwareManager.DeleteVersion(id);
|
||||
}
|
||||
|
||||
return this.Json(true);
|
||||
}
|
||||
}
|
||||
|
||||
public class EditFunctionModel
|
||||
{
|
||||
[Required]
|
||||
public short? SoftwareId { get; set; }
|
||||
|
||||
public int FunctionId { get; set; }
|
||||
|
||||
public string Function { get; set; }
|
||||
|
||||
public short[] Employees { get; set; }
|
||||
}
|
||||
|
||||
public class SoftwareAddModel
|
||||
{
|
||||
[Required]
|
||||
public short? SoftwareId { get; set; }
|
||||
|
||||
[Required]
|
||||
public string AssemblyName { get; set; }
|
||||
|
||||
public int MajorV { get; set; }
|
||||
|
||||
public int MinorV { get; set; }
|
||||
|
||||
public int BuildV { get; set; }
|
||||
|
||||
[Required]
|
||||
public DateTime? ValidUntil { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
}
|
||||
|
||||
public class SoftwareEditModel
|
||||
{
|
||||
[Required]
|
||||
public short? VersionId { get; set; }
|
||||
|
||||
public DateTime? ValidUntil { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
Laa Production API
|
||||
---
|
||||
|
||||
1. **Base address** - http://sla12iis01.emea.sensus.net
|
||||
|
||||
1. **Authentication & Authorization** - each user has his own set of roles and allowed functions to access within his employee account's. Authentication succeeds over username, password and software name.
|
||||
|
||||
1. **POST: /LaaProductionWeb/api/personalization/login** - in order to authenticate particular user and obtain an authorization token. Use following parameters in the request body in json format:
|
||||
- **Username** - required string. Should match a username saved in the database.
|
||||
- **Password** - required hash string. Should match the password hash for the above entered username.
|
||||
- **Software** - required string. As software name, use the assembly name that calls this API.
|
||||
- if authentication succeeds you will receive in response a string **{token}** that should be used for further authorization otherwise error message is received.
|
||||
|
||||
1. **Authorization: Bearer {token}** - is the scheme to use within the authorization and further API calls on all other routes.
|
||||
|
||||
1. **Wildcard search:**
|
||||
|
||||
1. **GET: /LaaProductionWeb/api/search/wildcard** - returns a list of possible fields to return when searching. Default are all fields returned to the client.
|
||||
|
||||
1. **POST: /LaaProductionWeb/api/search/wildcard** - returns a list of found results. Within the searching you should use following parameters in the request body in json format:
|
||||
- **Token** - search string. Requires from 3 up to 50 - letters, digits and or (" ", "-") charachters.
|
||||
- **Fields** - optional. List of fields to return.
|
||||
@@ -1,80 +0,0 @@
|
||||
namespace LaaProduction.Web.Controllers.API.Search
|
||||
{
|
||||
using LaaProduction.Search;
|
||||
using LaaProduction.Web.App_Infrastructure;
|
||||
using LaaProductionDI;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Web.Http;
|
||||
|
||||
[AuthorizeBearer]
|
||||
[RoutePrefix("api/Search/Wildcard")]
|
||||
public class WildcardController : ApiController
|
||||
{
|
||||
private readonly ISearchManager searchManager;
|
||||
|
||||
public WildcardController()
|
||||
=> this.searchManager = LaaServiceProvider.GetService<ISearchManager>();
|
||||
|
||||
[HttpGet]
|
||||
public IHttpActionResult Get()
|
||||
{
|
||||
var fields = this.searchManager.WildcardFields();
|
||||
|
||||
return this.Json(fields);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IHttpActionResult Post([FromBody] WildcardSearchModel model)
|
||||
{
|
||||
IEnumerable<IDictionary<string, object>> results = Array.Empty<IDictionary<string, object>>();
|
||||
|
||||
if (this.ModelState.IsValid)
|
||||
{
|
||||
results = this.searchManager.SearchWildcard(model.Token, model.SelectedFields);
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.ResponseMessage(new HttpResponseMessage
|
||||
{
|
||||
Content = new StringContent(this.ModelState.Content()),
|
||||
RequestMessage = this.Request,
|
||||
StatusCode = HttpStatusCode.BadRequest,
|
||||
Version = this.Request.Version
|
||||
});
|
||||
}
|
||||
|
||||
return this.Json(results);
|
||||
}
|
||||
}
|
||||
|
||||
public class WildcardSearchModel
|
||||
{
|
||||
[Required]
|
||||
[StringLength(50, MinimumLength = 3)]
|
||||
[RegularExpression("^[0-9 a-z-A-Z]+$")]
|
||||
public string Token { get; set; }
|
||||
|
||||
public string Fields { get; set; }
|
||||
|
||||
internal IEnumerable<string> SelectedFields
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(this.Fields))
|
||||
{
|
||||
return Array.Empty<string>();
|
||||
}
|
||||
|
||||
return WebUtility
|
||||
.UrlDecode(this.Fields)
|
||||
?.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
|
||||
?? Array.Empty<string>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,12 +41,15 @@
|
||||
|
||||
var software = typeof(HomeController)
|
||||
.Assembly
|
||||
.GetName()
|
||||
.Name;
|
||||
.GetName();
|
||||
var assembly = software.Name;
|
||||
var majorV = software.Version.Major;
|
||||
var minorV = software.Version.Minor;
|
||||
var buildV = software.Version.Build;
|
||||
|
||||
var token = await this.httpClient
|
||||
.Post("/Personalization/Login")
|
||||
.WhitJsonBody(new { username, password, software })
|
||||
.Post("/Login/Local")
|
||||
.WhitJsonBody(new { username, password, assembly, majorV, minorV, buildV })
|
||||
.SendAsync<string>();
|
||||
|
||||
if (!token.Succeeded)
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
namespace LaaProduction.Web.Controllers
|
||||
{
|
||||
using System.Web.Http;
|
||||
using System.Web.Http.Results;
|
||||
|
||||
public class ValuesController : ApiController
|
||||
{
|
||||
// GET api/values
|
||||
public JsonResult<string[]> Get()
|
||||
{
|
||||
return this.Json(new string[] { "value1", "value2" });
|
||||
}
|
||||
|
||||
// GET api/values/5
|
||||
public string Get(int id)
|
||||
{
|
||||
return "value";
|
||||
}
|
||||
|
||||
// POST api/values
|
||||
public void Post([FromBody]string value)
|
||||
{
|
||||
}
|
||||
|
||||
// PUT api/values/5
|
||||
public void Put(int id, [FromBody]string value)
|
||||
{
|
||||
}
|
||||
|
||||
// DELETE api/values/5
|
||||
public void Delete(int id)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -140,6 +140,12 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="API\APIExtensions.cs" />
|
||||
<Compile Include="API\LoginController.cs" />
|
||||
<Compile Include="API\Personalization\EmployeesController.cs" />
|
||||
<Compile Include="API\Personalization\RolesController.cs" />
|
||||
<Compile Include="API\Personalization\SoftwareController.cs" />
|
||||
<Compile Include="API\Search\WildcardController.cs" />
|
||||
<Compile Include="App_Infrastructure\AllowedRolesAttribute.cs" />
|
||||
<Compile Include="App_Infrastructure\Appsettings.cs" />
|
||||
<Compile Include="App_Infrastructure\AuthorizationFilter.cs" />
|
||||
@@ -176,12 +182,6 @@
|
||||
<Compile Include="Areas\Software\Controllers\AppIdController.cs" />
|
||||
<Compile Include="Areas\Software\Controllers\FunctionsController.cs" />
|
||||
<Compile Include="Areas\Software\SoftwareAreaRegistration.cs" />
|
||||
<Compile Include="Controllers\API\APIExtensions.cs" />
|
||||
<Compile Include="Controllers\API\Personalization\EmployeesController.cs" />
|
||||
<Compile Include="Controllers\API\Personalization\LoginController.cs" />
|
||||
<Compile Include="Controllers\API\Personalization\RolesController.cs" />
|
||||
<Compile Include="Controllers\API\Personalization\SoftwareController.cs" />
|
||||
<Compile Include="Controllers\API\Search\WildcardController.cs" />
|
||||
<Compile Include="Controllers\ApprovalsController.cs" />
|
||||
<Compile Include="Controllers\EmailController.cs" />
|
||||
<Compile Include="Controllers\HomeController.cs" />
|
||||
@@ -228,8 +228,8 @@
|
||||
<Content Include="Areas\Personalization\Views\web.config">
|
||||
<SubType>Designer</SubType>
|
||||
</Content>
|
||||
<Content Include="Controllers\API\README.md" />
|
||||
<Content Include="Areas\Personalization\Views\Software\Details.cshtml" />
|
||||
<Content Include="API\README.md" />
|
||||
<None Include="packages.config" />
|
||||
<Content Include="Views\_ViewStart.cshtml" />
|
||||
<Content Include="Views\Approvals\Add.cshtml" />
|
||||
@@ -277,6 +277,10 @@
|
||||
<Project>{ff167011-431a-41a7-a7db-560e08860388}</Project>
|
||||
<Name>LaaProduction.Services</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\LaaProduction.SharedModels\LaaProduction.SharedModels.csproj">
|
||||
<Project>{0BF77588-2684-459D-8C71-DBBC6B05E9EE}</Project>
|
||||
<Name>LaaProduction.SharedModels</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\LaaProduction.Shipment\LaaProduction.Shipment.csproj">
|
||||
<Project>{a487e02b-0e6c-4a98-84f6-4af3e7b8e73b}</Project>
|
||||
<Name>LaaProduction.Shipment</Name>
|
||||
|
||||
@@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LaaProduction.Web", "LaaPro
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LaaProduction.Personalization.Updater", "LaaProduction.Personalization.Updater\LaaProduction.Personalization.Updater.csproj", "{4B7F1659-2A57-414C-A192-FA0A822B6612}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LaaProduction.SharedModels", "LaaProduction.SharedModels\LaaProduction.SharedModels.csproj", "{0BF77588-2684-459D-8C71-DBBC6B05E9EE}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -45,6 +47,10 @@ Global
|
||||
{4B7F1659-2A57-414C-A192-FA0A822B6612}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4B7F1659-2A57-414C-A192-FA0A822B6612}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4B7F1659-2A57-414C-A192-FA0A822B6612}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0BF77588-2684-459D-8C71-DBBC6B05E9EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0BF77588-2684-459D-8C71-DBBC6B05E9EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0BF77588-2684-459D-8C71-DBBC6B05E9EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0BF77588-2684-459D-8C71-DBBC6B05E9EE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
Reference in New Issue
Block a user