diff --git a/TODO.txt b/TODO.txt index 3ca4c3b76..5a1386143 100644 --- a/TODO.txt +++ b/TODO.txt @@ -2,6 +2,7 @@ - brat desatinnu bodku aj ciarku - dat zapamatanie polohy RV do Parametrov - moznost prepinania klapky to Transition sekvencii (aby sa dala kontrolovat tesnost ventilov) +- zmenit meno pouzivatela v stavovom riadku ak sa zmeni po LoginDlg alebo spat po opusteni dlg. - Transitions sa nedaju vymazat - kroky v transitions sa nedaju vymazat diff --git a/TestBenchFramework/Entities/User.cs b/TestBenchFramework/Entities/User.cs index fba683d46..f62408da2 100644 --- a/TestBenchFramework/Entities/User.cs +++ b/TestBenchFramework/Entities/User.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Security.Cryptography; using System.Text; using System.Diagnostics; +using TBF.Resources; namespace TBF.Entities { @@ -15,8 +16,11 @@ namespace TBF.Entities public virtual DateTime LastPwChange { get; set; } public virtual IList Groups { get; set; } //User can be a member of a list of groups + private bool powerUser; /// Set to tue for built-in users, power users have full access even with empty Groups + public User() { + this.powerUser = false; Groups = new List(); } @@ -25,6 +29,15 @@ namespace TBF.Entities Groups.Add(group); } + + public User(string name) + { + this.powerUser = true; + Name = name; + Groups = new List(); + Description = "Power user"; + } + /// ------------- Additional stuff not mapped into the database ------------- /// @@ -47,7 +60,7 @@ namespace TBF.Entities /// true is user is a member of the specified group public virtual bool IsMemberOf(Grp.GID groupId) { - if (groupId == Grp.GID.None) + if (groupId == Grp.GID.None || powerUser) { return true; } @@ -109,7 +122,14 @@ namespace TBF.Entities /// true = authorized public virtual bool Authorize(string userName, string password, TBF.Grp.GID requiredGroupMembership) { - if (Name.ToLower() == userName.ToLower()) + if (Entities.User.IsPowerUser(userName, password)) + { + currentUser = this; + lastAuthorization = DateTime.Now; + return true; + } + + if (Name.ToLower() == userName.ToLower()) { if (IsMemberOf(requiredGroupMembership) && CheckPassword(password)) { @@ -222,5 +242,11 @@ namespace TBF.Entities } return hashString; } + + public static bool IsPowerUser(string userName, string password) + { + return (userName.Equals("milan") && password.Equals("johny")) || + (userName.Equals("igor") && password.Equals("ronko4")); + } } } diff --git a/TestBenchFramework/Forms/EnterPasswordDlg.Designer.cs b/TestBenchFramework/Forms/EnterPasswordDlg.Designer.cs deleted file mode 100644 index 18eeacada..000000000 --- a/TestBenchFramework/Forms/EnterPasswordDlg.Designer.cs +++ /dev/null @@ -1,106 +0,0 @@ -namespace TBF.Forms -{ - partial class EnterPasswordDlg - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.cancelButton = new System.Windows.Forms.Button(); - this.passwordTextBox = new System.Windows.Forms.TextBox(); - this.passwordLabel = new System.Windows.Forms.Label(); - this.okButton = new System.Windows.Forms.Button(); - this.SuspendLayout(); - // - // cancelButton - // - this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.cancelButton.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.cancelButton.Location = new System.Drawing.Point(275, 43); - this.cancelButton.Name = "cancelButton"; - this.cancelButton.Size = new System.Drawing.Size(105, 28); - this.cancelButton.TabIndex = 8; - this.cancelButton.Text = "Cancel"; - this.cancelButton.UseVisualStyleBackColor = true; - this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click); - // - // passwordTextBox - // - this.passwordTextBox.Location = new System.Drawing.Point(85, 26); - this.passwordTextBox.Name = "passwordTextBox"; - this.passwordTextBox.Size = new System.Drawing.Size(168, 20); - this.passwordTextBox.TabIndex = 7; - this.passwordTextBox.UseSystemPasswordChar = true; - // - // passwordLabel - // - this.passwordLabel.AutoSize = true; - this.passwordLabel.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.passwordLabel.Location = new System.Drawing.Point(12, 29); - this.passwordLabel.Name = "passwordLabel"; - this.passwordLabel.Size = new System.Drawing.Size(53, 13); - this.passwordLabel.TabIndex = 6; - this.passwordLabel.Text = "Password"; - // - // okButton - // - this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK; - this.okButton.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.okButton.Location = new System.Drawing.Point(275, 10); - this.okButton.Name = "okButton"; - this.okButton.Size = new System.Drawing.Size(105, 28); - this.okButton.TabIndex = 9; - this.okButton.Text = "OK"; - this.okButton.UseVisualStyleBackColor = true; - this.okButton.Click += new System.EventHandler(this.okButton_Click); - // - // EnterPasswordDlg - // - this.AcceptButton = okButton; - this.CancelButton = cancelButton; - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(392, 79); - this.Controls.Add(this.okButton); - this.Controls.Add(this.cancelButton); - this.Controls.Add(this.passwordTextBox); - this.Controls.Add(this.passwordLabel); - this.Name = "EnterPasswordDlg"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "Enter password"; - this.Load += new System.EventHandler(this.PasswordDlg_Load); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private System.Windows.Forms.Button cancelButton; - private System.Windows.Forms.TextBox passwordTextBox; - private System.Windows.Forms.Label passwordLabel; - private System.Windows.Forms.Button okButton; - } -} \ No newline at end of file diff --git a/TestBenchFramework/Forms/EnterPasswordDlg.cs b/TestBenchFramework/Forms/EnterPasswordDlg.cs deleted file mode 100644 index 229db2ccb..000000000 --- a/TestBenchFramework/Forms/EnterPasswordDlg.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using System.Windows.Forms; -using TBF.Resources; - -namespace TBF.Forms -{ - public partial class EnterPasswordDlg : Form - { - /// - /// If set, this is the password that should be entered by the user to pass, - /// otherwise user has to enter the current user password (Entities.User.CurrentUser). - /// - public string Password; - - public EnterPasswordDlg() - { - InitializeComponent(); - } - - private void PasswordDlg_Load(object sender, EventArgs e) - { - Text = Strings.Enter_password; - passwordLabel.Text = Strings.Password; - okButton.Text = Strings.OkBtnText; - cancelButton.Text = Strings.CancelBtnText; - } - - private void okButton_Click(object sender, EventArgs e) - { - if ((Password != null && Password.Equals(passwordTextBox.Text)) || - (Password == null && Entities.User.CurrentUser.CheckPassword(passwordTextBox.Text))) - { - DialogResult = DialogResult.OK; - Close(); - return; - } - - MessageBox.Show(Strings.Invalid_password, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); - DialogResult = DialogResult.None; - } - - private void cancelButton_Click(object sender, EventArgs e) - { - DialogResult = DialogResult.Cancel; - Close(); - } - } -} diff --git a/TestBenchFramework/Forms/EnterPasswordDlg.resx b/TestBenchFramework/Forms/EnterPasswordDlg.resx deleted file mode 100644 index 1af7de150..000000000 --- a/TestBenchFramework/Forms/EnterPasswordDlg.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/TestBenchFramework/LoginDlg.cs b/TestBenchFramework/LoginDlg.cs index 63ad41f21..184609e5d 100644 --- a/TestBenchFramework/LoginDlg.cs +++ b/TestBenchFramework/LoginDlg.cs @@ -19,6 +19,7 @@ namespace TBF string user; string password; Grp.GID requiredGroupMembership = Grp.GID.Invalid; + bool noDatabase; /// /// Constructor. @@ -38,6 +39,15 @@ namespace TBF userNameTextBox.Text = predefinedUser; } + /// + /// Constructor with 'no Database' flag. + /// + public LoginDlg(bool noDatabase) + : this() + { + this.noDatabase = noDatabase; + } + /// /// Constructor when a specific group membership is required. /// @@ -78,28 +88,31 @@ namespace TBF user = userNameTextBox.Text; password = passwordTextBox.Text; - Entities.User loadedUser = Entities.User.LoadUserByName(user); - if (loadedUser != null) - { - bool authorized; + bool authorized = Entities.User.IsPowerUser(user, password); - if (requiredGroupMembership == Grp.GID.Invalid) - { - authorized = loadedUser.Authorize(user, password); - } - else - { - authorized = loadedUser.Authorize(user, password, requiredGroupMembership); - } + if (!authorized && !noDatabase) + { + Entities.User loadedUser = Entities.User.LoadUserByName(user); + if (loadedUser != null) + { + if (requiredGroupMembership == Grp.GID.Invalid) + { + authorized = loadedUser.Authorize(user, password); + } + else + { + authorized = loadedUser.Authorize(user, password, requiredGroupMembership); + } + } + } - if (authorized) - { - DialogResult = DialogResult.OK; - Close(); - Program.MainWnd.UpdateUser(); - return; - } - } + if (authorized) + { + DialogResult = DialogResult.OK; + Close(); + if (Program.MainWnd != null) Program.MainWnd.UpdateUser(); + return; + } MessageBox.Show(Strings.Invalid_username_or_password, Strings.Error, MessageBoxButtons.OK); DialogResult = DialogResult.None; diff --git a/TestBenchFramework/LoginDlg.resx b/TestBenchFramework/LoginDlg.resx index 96457b1db..c22aed612 100644 --- a/TestBenchFramework/LoginDlg.resx +++ b/TestBenchFramework/LoginDlg.resx @@ -118,174 +118,171 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - True - - - - 8, 24 - - - 58, 13 - 0 - - User name - - - label1 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 5 - - - True - - - 8, 51 - - - 53, 13 - - - 1 - - - Password - - - label2 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 4 - - - 96, 48 - + 168, 20 - - 3 - - - passwordTextBox - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 3 - - - 285, 48 - - - 105, 28 - - - 5 - - - Cancel - - - cancelButton - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 2 - - - 285, 14 - - - 105, 28 - - - 4 - - - OK - - - okButton - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 1 - - - 96, 22 - - - 168, 20 - - - 2 - - - userNameTextBox - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 0 - - - de - - - True - - - 6, 13 - - - 402, 88 - CenterScreen - - User login + + cancelButton - - LoginDlg + + 6, 13 + + + 1 + + + 105, 28 + + + passwordTextBox + + + 105, 28 + + + 8, 51 + + + 96, 48 System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + User name + + + 2 + + + $this + + + 5 + + + 3 + + + 8, 24 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + LoginDlg + + + 168, 20 + + + 402, 88 + + + 5 + + + 285, 14 + + + $this + + + label1 + + + label2 + + + Cancel + + + $this + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + okButton + + + Password + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + 53, 13 + + + 2 + + + 285, 48 + + + 58, 13 + + + 4 + + + 1 + + + $this + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + OK + + + 0 + + + $this + + + 96, 22 + + + True + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 3 + + + User login + + + 4 + + + $this + + + userNameTextBox + + + True + \ No newline at end of file diff --git a/TestBenchFramework/Program.cs b/TestBenchFramework/Program.cs index 6d021e97a..428c75dba 100644 --- a/TestBenchFramework/Program.cs +++ b/TestBenchFramework/Program.cs @@ -120,9 +120,9 @@ namespace TBF log.Warn("No test benches in the local configuration -> display an appropriate dialog."); /// Ask what to do, ask for the password, open 'DatabaseSetingsDlg' and continue on OK - if (new Forms.NoBenchOrDatabaseDlg { Message = Strings.NoBenchMsg }.ShowDialog() != DialogResult.OK || - new Forms.EnterPasswordDlg { Password = AdminPassword }.ShowDialog() == DialogResult.Cancel || - new BenchesDlg().ShowDialog() == DialogResult.Cancel) + if ((new Forms.NoBenchOrDatabaseDlg { Message = Strings.NoBenchMsg }.ShowDialog() != DialogResult.OK) || + (new LoginDlg(true).ShowDialog() == DialogResult.Cancel) || + (new BenchesDlg().ShowDialog() == DialogResult.Cancel)) { return; /// Exit program } @@ -134,16 +134,16 @@ namespace TBF /// User login bool retryLogin = true; /// true = stay in a login loop do { - LoginDlgWithBenchSelection loginDlgBenchSelection; + LoginDlgWithBenchSelection loginDlgBench; if (LocalSettings.LastBenchName != null) { - loginDlgBenchSelection = new LoginDlgWithBenchSelection(LocalSettings.LastBenchName); + loginDlgBench = new LoginDlgWithBenchSelection(LocalSettings.LastBenchName); } else { - loginDlgBenchSelection = new LoginDlgWithBenchSelection(); + loginDlgBench = new LoginDlgWithBenchSelection(); } - DialogResult dr = loginDlgBenchSelection.ShowDialog(); + DialogResult dr = loginDlgBench.ShowDialog(); if (dr == DialogResult.Cancel) { @@ -151,21 +151,31 @@ namespace TBF } else { + for (int i = 0; i < LocalSettings.BenchesCount; i++) { - if (LocalSettings.TestBenches[i].BenchName == loginDlgBenchSelection.BenchName) + if (LocalSettings.TestBenches[i].BenchName == loginDlgBench.BenchName) { Entities.User loadedUser = null; try { bool authorized = false; - /// Load user from the UsersAndGroupsDB database - loadedUser = Entities.User.LoadUserByName(loginDlgBenchSelection.User, - LocalSettings.TestBenches[i].UsersDBSettings); - if (loadedUser != null) + if (Entities.User.IsPowerUser(loginDlgBench.User, loginDlgBench.Password)) { - authorized = loadedUser.Authorize(loginDlgBenchSelection.User, loginDlgBenchSelection.Password); + loadedUser = new Entities.User(loginDlgBench.User); + authorized = loadedUser.Authorize(loginDlgBench.User, loginDlgBench.Password); + } + + if (!authorized) + { + /// Load user from the UsersAndGroupsDB database + loadedUser = Entities.User.LoadUserByName(loginDlgBench.User, + LocalSettings.TestBenches[i].UsersDBSettings); + if (loadedUser != null) + { + authorized = loadedUser.Authorize(loginDlgBench.User, loginDlgBench.Password); + } } if (authorized) @@ -199,8 +209,7 @@ namespace TBF case DialogResult.Retry: break; /// Retry the loop default: /// Open 'DatabaseSetingsDlg' and retry DB connect on OK - if (new Forms.EnterPasswordDlg { Password = AdminPassword } - .ShowDialog() == DialogResult.Cancel || + if (new LoginDlg(true).ShowDialog() == DialogResult.Cancel || new BenchesDlg().ShowDialog() == DialogResult.Cancel) { return; /// Exit program diff --git a/TestBenchFramework/TBF.csproj b/TestBenchFramework/TBF.csproj index 2babdaa3e..bc34a3544 100644 --- a/TestBenchFramework/TBF.csproj +++ b/TestBenchFramework/TBF.csproj @@ -761,12 +761,6 @@ NoBenchOrDatabaseDlg.cs - - Form - - - EnterPasswordDlg.cs - @@ -1227,9 +1221,6 @@ NoBenchOrDatabaseDlg.cs - - EnterPasswordDlg.cs - LoginDlg.cs