Current user's name shown instead Options

This commit is contained in:
Stoyan Zlatev
2023-06-27 13:26:31 +02:00
parent 80c1b9838c
commit 1710ad2bbd
8 changed files with 71 additions and 290 deletions
@@ -17,7 +17,9 @@
private static string bearer;
private static IEnumerable<SoftwareFunctions> softwareFunctions = Array.Empty<SoftwareFunctions>();
public static Boolean HasUser => !string.IsNullOrWhiteSpace(bearer);
public static string UserName;
public static bool HasUser => !string.IsNullOrWhiteSpace(bearer);
public static void Initialize()
{
@@ -48,9 +50,15 @@
var authenticationResponse = LocalWebRequest.PostRequestAndGetResponseAsync(
url: $"{ServiceUrls.LaaProductionAPI}/LaaProductionWeb/API/Login/AD",
json: model);
bearer = authenticationResponse.Content;
softwareFunctions = GetFunctions();
UserName = "Options";
if (HasUser)
{
UserName = $"{model.FirstName} {model.LastName}";
}
}
/// <summary>
@@ -72,6 +80,24 @@
bearer = authenticationResponse.Content;
softwareFunctions = GetFunctions();
UserName = "Options";
if (HasUser)
{
try
{
UserName = LocalWebRequest
.GetRequest(
timeoutMs: 1200,
url: $"{ServiceUrls.LaaProductionAPI}/LaaProductionWeb/API/Personalization/Login",
header: new Dictionary<string, string> { { "Authorization", $"Bearer {bearer}" } })
.Trim('"');
}
catch (Exception e)
{
}
}
return HasUser;
}
@@ -108,8 +134,11 @@
public static void Logout()
{
UserName = "Options";
bearer = default(string);
softwareFunctions = Array.Empty<SoftwareFunctions>();
Initialize();
}
}
}
+17 -17
View File
@@ -51,8 +51,8 @@
this.btnFiles = new System.Windows.Forms.Button();
this.btnLegacyTestApp = new System.Windows.Forms.Button();
this.menu = new System.Windows.Forms.MenuStrip();
this.loginToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.loginToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.optionsMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.loginMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.logoutMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.gpGerneral.SuspendLayout();
this.gpLAA.SuspendLayout();
@@ -323,29 +323,29 @@
//
this.menu.AutoSize = false;
this.menu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.loginToolStripMenuItem});
this.optionsMenuItem});
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
// optionsMenuItem
//
this.loginToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.loginToolStripMenuItem1,
this.optionsMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.loginMenuItem,
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;
this.optionsMenuItem.Name = "optionsMenuItem";
this.optionsMenuItem.Size = new System.Drawing.Size(61, 20);
this.optionsMenuItem.Text = "Options";
this.optionsMenuItem.TextDirection = System.Windows.Forms.ToolStripTextDirection.Horizontal;
//
// loginToolStripMenuItem1
// loginMenuItem
//
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);
this.loginMenuItem.Name = "loginMenuItem";
this.loginMenuItem.Size = new System.Drawing.Size(180, 22);
this.loginMenuItem.Text = "Login";
this.loginMenuItem.Click += new System.EventHandler(this.OnLoginClick);
//
// logoutMenuItem
//
@@ -407,8 +407,8 @@
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 optionsMenuItem;
private System.Windows.Forms.ToolStripMenuItem loginMenuItem;
private System.Windows.Forms.ToolStripMenuItem logoutMenuItem;
}
}
+6 -1
View File
@@ -25,6 +25,7 @@
this.InitializeComponent();
this.InitializeFormState();
this.optionsMenuItem.Text = Software.UserName;
this.Text = $"{this.Text} {SoftwareVersion.Current.VersionString}";
var logger = NLogHelper.CreateOrGetLogger("GenesisToolBox");
logger.Info($"GenesisToolBox {SoftwareVersion.Current}");
@@ -461,6 +462,8 @@
groupBox.Show();
}
}
this.optionsMenuItem.Text = Software.UserName;
}
/// <summary>
@@ -527,7 +530,9 @@
{
this.Controls.Remove(loginForm);
this.ShowAvailableSoftwareFunctions();
this.Update();
this.optionsMenuItem.Text = Software.UserName;
}
else
{