diff --git a/Common/.shared/SharedAssemblyInfo.cs b/Common/.shared/SharedAssemblyInfo.cs index b198312b..62f0cb85 100644 --- a/Common/.shared/SharedAssemblyInfo.cs +++ b/Common/.shared/SharedAssemblyInfo.cs @@ -14,5 +14,5 @@ using System.Reflection; //[assembly: AssemblyVersion("1.2.*.0")] -[assembly: AssemblyVersion("2.6.8.*")] -[assembly: AssemblyFileVersion("2.6.8.0")] \ No newline at end of file +[assembly: AssemblyVersion("2.6.7.*")] +[assembly: AssemblyFileVersion("2.6.7.0")] \ No newline at end of file diff --git a/Common/CommonCore.Configuration/ServiceUrls.cs b/Common/CommonCore.Configuration/ServiceUrls.cs index 84e92c5c..a666069a 100644 --- a/Common/CommonCore.Configuration/ServiceUrls.cs +++ b/Common/CommonCore.Configuration/ServiceUrls.cs @@ -200,7 +200,7 @@ namespace Xylem.Common.CommonCore.Configuration = "http://sla12iis01.emea.sensus.net/MeterProcessState/api/CordonelPressureSensorTest/GetTestResults/{0}"; public const string LaaProductionAPI -#if DEBUG //== false // when false uses always the production url. +#if DEBUG == false // when false uses always the production url. = "http://localhost:52822"; #else = "http://sla12iis01.emea.sensus.net"; diff --git a/Common/Ui/GenesisToolBox/Ctls/ChangePassword.Designer.cs b/Common/Ui/GenesisToolBox/Ctls/ChangePassword.Designer.cs index e6da76fc..c83b9aca 100644 --- a/Common/Ui/GenesisToolBox/Ctls/ChangePassword.Designer.cs +++ b/Common/Ui/GenesisToolBox/Ctls/ChangePassword.Designer.cs @@ -38,8 +38,8 @@ this.confirmPassword = new System.Windows.Forms.TextBox(); this.submitBtn = new System.Windows.Forms.Button(); this.cancelBtn = new System.Windows.Forms.Button(); - this.ChangePasswordErrorProvider = new System.Windows.Forms.ErrorProvider(this.components); this.errorLbl = new System.Windows.Forms.Label(); + this.ChangePasswordErrorProvider = new System.Windows.Forms.ErrorProvider(this.components); this.layout.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.ChangePasswordErrorProvider)).BeginInit(); this.SuspendLayout(); @@ -48,9 +48,9 @@ // this.layout.AutoSize = true; this.layout.ColumnCount = 3; - this.layout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 18.75F)); - this.layout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 62.5F)); - this.layout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 18.75F)); + this.layout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 16.66667F)); + this.layout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 66.66666F)); + this.layout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 16.66667F)); this.layout.Controls.Add(this.oldPasswordLbl, 1, 1); this.layout.Controls.Add(this.newPasswordLbl, 1, 4); this.layout.Controls.Add(this.confirmPasswordLbl, 1, 7); @@ -68,17 +68,17 @@ this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 10F)); + this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 5F)); this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 10F)); + this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 5F)); this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 10F)); this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 10F)); this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.layout.Size = new System.Drawing.Size(413, 584); this.layout.TabIndex = 0; @@ -88,10 +88,10 @@ this.oldPasswordLbl.AutoSize = true; this.oldPasswordLbl.Dock = System.Windows.Forms.DockStyle.Fill; this.oldPasswordLbl.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.oldPasswordLbl.Location = new System.Drawing.Point(77, 178); + this.oldPasswordLbl.Location = new System.Drawing.Point(68, 185); this.oldPasswordLbl.Margin = new System.Windows.Forms.Padding(0); this.oldPasswordLbl.Name = "oldPasswordLbl"; - this.oldPasswordLbl.Size = new System.Drawing.Size(258, 15); + this.oldPasswordLbl.Size = new System.Drawing.Size(275, 15); this.oldPasswordLbl.TabIndex = 0; this.oldPasswordLbl.Text = "Old password"; this.oldPasswordLbl.TextAlign = System.Drawing.ContentAlignment.BottomLeft; @@ -101,10 +101,10 @@ this.newPasswordLbl.AutoSize = true; this.newPasswordLbl.Dock = System.Windows.Forms.DockStyle.Fill; this.newPasswordLbl.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.newPasswordLbl.Location = new System.Drawing.Point(77, 226); + this.newPasswordLbl.Location = new System.Drawing.Point(68, 228); this.newPasswordLbl.Margin = new System.Windows.Forms.Padding(0); this.newPasswordLbl.Name = "newPasswordLbl"; - this.newPasswordLbl.Size = new System.Drawing.Size(258, 15); + this.newPasswordLbl.Size = new System.Drawing.Size(275, 15); this.newPasswordLbl.TabIndex = 1; this.newPasswordLbl.Text = "New password"; this.newPasswordLbl.TextAlign = System.Drawing.ContentAlignment.BottomLeft; @@ -114,10 +114,10 @@ this.confirmPasswordLbl.AutoSize = true; this.confirmPasswordLbl.Dock = System.Windows.Forms.DockStyle.Fill; this.confirmPasswordLbl.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.confirmPasswordLbl.Location = new System.Drawing.Point(77, 274); + this.confirmPasswordLbl.Location = new System.Drawing.Point(68, 271); this.confirmPasswordLbl.Margin = new System.Windows.Forms.Padding(0); this.confirmPasswordLbl.Name = "confirmPasswordLbl"; - this.confirmPasswordLbl.Size = new System.Drawing.Size(258, 15); + this.confirmPasswordLbl.Size = new System.Drawing.Size(275, 15); this.confirmPasswordLbl.TabIndex = 2; this.confirmPasswordLbl.Text = "Confirm password"; this.confirmPasswordLbl.TextAlign = System.Drawing.ContentAlignment.BottomLeft; @@ -126,10 +126,10 @@ // this.oldPassword.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.oldPassword.Dock = System.Windows.Forms.DockStyle.Fill; - this.oldPassword.Location = new System.Drawing.Point(80, 193); + this.oldPassword.Location = new System.Drawing.Point(71, 200); this.oldPassword.Margin = new System.Windows.Forms.Padding(3, 0, 0, 0); this.oldPassword.Name = "oldPassword"; - this.oldPassword.Size = new System.Drawing.Size(255, 23); + this.oldPassword.Size = new System.Drawing.Size(272, 23); this.oldPassword.TabIndex = 3; this.oldPassword.UseSystemPasswordChar = true; // @@ -137,10 +137,10 @@ // this.newPassword.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.newPassword.Dock = System.Windows.Forms.DockStyle.Fill; - this.newPassword.Location = new System.Drawing.Point(80, 241); + this.newPassword.Location = new System.Drawing.Point(71, 243); this.newPassword.Margin = new System.Windows.Forms.Padding(3, 0, 0, 0); this.newPassword.Name = "newPassword"; - this.newPassword.Size = new System.Drawing.Size(255, 23); + this.newPassword.Size = new System.Drawing.Size(272, 23); this.newPassword.TabIndex = 4; this.newPassword.UseSystemPasswordChar = true; // @@ -148,10 +148,10 @@ // this.confirmPassword.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.confirmPassword.Dock = System.Windows.Forms.DockStyle.Fill; - this.confirmPassword.Location = new System.Drawing.Point(80, 289); + this.confirmPassword.Location = new System.Drawing.Point(71, 286); this.confirmPassword.Margin = new System.Windows.Forms.Padding(3, 0, 0, 0); this.confirmPassword.Name = "confirmPassword"; - this.confirmPassword.Size = new System.Drawing.Size(255, 23); + this.confirmPassword.Size = new System.Drawing.Size(272, 23); this.confirmPassword.TabIndex = 5; this.confirmPassword.UseSystemPasswordChar = true; // @@ -160,11 +160,10 @@ this.submitBtn.AutoSize = true; this.submitBtn.Cursor = System.Windows.Forms.Cursors.Hand; this.submitBtn.Dock = System.Windows.Forms.DockStyle.Fill; - this.submitBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.submitBtn.Location = new System.Drawing.Point(80, 322); + this.submitBtn.Location = new System.Drawing.Point(71, 319); this.submitBtn.Margin = new System.Windows.Forms.Padding(3, 0, 0, 0); this.submitBtn.Name = "submitBtn"; - this.submitBtn.Size = new System.Drawing.Size(255, 27); + this.submitBtn.Size = new System.Drawing.Size(272, 27); this.submitBtn.TabIndex = 6; this.submitBtn.Text = "Change password"; this.submitBtn.UseVisualStyleBackColor = true; @@ -175,18 +174,14 @@ this.cancelBtn.AutoSize = true; this.cancelBtn.Cursor = System.Windows.Forms.Cursors.Hand; this.cancelBtn.Dock = System.Windows.Forms.DockStyle.Fill; - this.cancelBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.cancelBtn.Location = new System.Drawing.Point(80, 359); + this.cancelBtn.Location = new System.Drawing.Point(71, 356); this.cancelBtn.Margin = new System.Windows.Forms.Padding(3, 0, 0, 0); this.cancelBtn.Name = "cancelBtn"; - this.cancelBtn.Size = new System.Drawing.Size(255, 27); + this.cancelBtn.Size = new System.Drawing.Size(272, 27); this.cancelBtn.TabIndex = 7; this.cancelBtn.Text = "Cancel"; this.cancelBtn.UseVisualStyleBackColor = true; - // - // ChangePasswordErrorProvider - // - this.ChangePasswordErrorProvider.ContainerControl = this; + this.cancelBtn.Click += new System.EventHandler(this.OnCancellationClick); // // errorLbl // @@ -194,13 +189,17 @@ this.errorLbl.Dock = System.Windows.Forms.DockStyle.Fill; this.errorLbl.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.errorLbl.ForeColor = System.Drawing.Color.Firebrick; - this.errorLbl.Location = new System.Drawing.Point(77, 386); + this.errorLbl.Location = new System.Drawing.Point(68, 383); this.errorLbl.Margin = new System.Windows.Forms.Padding(0); this.errorLbl.Name = "errorLbl"; - this.errorLbl.Size = new System.Drawing.Size(258, 20); + this.errorLbl.Size = new System.Drawing.Size(275, 15); this.errorLbl.TabIndex = 8; this.errorLbl.TextAlign = System.Drawing.ContentAlignment.BottomLeft; // + // ChangePasswordErrorProvider + // + this.ChangePasswordErrorProvider.ContainerControl = this; + // // ChangePassword // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); diff --git a/Common/Ui/GenesisToolBox/Ctls/ChangePassword.cs b/Common/Ui/GenesisToolBox/Ctls/ChangePassword.cs index d90ceb64..5aab22e9 100644 --- a/Common/Ui/GenesisToolBox/Ctls/ChangePassword.cs +++ b/Common/Ui/GenesisToolBox/Ctls/ChangePassword.cs @@ -6,9 +6,9 @@ using Xylem.Common.Ui.GenesisToolBox.Infrastructure; - public partial class ChangePassword : UserControl + public partial class ChangePassword : UserControl, IIdentityForm { - private readonly Action changePasswordSubmitted; + private readonly Action closeOnSuccessOrCancel; private readonly IDictionary fields; public ChangePassword() @@ -18,9 +18,9 @@ this.Dock = DockStyle.Fill; } - public ChangePassword(Action resetPasswordSubmitted) : this() + public ChangePassword(Action closeOnSuccess) : this() { - this.changePasswordSubmitted = resetPasswordSubmitted; + this.closeOnSuccessOrCancel = closeOnSuccess; this.fields = new Dictionary { @@ -30,17 +30,17 @@ }; } - public event Action OnCancellation; - private void OnCancellationClick(Object sender, EventArgs args) { - this.OnCancellation?.Invoke(this); + this.closeOnSuccessOrCancel?.Invoke(this); } private void OnFormSubmittedClick(Object sender, EventArgs args) { this.ChangePasswordErrorProvider.Clear(); + this.errorLbl.Text = default(string); + if (!Software.ChangePassword(this.oldPassword.Text, this.newPassword.Text, this.confirmPassword.Text, out var errors)) { this.errorLbl.Text = "Password change failed."; @@ -55,7 +55,7 @@ } else { - this.changePasswordSubmitted?.Invoke(this); + this.closeOnSuccessOrCancel?.Invoke(this); } } } diff --git a/Common/Ui/GenesisToolBox/Ctls/LoginForm.Designer.cs b/Common/Ui/GenesisToolBox/Ctls/LoginForm.Designer.cs index 2bc98d2d..2035e032 100644 --- a/Common/Ui/GenesisToolBox/Ctls/LoginForm.Designer.cs +++ b/Common/Ui/GenesisToolBox/Ctls/LoginForm.Designer.cs @@ -29,148 +29,171 @@ private void InitializeComponent() { this.components = new System.ComponentModel.Container(); - this.LoginFormPanel = new System.Windows.Forms.Panel(); - this.ErrorMessage = new System.Windows.Forms.Label(); - this.LoginButton = new System.Windows.Forms.Button(); - this.Password = new System.Windows.Forms.TextBox(); - this.UsernameLabel = new System.Windows.Forms.Label(); - this.Username = new System.Windows.Forms.TextBox(); - this.PasswordLabel = new System.Windows.Forms.Label(); this.LoginErrorProvider = new System.Windows.Forms.ErrorProvider(this.components); + this.layout = new System.Windows.Forms.TableLayoutPanel(); + this.passwordLbl = new System.Windows.Forms.Label(); + this.usernameLbl = new System.Windows.Forms.Label(); + this.username = new System.Windows.Forms.TextBox(); + this.password = new System.Windows.Forms.TextBox(); + this.loginBtn = new System.Windows.Forms.Button(); this.cancelBtn = new System.Windows.Forms.Button(); - this.LoginFormPanel.SuspendLayout(); + this.errorLbl = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.LoginErrorProvider)).BeginInit(); + this.layout.SuspendLayout(); this.SuspendLayout(); // - // LoginFormPanel - // - this.LoginFormPanel.Controls.Add(this.cancelBtn); - this.LoginFormPanel.Controls.Add(this.ErrorMessage); - this.LoginFormPanel.Controls.Add(this.LoginButton); - this.LoginFormPanel.Controls.Add(this.Password); - this.LoginFormPanel.Controls.Add(this.UsernameLabel); - this.LoginFormPanel.Controls.Add(this.Username); - this.LoginFormPanel.Controls.Add(this.PasswordLabel); - this.LoginFormPanel.Dock = System.Windows.Forms.DockStyle.Fill; - this.LoginFormPanel.Location = new System.Drawing.Point(0, 0); - this.LoginFormPanel.Name = "LoginFormPanel"; - this.LoginFormPanel.Size = new System.Drawing.Size(458, 439); - this.LoginFormPanel.TabIndex = 0; - // - // ErrorMessage - // - this.ErrorMessage.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.ErrorMessage.AutoSize = true; - this.ErrorMessage.ForeColor = System.Drawing.Color.Red; - this.ErrorMessage.Location = new System.Drawing.Point(96, 251); - this.ErrorMessage.Name = "ErrorMessage"; - this.ErrorMessage.Size = new System.Drawing.Size(0, 13); - this.ErrorMessage.TabIndex = 5; - // - // LoginButton - // - this.LoginButton.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.LoginButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.LoginButton.Location = new System.Drawing.Point(97, 221); - this.LoginButton.Name = "LoginButton"; - this.LoginButton.Size = new System.Drawing.Size(266, 23); - this.LoginButton.TabIndex = 4; - this.LoginButton.Text = "Login"; - this.LoginButton.UseVisualStyleBackColor = true; - this.LoginButton.Click += new System.EventHandler(this.LoginButtonClick); - // - // Password - // - this.Password.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.Password.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.Password.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.Password.Location = new System.Drawing.Point(97, 195); - this.Password.Name = "Password"; - this.Password.PasswordChar = '*'; - this.Password.Size = new System.Drawing.Size(266, 20); - this.Password.TabIndex = 3; - this.Password.UseSystemPasswordChar = true; - // - // UsernameLabel - // - this.UsernameLabel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.UsernameLabel.AutoSize = true; - this.UsernameLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.UsernameLabel.Location = new System.Drawing.Point(94, 140); - this.UsernameLabel.Name = "UsernameLabel"; - this.UsernameLabel.Size = new System.Drawing.Size(63, 13); - this.UsernameLabel.TabIndex = 0; - this.UsernameLabel.Text = "Username"; - // - // Username - // - this.Username.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.Username.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.Username.Location = new System.Drawing.Point(97, 156); - this.Username.Name = "Username"; - this.Username.Size = new System.Drawing.Size(266, 20); - this.Username.TabIndex = 2; - // - // PasswordLabel - // - this.PasswordLabel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.PasswordLabel.AutoSize = true; - this.PasswordLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.PasswordLabel.Location = new System.Drawing.Point(94, 179); - this.PasswordLabel.Name = "PasswordLabel"; - this.PasswordLabel.Size = new System.Drawing.Size(61, 13); - this.PasswordLabel.TabIndex = 1; - this.PasswordLabel.Text = "Password"; - // // LoginErrorProvider // this.LoginErrorProvider.BlinkRate = 0; this.LoginErrorProvider.BlinkStyle = System.Windows.Forms.ErrorBlinkStyle.NeverBlink; this.LoginErrorProvider.ContainerControl = this; // + // layout + // + this.layout.ColumnCount = 3; + this.layout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 16.66667F)); + this.layout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 66.66666F)); + this.layout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 16.66667F)); + this.layout.Controls.Add(this.passwordLbl, 1, 4); + this.layout.Controls.Add(this.usernameLbl, 1, 1); + this.layout.Controls.Add(this.username, 1, 2); + this.layout.Controls.Add(this.password, 1, 5); + this.layout.Controls.Add(this.loginBtn, 1, 7); + this.layout.Controls.Add(this.cancelBtn, 1, 9); + this.layout.Controls.Add(this.errorLbl, 1, 10); + this.layout.Dock = System.Windows.Forms.DockStyle.Fill; + this.layout.Location = new System.Drawing.Point(0, 0); + this.layout.Name = "layout"; + this.layout.RowCount = 12; + this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 5F)); + this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 10F)); + this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 10F)); + this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.layout.Size = new System.Drawing.Size(385, 541); + this.layout.TabIndex = 1; + // + // passwordLbl + // + this.passwordLbl.AutoSize = true; + this.passwordLbl.Dock = System.Windows.Forms.DockStyle.Fill; + this.passwordLbl.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.passwordLbl.Location = new System.Drawing.Point(64, 230); + this.passwordLbl.Margin = new System.Windows.Forms.Padding(0); + this.passwordLbl.Name = "passwordLbl"; + this.passwordLbl.Size = new System.Drawing.Size(256, 15); + this.passwordLbl.TabIndex = 1; + this.passwordLbl.Text = "Password"; + this.passwordLbl.TextAlign = System.Drawing.ContentAlignment.BottomLeft; + // + // usernameLbl + // + this.usernameLbl.AutoSize = true; + this.usernameLbl.Dock = System.Windows.Forms.DockStyle.Fill; + this.usernameLbl.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.usernameLbl.Location = new System.Drawing.Point(64, 187); + this.usernameLbl.Margin = new System.Windows.Forms.Padding(0); + this.usernameLbl.Name = "usernameLbl"; + this.usernameLbl.Size = new System.Drawing.Size(256, 15); + this.usernameLbl.TabIndex = 0; + this.usernameLbl.Text = "Username"; + this.usernameLbl.TextAlign = System.Drawing.ContentAlignment.BottomLeft; + // + // username + // + this.username.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.username.Dock = System.Windows.Forms.DockStyle.Fill; + this.username.Location = new System.Drawing.Point(67, 202); + this.username.Margin = new System.Windows.Forms.Padding(3, 0, 0, 0); + this.username.Name = "username"; + this.username.Size = new System.Drawing.Size(253, 23); + this.username.TabIndex = 2; + // + // password + // + this.password.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.password.Dock = System.Windows.Forms.DockStyle.Fill; + this.password.Location = new System.Drawing.Point(67, 245); + this.password.Margin = new System.Windows.Forms.Padding(3, 0, 0, 0); + this.password.Name = "password"; + this.password.Size = new System.Drawing.Size(253, 23); + this.password.TabIndex = 3; + this.password.UseSystemPasswordChar = true; + // + // loginBtn + // + this.loginBtn.AutoSize = true; + this.loginBtn.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.loginBtn.Cursor = System.Windows.Forms.Cursors.Hand; + this.loginBtn.Dock = System.Windows.Forms.DockStyle.Fill; + this.loginBtn.Location = new System.Drawing.Point(67, 278); + this.loginBtn.Margin = new System.Windows.Forms.Padding(3, 0, 0, 0); + this.loginBtn.Name = "loginBtn"; + this.loginBtn.Size = new System.Drawing.Size(253, 25); + this.loginBtn.TabIndex = 4; + this.loginBtn.Text = "Login"; + this.loginBtn.UseVisualStyleBackColor = true; + this.loginBtn.Click += new System.EventHandler(this.OnLoginClick); + // // cancelBtn // - this.cancelBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.cancelBtn.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.cancelBtn.Location = new System.Drawing.Point(97, 246); + this.cancelBtn.AutoSize = true; + this.cancelBtn.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.cancelBtn.Cursor = System.Windows.Forms.Cursors.Hand; + this.cancelBtn.Dock = System.Windows.Forms.DockStyle.Fill; + this.cancelBtn.Location = new System.Drawing.Point(67, 313); + this.cancelBtn.Margin = new System.Windows.Forms.Padding(3, 0, 0, 0); this.cancelBtn.Name = "cancelBtn"; - this.cancelBtn.Size = new System.Drawing.Size(266, 23); - this.cancelBtn.TabIndex = 6; + this.cancelBtn.Size = new System.Drawing.Size(253, 25); + this.cancelBtn.TabIndex = 5; this.cancelBtn.Text = "Cancel"; this.cancelBtn.UseVisualStyleBackColor = true; this.cancelBtn.Click += new System.EventHandler(this.OnCancelClick); // + // errorLbl + // + this.errorLbl.AutoSize = true; + this.errorLbl.Dock = System.Windows.Forms.DockStyle.Fill; + this.errorLbl.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.errorLbl.Font = new System.Drawing.Font("Consolas", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.errorLbl.ForeColor = System.Drawing.Color.Firebrick; + this.errorLbl.Location = new System.Drawing.Point(64, 338); + this.errorLbl.Margin = new System.Windows.Forms.Padding(0); + this.errorLbl.Name = "errorLbl"; + this.errorLbl.Size = new System.Drawing.Size(256, 15); + this.errorLbl.TabIndex = 6; + // // LoginForm // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.LoginFormPanel); + this.Controls.Add(this.layout); + this.Font = new System.Drawing.Font("Consolas", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.Name = "LoginForm"; - this.Size = new System.Drawing.Size(458, 439); - this.LoginFormPanel.ResumeLayout(false); - this.LoginFormPanel.PerformLayout(); + this.Size = new System.Drawing.Size(385, 541); ((System.ComponentModel.ISupportInitialize)(this.LoginErrorProvider)).EndInit(); + this.layout.ResumeLayout(false); + this.layout.PerformLayout(); this.ResumeLayout(false); } #endregion - - private System.Windows.Forms.Panel LoginFormPanel; - private System.Windows.Forms.Button LoginButton; - private System.Windows.Forms.TextBox Password; - private System.Windows.Forms.Label UsernameLabel; - private System.Windows.Forms.TextBox Username; - private System.Windows.Forms.Label PasswordLabel; private System.Windows.Forms.ErrorProvider LoginErrorProvider; - private System.Windows.Forms.Label ErrorMessage; + private System.Windows.Forms.TableLayoutPanel layout; + private System.Windows.Forms.Label passwordLbl; + private System.Windows.Forms.Label usernameLbl; + private System.Windows.Forms.TextBox username; + private System.Windows.Forms.TextBox password; + private System.Windows.Forms.Button loginBtn; private System.Windows.Forms.Button cancelBtn; + private System.Windows.Forms.Label errorLbl; } } diff --git a/Common/Ui/GenesisToolBox/Ctls/LoginForm.cs b/Common/Ui/GenesisToolBox/Ctls/LoginForm.cs index 8b72b837..cc7359c8 100644 --- a/Common/Ui/GenesisToolBox/Ctls/LoginForm.cs +++ b/Common/Ui/GenesisToolBox/Ctls/LoginForm.cs @@ -1,13 +1,15 @@ namespace Xylem.Common.Ui.GenesisToolBox.Ctls { using System; + using System.Collections.Generic; using System.Windows.Forms; using Xylem.Common.Ui.GenesisToolBox.Infrastructure; - public partial class LoginForm : UserControl + public partial class LoginForm : UserControl, IIdentityForm { - private readonly Action submittedCallback; + private readonly Action submittedCallback; + private readonly IDictionary fields; public LoginForm() { @@ -16,44 +18,44 @@ this.Dock = DockStyle.Fill; } - public LoginForm(Action submittedCallback) : this() - => this.submittedCallback = submittedCallback; - - public event Action OnCancellation; - - private void LoginButtonClick(object sender, EventArgs e) + public LoginForm(Action submittedCallback) : this() { - this.ErrorMessage.Text = default(string); - this.LoginErrorProvider.Clear(); + this.submittedCallback = submittedCallback; - var isValid = true; - - if (string.IsNullOrWhiteSpace(this.Username.Text)) + this.fields = new Dictionary { - isValid = false; - - this.LoginErrorProvider.SetError(this.Username, "Username is required."); - } - - if (string.IsNullOrWhiteSpace(this.Password.Text)) - { - isValid = false; - - this.LoginErrorProvider.SetError(this.Password, "Password is required."); - } - - if (isValid) - { - this.submittedCallback?.Invoke(this.Username.Text, this.Password.Text.ComputeBase64Hash(), this); - } + { "Username", this.username }, + { "Password", this.password }, + }; } - internal void ShowError(string errorMessage) - => this.ErrorMessage.Text = errorMessage; + private void OnLoginClick(object sender, EventArgs e) + { + this.LoginErrorProvider.Clear(); + + this.errorLbl.Text = default(string); + + if (!Software.Login(this.username.Text, this.password.Text.ComputeBase64Hash(), out var errors)) + { + this.errorLbl.Text = "Invalid login attempt!"; + + foreach (var kvp in errors) + { + if (this.fields.TryGetValue(kvp.Key, out var control)) + { + this.LoginErrorProvider.SetError(control, kvp.Value); + } + } + } + else + { + this.submittedCallback?.Invoke(this); + } + } private void OnCancelClick(Object sender, EventArgs e) { - this.OnCancellation?.Invoke(this); + this.submittedCallback?.Invoke(this); } } } diff --git a/Common/Ui/GenesisToolBox/Ctls/RegisterLDAPUser.Designer.cs b/Common/Ui/GenesisToolBox/Ctls/RegisterLDAPUser.Designer.cs index 88e103c2..b4701af5 100644 --- a/Common/Ui/GenesisToolBox/Ctls/RegisterLDAPUser.Designer.cs +++ b/Common/Ui/GenesisToolBox/Ctls/RegisterLDAPUser.Designer.cs @@ -58,9 +58,9 @@ // this.layout.AutoSize = true; this.layout.ColumnCount = 3; - this.layout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 18.51852F)); - this.layout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 62.96296F)); - this.layout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 18.51852F)); + this.layout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 16.66667F)); + this.layout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 66.66666F)); + this.layout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 16.66667F)); this.layout.Controls.Add(this.employeeIdLbl, 1, 1); this.layout.Controls.Add(this.employeeId, 1, 2); this.layout.Controls.Add(this.firstnameLbl, 1, 4); @@ -116,7 +116,6 @@ this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.layout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.layout.Size = new System.Drawing.Size(371, 545); this.layout.TabIndex = 1; // @@ -125,10 +124,10 @@ this.employeeIdLbl.AutoSize = true; this.employeeIdLbl.Dock = System.Windows.Forms.DockStyle.Fill; this.employeeIdLbl.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.employeeIdLbl.Location = new System.Drawing.Point(68, 58); + this.employeeIdLbl.Location = new System.Drawing.Point(61, 58); this.employeeIdLbl.Margin = new System.Windows.Forms.Padding(0); this.employeeIdLbl.Name = "employeeIdLbl"; - this.employeeIdLbl.Size = new System.Drawing.Size(233, 15); + this.employeeIdLbl.Size = new System.Drawing.Size(247, 15); this.employeeIdLbl.TabIndex = 0; this.employeeIdLbl.Text = "Employee Id"; this.employeeIdLbl.TextAlign = System.Drawing.ContentAlignment.BottomLeft; @@ -137,11 +136,11 @@ // this.employeeId.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.employeeId.Dock = System.Windows.Forms.DockStyle.Fill; - this.employeeId.Location = new System.Drawing.Point(71, 73); + this.employeeId.Location = new System.Drawing.Point(64, 73); this.employeeId.Margin = new System.Windows.Forms.Padding(3, 0, 0, 0); this.employeeId.Name = "employeeId"; this.employeeId.ReadOnly = true; - this.employeeId.Size = new System.Drawing.Size(230, 23); + this.employeeId.Size = new System.Drawing.Size(244, 23); this.employeeId.TabIndex = 1; // // firstnameLbl @@ -149,10 +148,10 @@ this.firstnameLbl.AutoSize = true; this.firstnameLbl.Dock = System.Windows.Forms.DockStyle.Fill; this.firstnameLbl.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.firstnameLbl.Location = new System.Drawing.Point(68, 101); + this.firstnameLbl.Location = new System.Drawing.Point(61, 101); this.firstnameLbl.Margin = new System.Windows.Forms.Padding(0); this.firstnameLbl.Name = "firstnameLbl"; - this.firstnameLbl.Size = new System.Drawing.Size(233, 15); + this.firstnameLbl.Size = new System.Drawing.Size(247, 15); this.firstnameLbl.TabIndex = 2; this.firstnameLbl.Text = "First name"; this.firstnameLbl.TextAlign = System.Drawing.ContentAlignment.BottomLeft; @@ -162,10 +161,10 @@ this.lastnameLbl.AutoSize = true; this.lastnameLbl.Dock = System.Windows.Forms.DockStyle.Fill; this.lastnameLbl.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.lastnameLbl.Location = new System.Drawing.Point(68, 144); + this.lastnameLbl.Location = new System.Drawing.Point(61, 144); this.lastnameLbl.Margin = new System.Windows.Forms.Padding(0); this.lastnameLbl.Name = "lastnameLbl"; - this.lastnameLbl.Size = new System.Drawing.Size(233, 15); + this.lastnameLbl.Size = new System.Drawing.Size(247, 15); this.lastnameLbl.TabIndex = 3; this.lastnameLbl.Text = "Last name"; this.lastnameLbl.TextAlign = System.Drawing.ContentAlignment.BottomLeft; @@ -175,10 +174,10 @@ this.phoneLbl.AutoSize = true; this.phoneLbl.Dock = System.Windows.Forms.DockStyle.Fill; this.phoneLbl.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.phoneLbl.Location = new System.Drawing.Point(68, 187); + this.phoneLbl.Location = new System.Drawing.Point(61, 187); this.phoneLbl.Margin = new System.Windows.Forms.Padding(0); this.phoneLbl.Name = "phoneLbl"; - this.phoneLbl.Size = new System.Drawing.Size(233, 15); + this.phoneLbl.Size = new System.Drawing.Size(247, 15); this.phoneLbl.TabIndex = 4; this.phoneLbl.Text = "Phone"; this.phoneLbl.TextAlign = System.Drawing.ContentAlignment.BottomLeft; @@ -188,10 +187,10 @@ this.emailLbl.AutoSize = true; this.emailLbl.Dock = System.Windows.Forms.DockStyle.Fill; this.emailLbl.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.emailLbl.Location = new System.Drawing.Point(68, 230); + this.emailLbl.Location = new System.Drawing.Point(61, 230); this.emailLbl.Margin = new System.Windows.Forms.Padding(0); this.emailLbl.Name = "emailLbl"; - this.emailLbl.Size = new System.Drawing.Size(233, 15); + this.emailLbl.Size = new System.Drawing.Size(247, 15); this.emailLbl.TabIndex = 5; this.emailLbl.Text = "Email"; this.emailLbl.TextAlign = System.Drawing.ContentAlignment.BottomLeft; @@ -201,10 +200,10 @@ this.usernameLbl.AutoSize = true; this.usernameLbl.Dock = System.Windows.Forms.DockStyle.Fill; this.usernameLbl.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.usernameLbl.Location = new System.Drawing.Point(68, 273); + this.usernameLbl.Location = new System.Drawing.Point(61, 273); this.usernameLbl.Margin = new System.Windows.Forms.Padding(0); this.usernameLbl.Name = "usernameLbl"; - this.usernameLbl.Size = new System.Drawing.Size(233, 15); + this.usernameLbl.Size = new System.Drawing.Size(247, 15); this.usernameLbl.TabIndex = 6; this.usernameLbl.Text = "Username"; this.usernameLbl.TextAlign = System.Drawing.ContentAlignment.BottomLeft; @@ -214,10 +213,10 @@ this.passwordLbl.AutoSize = true; this.passwordLbl.Dock = System.Windows.Forms.DockStyle.Fill; this.passwordLbl.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.passwordLbl.Location = new System.Drawing.Point(68, 316); + this.passwordLbl.Location = new System.Drawing.Point(61, 316); this.passwordLbl.Margin = new System.Windows.Forms.Padding(0); this.passwordLbl.Name = "passwordLbl"; - this.passwordLbl.Size = new System.Drawing.Size(233, 15); + this.passwordLbl.Size = new System.Drawing.Size(247, 15); this.passwordLbl.TabIndex = 7; this.passwordLbl.Text = "Password"; this.passwordLbl.TextAlign = System.Drawing.ContentAlignment.BottomLeft; @@ -227,10 +226,10 @@ this.confirmPasswordLbl.AutoSize = true; this.confirmPasswordLbl.Dock = System.Windows.Forms.DockStyle.Fill; this.confirmPasswordLbl.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.confirmPasswordLbl.Location = new System.Drawing.Point(68, 359); + this.confirmPasswordLbl.Location = new System.Drawing.Point(61, 359); this.confirmPasswordLbl.Margin = new System.Windows.Forms.Padding(0); this.confirmPasswordLbl.Name = "confirmPasswordLbl"; - this.confirmPasswordLbl.Size = new System.Drawing.Size(233, 15); + this.confirmPasswordLbl.Size = new System.Drawing.Size(247, 15); this.confirmPasswordLbl.TabIndex = 8; this.confirmPasswordLbl.Text = "Confirm password"; this.confirmPasswordLbl.TextAlign = System.Drawing.ContentAlignment.BottomLeft; @@ -239,64 +238,64 @@ // this.firstname.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.firstname.Dock = System.Windows.Forms.DockStyle.Fill; - this.firstname.Location = new System.Drawing.Point(71, 116); + this.firstname.Location = new System.Drawing.Point(64, 116); this.firstname.Margin = new System.Windows.Forms.Padding(3, 0, 0, 0); this.firstname.Name = "firstname"; this.firstname.ReadOnly = true; - this.firstname.Size = new System.Drawing.Size(230, 23); + this.firstname.Size = new System.Drawing.Size(244, 23); this.firstname.TabIndex = 9; // // lastname // this.lastname.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lastname.Dock = System.Windows.Forms.DockStyle.Fill; - this.lastname.Location = new System.Drawing.Point(71, 159); + this.lastname.Location = new System.Drawing.Point(64, 159); this.lastname.Margin = new System.Windows.Forms.Padding(3, 0, 0, 0); this.lastname.Name = "lastname"; this.lastname.ReadOnly = true; - this.lastname.Size = new System.Drawing.Size(230, 23); + this.lastname.Size = new System.Drawing.Size(244, 23); this.lastname.TabIndex = 10; // // phone // this.phone.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.phone.Dock = System.Windows.Forms.DockStyle.Fill; - this.phone.Location = new System.Drawing.Point(71, 202); + this.phone.Location = new System.Drawing.Point(64, 202); this.phone.Margin = new System.Windows.Forms.Padding(3, 0, 0, 0); this.phone.Name = "phone"; this.phone.ReadOnly = true; - this.phone.Size = new System.Drawing.Size(230, 23); + this.phone.Size = new System.Drawing.Size(244, 23); this.phone.TabIndex = 11; // // email // this.email.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.email.Dock = System.Windows.Forms.DockStyle.Fill; - this.email.Location = new System.Drawing.Point(71, 245); + this.email.Location = new System.Drawing.Point(64, 245); this.email.Margin = new System.Windows.Forms.Padding(3, 0, 0, 0); this.email.Name = "email"; this.email.ReadOnly = true; - this.email.Size = new System.Drawing.Size(230, 23); + this.email.Size = new System.Drawing.Size(244, 23); this.email.TabIndex = 12; // // username // this.username.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.username.Dock = System.Windows.Forms.DockStyle.Fill; - this.username.Location = new System.Drawing.Point(71, 288); + this.username.Location = new System.Drawing.Point(64, 288); this.username.Margin = new System.Windows.Forms.Padding(3, 0, 0, 0); this.username.Name = "username"; - this.username.Size = new System.Drawing.Size(230, 23); + this.username.Size = new System.Drawing.Size(244, 23); this.username.TabIndex = 13; // // password // this.password.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.password.Dock = System.Windows.Forms.DockStyle.Fill; - this.password.Location = new System.Drawing.Point(71, 331); + this.password.Location = new System.Drawing.Point(64, 331); this.password.Margin = new System.Windows.Forms.Padding(3, 0, 0, 0); this.password.Name = "password"; - this.password.Size = new System.Drawing.Size(230, 23); + this.password.Size = new System.Drawing.Size(244, 23); this.password.TabIndex = 14; this.password.UseSystemPasswordChar = true; // @@ -304,10 +303,10 @@ // this.confirmPassword.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.confirmPassword.Dock = System.Windows.Forms.DockStyle.Fill; - this.confirmPassword.Location = new System.Drawing.Point(71, 374); + this.confirmPassword.Location = new System.Drawing.Point(64, 374); this.confirmPassword.Margin = new System.Windows.Forms.Padding(3, 0, 0, 0); this.confirmPassword.Name = "confirmPassword"; - this.confirmPassword.Size = new System.Drawing.Size(230, 23); + this.confirmPassword.Size = new System.Drawing.Size(244, 23); this.confirmPassword.TabIndex = 15; this.confirmPassword.UseSystemPasswordChar = true; // @@ -316,11 +315,10 @@ this.submitBtn.AutoSize = true; this.submitBtn.Cursor = System.Windows.Forms.Cursors.Hand; this.submitBtn.Dock = System.Windows.Forms.DockStyle.Fill; - this.submitBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.submitBtn.Location = new System.Drawing.Point(71, 407); + this.submitBtn.Location = new System.Drawing.Point(64, 407); this.submitBtn.Margin = new System.Windows.Forms.Padding(3, 0, 0, 0); this.submitBtn.Name = "submitBtn"; - this.submitBtn.Size = new System.Drawing.Size(230, 27); + this.submitBtn.Size = new System.Drawing.Size(244, 27); this.submitBtn.TabIndex = 16; this.submitBtn.Text = "Complete Registration"; this.submitBtn.UseVisualStyleBackColor = true; @@ -331,11 +329,10 @@ this.cancelBtn.AutoSize = true; this.cancelBtn.Cursor = System.Windows.Forms.Cursors.Hand; this.cancelBtn.Dock = System.Windows.Forms.DockStyle.Fill; - this.cancelBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.cancelBtn.Location = new System.Drawing.Point(71, 444); + this.cancelBtn.Location = new System.Drawing.Point(64, 444); this.cancelBtn.Margin = new System.Windows.Forms.Padding(3, 0, 0, 0); this.cancelBtn.Name = "cancelBtn"; - this.cancelBtn.Size = new System.Drawing.Size(230, 27); + this.cancelBtn.Size = new System.Drawing.Size(244, 27); this.cancelBtn.TabIndex = 17; this.cancelBtn.Text = "Cancel"; this.cancelBtn.UseVisualStyleBackColor = true; @@ -347,10 +344,10 @@ this.errorLbl.Dock = System.Windows.Forms.DockStyle.Fill; this.errorLbl.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.errorLbl.ForeColor = System.Drawing.Color.Firebrick; - this.errorLbl.Location = new System.Drawing.Point(68, 471); + this.errorLbl.Location = new System.Drawing.Point(61, 471); this.errorLbl.Margin = new System.Windows.Forms.Padding(0); this.errorLbl.Name = "errorLbl"; - this.errorLbl.Size = new System.Drawing.Size(233, 15); + this.errorLbl.Size = new System.Drawing.Size(247, 15); this.errorLbl.TabIndex = 18; this.errorLbl.TextAlign = System.Drawing.ContentAlignment.BottomLeft; // diff --git a/Common/Ui/GenesisToolBox/Ctls/RegisterLDAPUser.cs b/Common/Ui/GenesisToolBox/Ctls/RegisterLDAPUser.cs index 98ae3771..d60cf28d 100644 --- a/Common/Ui/GenesisToolBox/Ctls/RegisterLDAPUser.cs +++ b/Common/Ui/GenesisToolBox/Ctls/RegisterLDAPUser.cs @@ -6,7 +6,7 @@ using Xylem.Common.Ui.GenesisToolBox.Infrastructure; - public partial class RegisterLDAPUser : UserControl + public partial class RegisterLDAPUser : UserControl, IIdentityForm { private readonly Action initializeFormState; private readonly IDictionary fields; @@ -51,6 +51,8 @@ { this.RegisterErrorProvider.Clear(); + this.errorLbl.Text = default(string); + var user = Software.PendingUser; user.Username = this.username.Text; diff --git a/Common/Ui/GenesisToolBox/FrmMainForm.cs b/Common/Ui/GenesisToolBox/FrmMainForm.cs index 0386e533..21db103a 100644 --- a/Common/Ui/GenesisToolBox/FrmMainForm.cs +++ b/Common/Ui/GenesisToolBox/FrmMainForm.cs @@ -12,6 +12,7 @@ using Ctls; using Infrastructure; using Utils.Logging; + using System.Collections.Generic; internal delegate void UpdateLayout(); @@ -393,12 +394,23 @@ /// private void HideContent() { - foreach (var control in Controls) + var controlsToRemove = new List(); + + foreach (Control control in Controls) { if (control is GroupBox groupBox) { groupBox.Hide(); } + else if (control is IIdentityForm _ ) + { + controlsToRemove.Add(control); + } + } + + foreach (var control in controlsToRemove) + { + this.Controls.Remove(control); } } @@ -407,7 +419,7 @@ /// private void SetSoftwareFunctions() { - // changePassword.Tag = SoftwareFunctions.LAA_ADMIN; + changePassword.Enabled = Software.IsAutenticated; btnSetup.Tag = SoftwareFunctions.GENERAL_SETUP; btnAlarm.Tag = SoftwareFunctions.GENERAL_ALARM; @@ -545,17 +557,7 @@ { Software.Logout(); - foreach (var control in Controls) - { - if (control is LoginForm loginForm) - { - Controls.Remove(loginForm); - - break; - } - } - - ShowAvailableSoftwareFunctions(); + InitializeFormState(); } private void OnLoginClick(Object sender, EventArgs args) @@ -576,43 +578,17 @@ if (!hasLoginForm) { - var loginForm = new LoginForm(LoginFormSubmitted); - loginForm.OnCancellation += OnControlCancellation; + var loginForm = new LoginForm(this.OnControlCancellation); Controls.Add(loginForm); } } - /// - /// Callback method that is called when user enters valid username and password. - /// - /// Not null or empty string. - /// Not null or empty string. - /// Is the LoginForm from witch is this method called. - private void LoginFormSubmitted(String username, String password, Object sender) - { - if (sender is LoginForm loginForm) - { - if (Software.Login(username, password)) - { - Controls.Remove(loginForm); - ShowAvailableSoftwareFunctions(); - - optionsMenuItem.Text = Software.UserName; - } - else - { - loginForm.ShowError("Invalid login attempt"); - } - } - } - private void OnChangePasswordClick(Object _, EventArgs _1) { this.HideContent(); var control = new ChangePassword(this.OnControlCancellation); - control.OnCancellation += this.OnControlCancellation; this.Controls.Add(control); } @@ -621,9 +597,9 @@ { if (control != null) { + this.HideContent(); + Software.Initialize(); - - this.Controls.Remove(control); } this.InitializeFormState(); diff --git a/Common/Ui/GenesisToolBox/GenesisToolBox.csproj b/Common/Ui/GenesisToolBox/GenesisToolBox.csproj index 98b584b8..242ca09d 100644 --- a/Common/Ui/GenesisToolBox/GenesisToolBox.csproj +++ b/Common/Ui/GenesisToolBox/GenesisToolBox.csproj @@ -450,6 +450,7 @@ + diff --git a/Common/Ui/GenesisToolBox/Infrastructure/IIdentityForm.cs b/Common/Ui/GenesisToolBox/Infrastructure/IIdentityForm.cs new file mode 100644 index 00000000..e4233063 --- /dev/null +++ b/Common/Ui/GenesisToolBox/Infrastructure/IIdentityForm.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Xylem.Common.Ui.GenesisToolBox.Infrastructure +{ + interface IIdentityForm + { + } +} diff --git a/Common/Ui/GenesisToolBox/Infrastructure/Software.cs b/Common/Ui/GenesisToolBox/Infrastructure/Software.cs index 02012e0f..44c04a3b 100644 --- a/Common/Ui/GenesisToolBox/Infrastructure/Software.cs +++ b/Common/Ui/GenesisToolBox/Infrastructure/Software.cs @@ -31,6 +31,8 @@ public static LDAPUser PendingUser => user; + public static Boolean IsAutenticated => !string.IsNullOrWhiteSpace(bearer); + public static AuthenticationHeaderValue AuthorizationHeader = new AuthenticationHeaderValue(Bearer, bearer); @@ -148,9 +150,11 @@ /// /// Sends login request and obtains an bearer authorization token. /// - public static Boolean Login(String username, String password) + public static Boolean Login(String username, String password, out Dictionary errors) { - var authenticationResponse = LocalWebRequest.PostRequestAndGetResponseAsync( + errors = new Dictionary(); + + var loginResponse = LocalWebRequest.PostRequestAndGetResponseAsync( url: $"{ServiceUrls.LaaProductionAPI}/LaaProductionWeb/API/Login/Local", json: new UserLoginModel { @@ -161,20 +165,28 @@ MinorV = SoftwareVersion.Current.MinorV, BuildV = SoftwareVersion.Current.BuildV, }); - bearer = authenticationResponse - ?.Content - ?.Trim() - ?.Trim('"'); - softwareFunctions = GetFunctions(); - if (!string.IsNullOrWhiteSpace(bearer)) + if (loginResponse.StatusCode == HttpStatusCode.OK) { - UserName = LocalWebRequest - .GetRequest( - timeoutMs: 1200, - url: $"{ServiceUrls.LaaProductionAPI}/LaaProductionWeb/API/Personalization/Login", - header: new Dictionary { { "Authorization", $"{Bearer} {bearer}" } }) - .Trim('"'); + bearer = loginResponse + ?.Content + ?.Trim() + ?.Trim('"'); + softwareFunctions = GetFunctions(); + + if (!string.IsNullOrWhiteSpace(bearer)) + { + UserName = LocalWebRequest + .GetRequest( + timeoutMs: 1200, + url: $"{ServiceUrls.LaaProductionAPI}/LaaProductionWeb/API/Personalization/Login", + header: new Dictionary { { "Authorization", $"{Bearer} {bearer}" } }) + .Trim('"'); + } + } + else + { + errors = JsonConvert.DeserializeObject>(loginResponse.Content); } if (string.IsNullOrWhiteSpace(UserName))