diff --git a/Config/Entities/Enums.cs b/Config/Entities/Enums.cs index acc22b6bd..c09c1c70a 100644 --- a/Config/Entities/Enums.cs +++ b/Config/Entities/Enums.cs @@ -332,5 +332,14 @@ namespace Config.Entities #endif Count } + + + public enum LoginMethod + { + UserName, /// = alias, abbreviation + FullName, /// = description + Number, + Count + } } diff --git a/Config/Entities/Procedure.cs b/Config/Entities/Procedure.cs index b054c5e07..d6de4f5a4 100644 --- a/Config/Entities/Procedure.cs +++ b/Config/Entities/Procedure.cs @@ -53,7 +53,7 @@ namespace Config.Entities /// /// Default values /// - CreationUser = (Config.Data.CurrentUser != null) ? Config.Data.CurrentUser.Name : null; + CreationUser = (Config.Data.CurrentUser != null) ? Config.Data.CurrentUser.UserName : null; CreationTime = DateTime.Now; LastChgUser = CreationUser; LastChgTime = CreationTime; diff --git a/Config/Entities/User.cs b/Config/Entities/User.cs index 4326f9db0..d3740fddb 100644 --- a/Config/Entities/User.cs +++ b/Config/Entities/User.cs @@ -16,11 +16,10 @@ namespace Config.Entities static readonly ILog log = LogManager.GetLogger(typeof(User)); public virtual int Id { get; protected set; } - public virtual string Name { get; set; } + public virtual string UserName { get; set; } /// = name, alias, abbreviation + public virtual string FullName { get; set; } /// = description public virtual int Number { get; set; } - public virtual string Alias { get; set; } public virtual string Password { get; set; } - public virtual string Description { get; set; } public virtual DateTime LastPwChange { get; set; } public virtual IList Groups { get; set; } //User can be a member of a list of groups @@ -37,13 +36,13 @@ namespace Config.Entities #endif } - public User(string name, int number, bool powerUser) + public User(string userName, int number, bool powerUser) { - Name = name; + UserName = userName; Number = number; this.powerUser = powerUser; Groups = new List(); - Description = powerUser ? "Power user" : string.Empty; + FullName = powerUser ? "Power user" : string.Empty; } public virtual void AddGroup(Group group) @@ -109,43 +108,6 @@ namespace Config.Entities return (Password == EncryptedPassword(password)); } - /// - /// The FIRST of TWO possible user authorization method to be used - /// when a specific group membership is required (you can use Grp.GID.None). - /// If the user is not authorized, the current user remains to be a current user - /// (i.e. the access rights were not risen to a higher level). - /// If you require different behavior, use Unauthorize() before calling Authorize(). - /// - /// - /// - /// - /// true = authorized - public virtual bool Authorize(string userName, string password, Grp.GID requiredGroupMembership) - { - if (Entities.User.IsPowerUser(userName, password)) - { - Data.CurrentUser = this; - Data.LastAuthorization = DateTime.Now; - log.FatalFormat("Power user '{0}' authorized @level '{1}'", userName, requiredGroupMembership); - return true; - } - - if (Name.ToLower() == userName.ToLower()) - { - if (IsMemberOf(requiredGroupMembership) && CheckPassword(password)) - { - Data.CurrentUser = this; - Data.LastAuthorization = DateTime.Now; - log.FatalFormat("User '{0}' authorized @level '{1}'", userName, requiredGroupMembership); - return true; - } - else - { - return false; - } - } - return false; - } /// /// The FIRST of TWO possible user authorization method to be used @@ -154,8 +116,55 @@ namespace Config.Entities /// (i.e. the access rights were not risen to a higher level). /// If you require different behavior, use Unauthorize() before calling Authorize(). /// - /// - /// + /// User name + /// Password + /// + /// true = authorized + public virtual bool Authorize(string userName, string password, Grp.GID requiredGroupMembership) + { + if (Entities.User.IsPowerUser(userName, password)) + { + Data.CurrentUser = this; + Data.LastAuthorization = DateTime.Now; + log.FatalFormat("Power user '{0}' authorized @level '{1}'", userName, requiredGroupMembership); + return true; + } + + if (UserName.ToLower() == userName.ToLower()) + { + if (IsMemberOf(requiredGroupMembership) && CheckPassword(password)) + { + Data.CurrentUser = this; + Data.LastAuthorization = DateTime.Now; + log.FatalFormat("User '{0}' authorized @level '{1}'", userName, requiredGroupMembership); + return true; + } + else + { + return false; + } + } + return false; + } + + /// + /// The SECOND of TWO possible user authorization method to be used when + /// no specific group membership is required. + /// + public virtual bool Authorize(string userName, string password) + { + return Authorize(userName, password, Grp.GID.None); + } + + /// + /// The FIRST of TWO possible user authorization method to be used + /// when a specific group membership is required (you can use Grp.GID.None). + /// If the user is not authorized, the current user remains to be a current user + /// (i.e. the access rights were not risen to a higher level). + /// If you require different behavior, use Unauthorize() before calling Authorize(). + /// + /// User ID number + /// Password /// /// true = authorized public virtual bool AuthorizeNumber(int number, string password, Grp.GID requiredGroupMembership) @@ -177,6 +186,15 @@ namespace Config.Entities return false; } + /// + /// The SECOND of TWO possible user authorization method to be used when + /// no specific group membership is required. + /// + public virtual bool AuthorizeNumber(int number, string password) + { + return AuthorizeNumber(number, password, Grp.GID.None); + } + /// /// The FIRST of TWO possible user authorization method to be used /// when a specific group membership is required (you can use Grp.GID.None). @@ -184,19 +202,19 @@ namespace Config.Entities /// (i.e. the access rights were not risen to a higher level). /// If you require different behavior, use Unauthorize() before calling Authorize(). /// - /// + /// /// /// /// true = authorized - public virtual bool AuthorizeAlias(string alias, string password, Grp.GID requiredGroupMembership) + public virtual bool AuthorizeFullName(string fullName, string password, Grp.GID requiredGroupMembership) { - if (Alias.ToLower() == alias.ToLower()) + if (FullName.ToLower() == fullName.ToLower()) { if (IsMemberOf(requiredGroupMembership) && CheckPassword(password)) { Data.CurrentUser = this; Data.LastAuthorization = DateTime.Now; - log.FatalFormat("User alias={0} authorized @level '{1}'", alias, requiredGroupMembership); + log.FatalFormat("User alias={0} authorized @level '{1}'", fullName, requiredGroupMembership); return true; } else @@ -207,49 +225,13 @@ namespace Config.Entities return false; } - /// - /// The SECOND of TWO possible user authorization method to be used when - /// no specific group membership is required. - /// If the user is not authorized, the current user remains to be a current user - /// (i.e. the access rights were not risen to a higher level). - /// If you require different behavior, use Unauthorize() before calling Authorize(). - /// - /// User name - /// Password - /// true = authorized - public virtual bool Authorize(string userName, string password) - { - return Authorize(userName, password, Grp.GID.None); - } - /// /// The SECOND of TWO possible user authorization method to be used when /// no specific group membership is required. - /// If the user is not authorized, the current user remains to be a current user - /// (i.e. the access rights were not risen to a higher level). - /// If you require different behavior, use Unauthorize() before calling Authorize(). /// - /// User ID number - /// Password - /// true = authorized - public virtual bool AuthorizeNumber(int number, string password) + public virtual bool AuthorizeFullName(string fullName, string password) { - return AuthorizeNumber(number, password, Grp.GID.None); - } - - /// - /// The SECOND of TWO possible user authorization method to be used when - /// no specific group membership is required. - /// If the user is not authorized, the current user remains to be a current user - /// (i.e. the access rights were not risen to a higher level). - /// If you require different behavior, use Unauthorize() before calling Authorize(). - /// - /// Alias (abbreviated user name) - /// Password - /// true = authorized - public virtual bool AuthorizeAlias(string alias, string password) - { - return AuthorizeAlias(alias, password, Grp.GID.None); + return AuthorizeFullName(fullName, password, Grp.GID.None); } /// @@ -260,23 +242,24 @@ namespace Config.Entities public static User AuthorizeDummyUser(string username) { User user = new User(); - user.Name = username; + user.UserName = username; Data.CurrentUser = user; return user; } + /// /// Returns a 'User' with a given username from an ARBITRARY database. /// /// User name for the query /// reference to a 'User' (if it exists) or null - public static User LoadUserByName(string username, DBSettings dbSettings) + public static User LoadUserByName(string userName, DBSettings dbSettings) { IList listOfUsers = FluentCommon.CreateSessionFactory(DBKind.Config, dbSettings, false) .OpenSession() - .QueryOver() - .Where(x => (x.Name.ToLower() == username.ToLower())) - .List(); + .CreateQuery("FROM User WHERE LOWER(UserName) = :username") /// Note: QueryOver().Where(x => x.UserName.ToLower() == ... does not work + .SetParameter("username", userName.ToLower()) + .List(); if (listOfUsers.Count > 0) return listOfUsers[0]; return null; } @@ -286,16 +269,81 @@ namespace Config.Entities /// /// User name for the query /// reference to a 'User' (if it exists) or null - public static User LoadUserByName(string username) + public static User LoadUserByName(string userName) { IList listOfUsers = FluentCommon.CreateSession(DBKind.Config) + .CreateQuery("FROM User WHERE LOWER(UserName) = :username") /// Note: QueryOver().Where(x => x.UserName.ToLower() == ... does not work + .SetParameter("username", userName.ToLower()) + .List(); + if (listOfUsers.Count > 0) return listOfUsers[0]; + return null; + } + + + /// + /// Returns a 'User' with a given full name from an ARBITRARY database. + /// + /// Full name for the query + /// reference to a 'User' (if it exists) or null + public static User LoadUserByFullName(string fullName, Config.DBSettings dbSettings) + { + IList listOfUsers = FluentCommon.CreateSessionFactory(DBKind.Config, dbSettings, false) + .OpenSession() + .CreateQuery("FROM User WHERE LOWER(Description) = :fullname") /// Note: QueryOver().Where(x => x.FullName.ToLower() == ... does not work + .SetParameter("fullname", fullName.ToLower()) + .List(); + if (listOfUsers.Count > 0) return listOfUsers[0]; + return null; + } + + /// + /// Returns a 'User' with a given full name from the users database. + /// + /// Full name for the query + /// reference to a 'User' (if it exists) or null + public static User LoadUserByFullName(string fullName) + { + IList listOfUsers = FluentCommon.CreateSession(DBKind.Config) + .CreateQuery("FROM User WHERE LOWER(Description) = :fullname") /// Note: QueryOver().Where(x => x.FullName.ToLower() == ... does not work + .SetParameter("fullname", fullName.ToLower()) + .List(); + if (listOfUsers.Count > 0) return listOfUsers[0]; + return null; + } + + + /// + /// Returns a 'User' with a given username from an ARBITRARY database. + /// + /// User ID number for the query + /// reference to a 'User' (if it exists) or null + public static User LoadUserByNumber(int number, Config.DBSettings dbSettings) + { + IList listOfUsers = FluentCommon.CreateSessionFactory(DBKind.Config, dbSettings, false) + .OpenSession() .QueryOver() - .Where(x => (x.Name.ToLower() == username.ToLower())) + .Where(x => (x.Number == number)) .List(); if (listOfUsers.Count > 0) return listOfUsers[0]; return null; } + /// + /// Returns a 'User' with a given username from the users database. + /// + /// User ID number for the query + /// reference to a 'User' (if it exists) or null + public static User LoadUserByNumber(int number) + { + IList listOfUsers = FluentCommon.CreateSession(DBKind.Config) + .QueryOver() + .Where(x => (x.Number == number)) + .List(); + if (listOfUsers.Count > 0) return listOfUsers[0]; + return null; + } + + /// /// returns an IList of all Users /// diff --git a/Config/Entities/WMType.cs b/Config/Entities/WMType.cs index b4b0c06e2..bc708fe9d 100644 --- a/Config/Entities/WMType.cs +++ b/Config/Entities/WMType.cs @@ -41,7 +41,7 @@ namespace Config.Entities WMType procedure = new WMType() { CreateTime = DateTime.Now, - CreateUserName = Config.Data.CurrentUser.Name, + CreateUserName = Config.Data.CurrentUser.UserName, CreateDescription = "A default water meter created.", Name = "Watermeter", PulseRate = 1000, diff --git a/Config/FluentCommon.cs b/Config/FluentCommon.cs index 2dc44d4d6..4c5d1b29e 100644 --- a/Config/FluentCommon.cs +++ b/Config/FluentCommon.cs @@ -182,8 +182,8 @@ namespace Config /// Create the user 'admin' add his groups var admin = new Entities.User { - Name = Data.AdminUsername, - Description = Strings.Administrator, + UserName = Data.AdminUsername, + FullName = Strings.Administrator, LastPwChange = DateTime.Now }; admin.SetPassword(Data.AdminPassword); diff --git a/Config/IUser.cs b/Config/IUser.cs index 2b548e8fd..3ce42b67c 100644 --- a/Config/IUser.cs +++ b/Config/IUser.cs @@ -4,23 +4,23 @@ namespace Config { public interface IUser { - string Name { get; } - string Alias { get; } + string UserName { get; } + string FullName { get; } int Number { get; } bool IsMemberOf(Grp.GID group); - bool Authorize(string username, string password); - bool Authorize(string username, string password, Grp.GID requiredGroup); + bool Authorize(string userName, string password); + bool Authorize(string userName, string password, Grp.GID requiredGroup); - bool AuthorizeAlias(string alias, string password); - bool AuthorizeAlias(string alias, string password, Grp.GID requiredGroup); + bool AuthorizeFullName(string fullName, string password); + bool AuthorizeFullName(string fullName, string password, Grp.GID requiredGroup); bool AuthorizeNumber(int number, string password); bool AuthorizeNumber(int number, string password, Grp.GID requiredGroup); //IUser LoadUserByName(string username, DBSettings dbSettings); + //IUser LoadUserByFullName(string alias, DBSettings dbSettings); //IUser LoadUserByNumber(int number, DBSettings dbSettings); - //IUser LoadUserByAlias(string alias, DBSettings dbSettings); } } diff --git a/Config/Mappings/UserMap.cs b/Config/Mappings/UserMap.cs index 25852b0bd..ccb028381 100644 --- a/Config/Mappings/UserMap.cs +++ b/Config/Mappings/UserMap.cs @@ -10,10 +10,10 @@ namespace Config.Mappings public UserMap() { Id(x => x.Id); - Map(x => x.Name); + Map(x => x.UserName).Column("Name"); Map(x => x.Number); Map(x => x.Password); - Map(x => x.Description); + Map(x => x.FullName).Column("Description"); Map(x => x.LastPwChange); HasMany(x => x.Groups) .Cascade.All(); diff --git a/TestBenchFramework/BenchControl/ResultsPrinters/Basic/BasicPrintDocument.cs b/TestBenchFramework/BenchControl/ResultsPrinters/Basic/BasicPrintDocument.cs index 154804a44..6a59ba608 100644 --- a/TestBenchFramework/BenchControl/ResultsPrinters/Basic/BasicPrintDocument.cs +++ b/TestBenchFramework/BenchControl/ResultsPrinters/Basic/BasicPrintDocument.cs @@ -177,7 +177,7 @@ namespace TBF.BenchControl.ResultsPrinters.Basic //batch.EndTime.ToShortDateString() + " " + batch.EndTime.ToShortTimeString(), string.Format("{0:yyyy.MM.dd HH:mm}", batch.EndTime), batch.ProcedureName, - Config.Data.CurrentUser.Name, + Config.Data.CurrentUser.UserName, batch.AmbientTempAve().ToString("F1") + " °C", Config.Units.ConvertTo(Config.Unit.mbar, batch.AmbientPressAve()).ToString("F0") + " mbar", batch.AmbientHumiAve().ToString("F0") + " %", diff --git a/TestBenchFramework/BenchControl/Sequences/MainSeq.cs b/TestBenchFramework/BenchControl/Sequences/MainSeq.cs index e8e4e7486..6783d976a 100644 --- a/TestBenchFramework/BenchControl/Sequences/MainSeq.cs +++ b/TestBenchFramework/BenchControl/Sequences/MainSeq.cs @@ -319,7 +319,7 @@ namespace TBF.BenchControl.Sequences /// BatchRslts = Results.BatchResults.NewFromProcedure(Program.LocalSettings.BatchNr, (BenchInfo != null) ? BenchInfo.TestBenchId : 1, - Config.Data.CurrentUser.Name, Config.Data.CurrentUser.Number, Program.Version, + Config.Data.CurrentUser.UserName, Config.Data.CurrentUser.Number, Program.Version, StateMachine.Procedure, waterMeterData, waterMeterParts); StateMachine.CycleStartTimeStamp = BatchRslts.Batch.StartTime; diff --git a/TestBenchFramework/Forms/EditSelectedUser.cs b/TestBenchFramework/Forms/EditSelectedUser.cs index b1d000c95..720b52fd2 100644 --- a/TestBenchFramework/Forms/EditSelectedUser.cs +++ b/TestBenchFramework/Forms/EditSelectedUser.cs @@ -27,8 +27,8 @@ namespace TBF.Forms { Localize(); - txtName.Text = CurrentEditUser.Name; - txtDescription.Text = CurrentEditUser.Description; + txtName.Text = CurrentEditUser.UserName; + txtDescription.Text = CurrentEditUser.FullName; txtPassword.Text = ""; ShowGroups(); } @@ -79,13 +79,13 @@ namespace TBF.Forms } - CurrentEditUser.Name = txtName.Text; + CurrentEditUser.UserName = txtName.Text; if (txtPassword.Text != "") { CurrentEditUser.SetPassword(txtPassword.Text); } - CurrentEditUser.Description = txtDescription.Text; + CurrentEditUser.FullName = txtDescription.Text; // Groups CurrentEditUser.Groups.Clear(); @@ -115,7 +115,7 @@ namespace TBF.Forms { if (person.Id != CurrentEditUser.Id) { // other user - if (person.Name.ToLower() == Username.ToLower()) + if (person.UserName.ToLower() == Username.ToLower()) { // Name is equal, so allready taken return true; diff --git a/TestBenchFramework/Forms/EditUsers.cs b/TestBenchFramework/Forms/EditUsers.cs index ac6e96099..22fabca2e 100644 --- a/TestBenchFramework/Forms/EditUsers.cs +++ b/TestBenchFramework/Forms/EditUsers.cs @@ -59,7 +59,7 @@ namespace TBF.Forms listViewUsers.Items.Clear(); foreach (var person in ListOfUsers) { - ListViewItem item = new ListViewItem(person.Name); + ListViewItem item = new ListViewItem(person.UserName); item.SubItems.Add(person.Id.ToString()); item.Tag = person; this.listViewUsers.Items.Add(item); diff --git a/TestBenchFramework/Forms/LoginDlg.Designer.cs b/TestBenchFramework/Forms/LoginDlg.Designer.cs index dcf39e27c..22d9dcce5 100644 --- a/TestBenchFramework/Forms/LoginDlg.Designer.cs +++ b/TestBenchFramework/Forms/LoginDlg.Designer.cs @@ -31,77 +31,78 @@ namespace TBF.Forms /// private void InitializeComponent() { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(LoginDlg)); - this.label1 = new System.Windows.Forms.Label(); - this.label2 = new System.Windows.Forms.Label(); - this.passwordTextBox = new System.Windows.Forms.TextBox(); - this.cancelButton = new System.Windows.Forms.Button(); - this.okButton = new System.Windows.Forms.Button(); - this.userNameTextBox = new System.Windows.Forms.TextBox(); - this.SuspendLayout(); - // - // label1 - // - resources.ApplyResources(this.label1, "label1"); - this.label1.Name = "label1"; - // - // label2 - // - resources.ApplyResources(this.label2, "label2"); - this.label2.Name = "label2"; - // - // passwordTextBox - // - resources.ApplyResources(this.passwordTextBox, "passwordTextBox"); - this.passwordTextBox.Name = "passwordTextBox"; - this.passwordTextBox.UseSystemPasswordChar = true; - // - // cancelButton - // - resources.ApplyResources(this.cancelButton, "cancelButton"); - this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.cancelButton.Name = "cancelButton"; - this.cancelButton.UseVisualStyleBackColor = true; - this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click); - // - // okButton - // - resources.ApplyResources(this.okButton, "okButton"); - this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK; - this.okButton.Name = "okButton"; - this.okButton.UseVisualStyleBackColor = true; - this.okButton.Click += new System.EventHandler(this.okButton_Click); - // - // userNameTextBox - // - resources.ApplyResources(this.userNameTextBox, "userNameTextBox"); - this.userNameTextBox.Name = "userNameTextBox"; - // - // LoginDlg - // - this.AcceptButton = this.okButton; - resources.ApplyResources(this, "$this"); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.CancelButton = this.cancelButton; - this.Controls.Add(this.userNameTextBox); - this.Controls.Add(this.okButton); - this.Controls.Add(this.cancelButton); - this.Controls.Add(this.passwordTextBox); - this.Controls.Add(this.label2); - this.Controls.Add(this.label1); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; - this.Name = "LoginDlg"; - this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; - this.Load += new System.EventHandler(this.LoginDlg_Load); - this.ResumeLayout(false); - this.PerformLayout(); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(LoginDlg)); + this.aliasLabel = new System.Windows.Forms.Label(); + this.passwordLabel = new System.Windows.Forms.Label(); + this.passwordTextBox = new System.Windows.Forms.TextBox(); + this.cancelButton = new System.Windows.Forms.Button(); + this.okButton = new System.Windows.Forms.Button(); + this.userNameTextBox = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // aliasLabel + // + resources.ApplyResources(this.aliasLabel, "aliasLabel"); + this.aliasLabel.Name = "aliasLabel"; + this.aliasLabel.Click += new System.EventHandler(this.aliasLabel_Click); + // + // passwordLabel + // + resources.ApplyResources(this.passwordLabel, "passwordLabel"); + this.passwordLabel.Name = "passwordLabel"; + // + // passwordTextBox + // + resources.ApplyResources(this.passwordTextBox, "passwordTextBox"); + this.passwordTextBox.Name = "passwordTextBox"; + this.passwordTextBox.UseSystemPasswordChar = true; + // + // cancelButton + // + resources.ApplyResources(this.cancelButton, "cancelButton"); + this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.cancelButton.Name = "cancelButton"; + this.cancelButton.UseVisualStyleBackColor = true; + this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click); + // + // okButton + // + resources.ApplyResources(this.okButton, "okButton"); + this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK; + this.okButton.Name = "okButton"; + this.okButton.UseVisualStyleBackColor = true; + this.okButton.Click += new System.EventHandler(this.okButton_Click); + // + // userNameTextBox + // + resources.ApplyResources(this.userNameTextBox, "userNameTextBox"); + this.userNameTextBox.Name = "userNameTextBox"; + // + // LoginDlg + // + this.AcceptButton = this.okButton; + resources.ApplyResources(this, "$this"); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.CancelButton = this.cancelButton; + this.Controls.Add(this.userNameTextBox); + this.Controls.Add(this.okButton); + this.Controls.Add(this.cancelButton); + this.Controls.Add(this.passwordTextBox); + this.Controls.Add(this.passwordLabel); + this.Controls.Add(this.aliasLabel); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.Name = "LoginDlg"; + this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; + this.Load += new System.EventHandler(this.LoginDlg_Load); + this.ResumeLayout(false); + this.PerformLayout(); } #endregion - private System.Windows.Forms.Label label1; - private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label aliasLabel; + private System.Windows.Forms.Label passwordLabel; private System.Windows.Forms.TextBox userNameTextBox; private System.Windows.Forms.TextBox passwordTextBox; private System.Windows.Forms.Button cancelButton; diff --git a/TestBenchFramework/Forms/LoginDlg.cs b/TestBenchFramework/Forms/LoginDlg.cs index a1d24ba1b..ff87d96af 100644 --- a/TestBenchFramework/Forms/LoginDlg.cs +++ b/TestBenchFramework/Forms/LoginDlg.cs @@ -24,6 +24,9 @@ namespace TBF.Forms Config.Grp.GID requiredGroupMembership = Config.Grp.GID.Invalid; bool noDatabase; + Config.Entities.LoginMethod method; + + /// /// Constructor. /// @@ -73,16 +76,34 @@ namespace TBF.Forms private void LoginDlg_Load(object sender, EventArgs e) { - Text = Strings.User_Login + " TBF v." + Program.Version; - label1.Text = Strings.Username; - label2.Text = Strings.Password; - okButton.Text = Strings.OkBtnText; - cancelButton.Text = Strings.CancelBtnText; - - if (user == null) userNameTextBox.Select(); - else passwordTextBox.Select(); + Localize(); + + if (user == null) + userNameTextBox.Select(); + else + passwordTextBox.Select(); } + void Localize() + { + Text = Strings.User_Login + " TBF v." + Program.Version; + aliasLabel.Text = GetAliasLabel(); + passwordLabel.Text = Strings.Password; + okButton.Text = Strings.OkBtnText; + cancelButton.Text = Strings.CancelBtnText; + } + + string GetAliasLabel() + { + switch (method) + { + default: + case Config.Entities.LoginMethod.UserName: return Strings.User_name; + case Config.Entities.LoginMethod.FullName: return Strings.Full_name; + case Config.Entities.LoginMethod.Number: return Strings.User_code; + } + } + /// /// Try to authorize the user when OK clicked. /// @@ -98,13 +119,20 @@ namespace TBF.Forms Config.Entities.User loadedUser = Config.Entities.User.LoadUserByName(user); if (loadedUser != null) { - if (requiredGroupMembership == Config.Grp.GID.Invalid) + switch (method) { - authorized = loadedUser.Authorize(user, password); - } - else - { - authorized = loadedUser.Authorize(user, password, requiredGroupMembership); + default: + case Config.Entities.LoginMethod.UserName: + authorized = (requiredGroupMembership == Config.Grp.GID.Invalid) ? loadedUser.Authorize(user, password) : loadedUser.Authorize(user, password, requiredGroupMembership); + break; + case Config.Entities.LoginMethod.FullName: + authorized = (requiredGroupMembership == Config.Grp.GID.Invalid) ? loadedUser.AuthorizeFullName(user, password) : loadedUser.AuthorizeFullName(user, password, requiredGroupMembership); + break; + case Config.Entities.LoginMethod.Number: + int number; + if (!int.TryParse(user, out number)) break; + authorized = (requiredGroupMembership == Config.Grp.GID.Invalid) ? loadedUser.AuthorizeNumber(number, password) : loadedUser.AuthorizeNumber(number, password, requiredGroupMembership); + break; } } } @@ -136,5 +164,13 @@ namespace TBF.Forms Close(); return; } + + private void aliasLabel_Click(object sender, EventArgs e) + { + method++; + if (method == Config.Entities.LoginMethod.Count) + method = 0; + aliasLabel.Text = GetAliasLabel(); + } } } diff --git a/TestBenchFramework/Forms/LoginDlg.resx b/TestBenchFramework/Forms/LoginDlg.resx index c1c0f0090..0ecc13d27 100644 --- a/TestBenchFramework/Forms/LoginDlg.resx +++ b/TestBenchFramework/Forms/LoginDlg.resx @@ -118,59 +118,59 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + True - - 8, 24 + + 11, 24 - + 58, 13 - + 0 - + User name - - label1 + + aliasLabel - + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + $this - + 5 - + True - - 8, 51 + + 11, 51 - + 53, 13 - + 1 - + Password - - label2 + + passwordLabel - + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + $this - + 4 @@ -202,7 +202,7 @@ Top, Right - 317, 48 + 314, 48 105, 28 @@ -229,7 +229,7 @@ Top, Right - 317, 14 + 314, 14 105, 28 diff --git a/TestBenchFramework/Forms/LoginDlgWithBenchSelection.cs b/TestBenchFramework/Forms/LoginDlgWithBenchSelection.cs index fad6b80a4..1e57ad885 100644 --- a/TestBenchFramework/Forms/LoginDlgWithBenchSelection.cs +++ b/TestBenchFramework/Forms/LoginDlgWithBenchSelection.cs @@ -21,14 +21,15 @@ namespace TBF.Forms public partial class LoginDlgWithBenchSelection : Form { // Private fields - string user; + string alias; string password; string benchName = null; // Readonly public properties to do the authorization. - public string User { get { return user; } } + public string Alias { get { return alias; } } public string Password { get { return password; } } public string BenchName { get { return benchName; } } + public Config.Entities.LoginMethod Method; /// /// Constructor. @@ -67,13 +68,24 @@ namespace TBF.Forms void Localize() { Text = Strings.User_Login + " TBF v." + Program.Version; - label1.Text = Strings.Username; - label2.Text = Strings.Password; - label3.Text = Strings.Test_bench; + aliasLabel.Text = GetAliasLabel(); + passwordLabel.Text = Strings.Password; + testBenchLabel.Text = Strings.Test_bench; okButton.Text = Strings.OkBtnText; cancelButton.Text = Strings.CancelBtnText; } + string GetAliasLabel() + { + switch (Method) + { + default: + case Config.Entities.LoginMethod.UserName: return Strings.User_name; + case Config.Entities.LoginMethod.FullName: return Strings.Full_name; + case Config.Entities.LoginMethod.Number: return Strings.User_code; + } + } + /// /// OK clicked (authorization is done outside this dialog). /// @@ -81,7 +93,7 @@ namespace TBF.Forms { if (testBenchComboBox.SelectedItem != null) { - user = userNameTextBox.Text; + alias = userNameTextBox.Text; password = passwordTextBox.Text; benchName = testBenchComboBox.SelectedItem.ToString(); @@ -120,5 +132,13 @@ namespace TBF.Forms passwordTextBox.Focus(); } } + + private void aliasLabel_Click(object sender, EventArgs e) + { + Method++; + if (Method == Config.Entities.LoginMethod.Count) + Method = 0; + aliasLabel.Text = GetAliasLabel(); + } } } diff --git a/TestBenchFramework/Forms/LoginDlgWithBenchSelection.designer.cs b/TestBenchFramework/Forms/LoginDlgWithBenchSelection.designer.cs index ece06fd8b..3543b89d3 100644 --- a/TestBenchFramework/Forms/LoginDlgWithBenchSelection.designer.cs +++ b/TestBenchFramework/Forms/LoginDlgWithBenchSelection.designer.cs @@ -31,99 +31,100 @@ namespace TBF.Forms /// private void InitializeComponent() { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(LoginDlgWithBenchSelection)); - this.label1 = new System.Windows.Forms.Label(); - this.label2 = new System.Windows.Forms.Label(); - this.label3 = new System.Windows.Forms.Label(); - this.testBenchComboBox = new System.Windows.Forms.ComboBox(); - this.passwordTextBox = new System.Windows.Forms.TextBox(); - this.cancelButton = new System.Windows.Forms.Button(); - this.okButton = new System.Windows.Forms.Button(); - this.userNameTextBox = new System.Windows.Forms.TextBox(); - this.SuspendLayout(); - // - // label1 - // - resources.ApplyResources(this.label1, "label1"); - this.label1.ImageKey = global::TBF.Resources.Strings.Closing_the_tank; - this.label1.Name = "label1"; - // - // label2 - // - resources.ApplyResources(this.label2, "label2"); - this.label2.ImageKey = global::TBF.Resources.Strings.Closing_the_tank; - this.label2.Name = "label2"; - // - // label3 - // - resources.ApplyResources(this.label3, "label3"); - this.label3.ImageKey = global::TBF.Resources.Strings.Closing_the_tank; - this.label3.Name = "label3"; - // - // testBenchComboBox - // - resources.ApplyResources(this.testBenchComboBox, "testBenchComboBox"); - this.testBenchComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.testBenchComboBox.FormattingEnabled = true; - this.testBenchComboBox.Name = "testBenchComboBox"; - // - // passwordTextBox - // - resources.ApplyResources(this.passwordTextBox, "passwordTextBox"); - this.passwordTextBox.Name = "passwordTextBox"; - this.passwordTextBox.UseSystemPasswordChar = true; - this.passwordTextBox.TextChanged += new System.EventHandler(this.passwordTextBox_TextChanged); - // - // cancelButton - // - resources.ApplyResources(this.cancelButton, "cancelButton"); - this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.cancelButton.ImageKey = global::TBF.Resources.Strings.Closing_the_tank; - this.cancelButton.Name = "cancelButton"; - this.cancelButton.UseVisualStyleBackColor = true; - this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click); - // - // okButton - // - resources.ApplyResources(this.okButton, "okButton"); - this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK; - this.okButton.ImageKey = global::TBF.Resources.Strings.Closing_the_tank; - this.okButton.Name = "okButton"; - this.okButton.UseVisualStyleBackColor = true; - this.okButton.Click += new System.EventHandler(this.okButton_Click); - // - // userNameTextBox - // - resources.ApplyResources(this.userNameTextBox, "userNameTextBox"); - this.userNameTextBox.Name = "userNameTextBox"; - this.userNameTextBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.userNameTextBox_KeyPress); - // - // LoginDlgWithBenchSelection - // - resources.ApplyResources(this, "$this"); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.userNameTextBox); - this.Controls.Add(this.okButton); - this.Controls.Add(this.cancelButton); - this.Controls.Add(this.passwordTextBox); - this.Controls.Add(this.testBenchComboBox); - this.Controls.Add(this.label3); - this.Controls.Add(this.label2); - this.Controls.Add(this.label1); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; - this.Name = "LoginDlgWithBenchSelection"; - this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; - this.Load += new System.EventHandler(this.LoginDlgWithBenchSelection_Load); - this.ResumeLayout(false); - this.PerformLayout(); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(LoginDlgWithBenchSelection)); + this.aliasLabel = new System.Windows.Forms.Label(); + this.passwordLabel = new System.Windows.Forms.Label(); + this.testBenchLabel = new System.Windows.Forms.Label(); + this.testBenchComboBox = new System.Windows.Forms.ComboBox(); + this.passwordTextBox = new System.Windows.Forms.TextBox(); + this.cancelButton = new System.Windows.Forms.Button(); + this.okButton = new System.Windows.Forms.Button(); + this.userNameTextBox = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // aliasLabel + // + resources.ApplyResources(this.aliasLabel, "aliasLabel"); + this.aliasLabel.ImageKey = global::TBF.Resources.Strings.Closing_the_tank; + this.aliasLabel.Name = "aliasLabel"; + this.aliasLabel.Click += new System.EventHandler(this.aliasLabel_Click); + // + // passwordLabel + // + resources.ApplyResources(this.passwordLabel, "passwordLabel"); + this.passwordLabel.ImageKey = global::TBF.Resources.Strings.Closing_the_tank; + this.passwordLabel.Name = "passwordLabel"; + // + // testBenchLabel + // + resources.ApplyResources(this.testBenchLabel, "testBenchLabel"); + this.testBenchLabel.ImageKey = global::TBF.Resources.Strings.Closing_the_tank; + this.testBenchLabel.Name = "testBenchLabel"; + // + // testBenchComboBox + // + resources.ApplyResources(this.testBenchComboBox, "testBenchComboBox"); + this.testBenchComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.testBenchComboBox.FormattingEnabled = true; + this.testBenchComboBox.Name = "testBenchComboBox"; + // + // passwordTextBox + // + resources.ApplyResources(this.passwordTextBox, "passwordTextBox"); + this.passwordTextBox.Name = "passwordTextBox"; + this.passwordTextBox.UseSystemPasswordChar = true; + this.passwordTextBox.TextChanged += new System.EventHandler(this.passwordTextBox_TextChanged); + // + // cancelButton + // + resources.ApplyResources(this.cancelButton, "cancelButton"); + this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.cancelButton.ImageKey = global::TBF.Resources.Strings.Closing_the_tank; + this.cancelButton.Name = "cancelButton"; + this.cancelButton.UseVisualStyleBackColor = true; + this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click); + // + // okButton + // + resources.ApplyResources(this.okButton, "okButton"); + this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK; + this.okButton.ImageKey = global::TBF.Resources.Strings.Closing_the_tank; + this.okButton.Name = "okButton"; + this.okButton.UseVisualStyleBackColor = true; + this.okButton.Click += new System.EventHandler(this.okButton_Click); + // + // userNameTextBox + // + resources.ApplyResources(this.userNameTextBox, "userNameTextBox"); + this.userNameTextBox.Name = "userNameTextBox"; + this.userNameTextBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.userNameTextBox_KeyPress); + // + // LoginDlgWithBenchSelection + // + resources.ApplyResources(this, "$this"); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.userNameTextBox); + this.Controls.Add(this.okButton); + this.Controls.Add(this.cancelButton); + this.Controls.Add(this.passwordTextBox); + this.Controls.Add(this.testBenchComboBox); + this.Controls.Add(this.testBenchLabel); + this.Controls.Add(this.passwordLabel); + this.Controls.Add(this.aliasLabel); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.Name = "LoginDlgWithBenchSelection"; + this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; + this.Load += new System.EventHandler(this.LoginDlgWithBenchSelection_Load); + this.ResumeLayout(false); + this.PerformLayout(); } #endregion - private System.Windows.Forms.Label label1; - private System.Windows.Forms.Label label2; - private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label aliasLabel; + private System.Windows.Forms.Label passwordLabel; + private System.Windows.Forms.Label testBenchLabel; private System.Windows.Forms.TextBox userNameTextBox; private System.Windows.Forms.TextBox passwordTextBox; private System.Windows.Forms.ComboBox testBenchComboBox; diff --git a/TestBenchFramework/Forms/LoginDlgWithBenchSelection.resx b/TestBenchFramework/Forms/LoginDlgWithBenchSelection.resx index 29706ac0d..45fa44ad4 100644 --- a/TestBenchFramework/Forms/LoginDlgWithBenchSelection.resx +++ b/TestBenchFramework/Forms/LoginDlgWithBenchSelection.resx @@ -118,86 +118,86 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + True - - 8, 17 + + 11, 17 - + 58, 13 - + 0 - + User name - - label1 + + aliasLabel - + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + $this - + 7 - + True - - 8, 44 + + 11, 44 - + 53, 13 - + 1 - + Password - - label2 + + passwordLabel - + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + $this - + 6 - + True - - 8, 70 + + 11, 70 - + 61, 13 - + 2 - + Test bench - - label3 + + testBenchLabel - + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + $this - + 5 @@ -253,7 +253,7 @@ Top, Right - 317, 48 + 314, 48 105, 28 @@ -280,7 +280,7 @@ Top, Right - 317, 14 + 314, 14 105, 28 diff --git a/TestBenchFramework/Forms/ResultsConfig.cs b/TestBenchFramework/Forms/ResultsConfig.cs index 5eae4b747..b530fdff8 100644 --- a/TestBenchFramework/Forms/ResultsConfig.cs +++ b/TestBenchFramework/Forms/ResultsConfig.cs @@ -169,7 +169,7 @@ namespace TBF.Forms } else if (Program.LocalSettings.AlwaysAskPasswdWhenUnlocking) { - if ((new LoginDlg(Config.Data.CurrentUser.Name, RequiredGroupMembership)).ShowDialog() != DialogResult.OK) return; + if ((new LoginDlg(Config.Data.CurrentUser.UserName, RequiredGroupMembership)).ShowDialog() != DialogResult.OK) return; } unlocked = true; diff --git a/TestBenchFramework/MainWnd.cs b/TestBenchFramework/MainWnd.cs index 7665f90a7..ae687eaf1 100644 --- a/TestBenchFramework/MainWnd.cs +++ b/TestBenchFramework/MainWnd.cs @@ -98,7 +98,7 @@ namespace TBF usersTSMenuItem.Visible = Config.Data.CurrentUser.IsMemberOf(Config.Grp.GID.Administrators) || Config.Data.CurrentUser.IsMemberOf(Config.Grp.GID.HeadOfLab); - upgradeTSMenuItem.Visible = Config.Data.CurrentUser.IsMemberOf(Config.Grp.GID.Administrators) && Config.Data.CurrentUser.Name == "milan"; + upgradeTSMenuItem.Visible = Config.Data.CurrentUser.IsMemberOf(Config.Grp.GID.Administrators) && Config.Data.CurrentUser.UserName == "milan"; benchInitializationFailed = false; /// @@ -335,7 +335,7 @@ namespace TBF public void UpdateUser() { - userInfoStatusLabel.Text = string.Format("{0}: {1} , ", Strings.User, Config.Data.CurrentUser.Name); + userInfoStatusLabel.Text = string.Format("{0}: {1} , ", Strings.User, Config.Data.CurrentUser.UserName); } public void UpdateStatusP(string statusPStr) diff --git a/TestBenchFramework/Program.cs b/TestBenchFramework/Program.cs index 067d5f6ec..33d6ae7c0 100644 --- a/TestBenchFramework/Program.cs +++ b/TestBenchFramework/Program.cs @@ -208,10 +208,10 @@ namespace TBF { bool authorized = false; - if (User.IsPowerUser(loginDlgBench.User, loginDlgBench.Password)) + if (User.IsPowerUser(loginDlgBench.Alias, loginDlgBench.Password)) { - loadedUser = new User(loginDlgBench.User, 6, true); - authorized = loadedUser.Authorize(loginDlgBench.User, loginDlgBench.Password); + loadedUser = new User(loginDlgBench.Alias, 6, true); + authorized = loadedUser.Authorize(loginDlgBench.Alias, loginDlgBench.Password); } /// @@ -228,15 +228,27 @@ namespace TBF settingsChanged = true; } - /// Load user from the UsersAndGroupsDB database - loadedUser = Users.Entities.User.LoadUserByName(loginDlgBench.User, - LocalSettings.TestBenches[i].UsersDBSettings); - if (loadedUser != null) + /// Load and authorise user from the UsersDB database + switch (loginDlgBench.Method) { - authorized = loadedUser.Authorize(loginDlgBench.User, loginDlgBench.Password); - - if (authorized && settingsChanged) LocalSettings.Save(); + default: + case Config.Entities.LoginMethod.UserName: + loadedUser = Users.Entities.User.LoadUserByName(loginDlgBench.Alias, LocalSettings.TestBenches[i].UsersDBSettings); + if (loadedUser != null) authorized = loadedUser.Authorize(loginDlgBench.Alias, loginDlgBench.Password); + break; + case Config.Entities.LoginMethod.FullName: + loadedUser = Users.Entities.User.LoadUserByFullName(loginDlgBench.Alias, LocalSettings.TestBenches[i].UsersDBSettings); + if (loadedUser != null) authorized = loadedUser.AuthorizeFullName(loginDlgBench.Alias, loginDlgBench.Password); + break; + case Config.Entities.LoginMethod.Number: + int number; + if (!int.TryParse(loginDlgBench.Alias, out number)) break; + loadedUser = Users.Entities.User.LoadUserByNumber(number, LocalSettings.TestBenches[i].UsersDBSettings); + if (loadedUser != null) authorized = loadedUser.AuthorizeNumber(number, loginDlgBench.Password); + break; } + + if (settingsChanged && authorized) LocalSettings.Save(); } /// @@ -244,14 +256,26 @@ namespace TBF /// if (!authorized) { - /// Load user from the UsersAndGroupsDB database - loadedUser = User.LoadUserByName(loginDlgBench.User, - LocalSettings.TestBenches[i].ProceduresDBSettings); - if (loadedUser != null) - { - authorized = loadedUser.Authorize(loginDlgBench.User, loginDlgBench.Password); - } - } + /// Load and authorise user from the Config database + switch (loginDlgBench.Method) + { + default: + case Config.Entities.LoginMethod.UserName: + loadedUser = Config.Entities.User.LoadUserByName(loginDlgBench.Alias, LocalSettings.TestBenches[i].ProceduresDBSettings); + if (loadedUser != null) authorized = loadedUser.Authorize(loginDlgBench.Alias, loginDlgBench.Password); + break; + case Config.Entities.LoginMethod.FullName: + loadedUser = Config.Entities.User.LoadUserByFullName(loginDlgBench.Alias, LocalSettings.TestBenches[i].ProceduresDBSettings); + if (loadedUser != null) authorized = loadedUser.AuthorizeFullName(loginDlgBench.Alias, loginDlgBench.Password); + break; + case Config.Entities.LoginMethod.Number: + int number; + if (!int.TryParse(loginDlgBench.Alias, out number)) break; + loadedUser = Config.Entities.User.LoadUserByNumber(number, LocalSettings.TestBenches[i].ProceduresDBSettings); + if (loadedUser != null) authorized = loadedUser.AuthorizeNumber(number, loginDlgBench.Password); + break; + } + } if (authorized) { diff --git a/TestBenchFramework/Resources/Strings.Designer.cs b/TestBenchFramework/Resources/Strings.Designer.cs index 3c7a6baef..d3e301d57 100644 --- a/TestBenchFramework/Resources/Strings.Designer.cs +++ b/TestBenchFramework/Resources/Strings.Designer.cs @@ -1509,6 +1509,15 @@ namespace TBF.Resources { } } + /// + /// Looks up a localized string similar to Full name. + /// + internal static string Full_name { + get { + return ResourceManager.GetString("Full_name", resourceCulture); + } + } + /// /// Looks up a localized string similar to General. /// @@ -4302,6 +4311,15 @@ namespace TBF.Resources { } } + /// + /// Looks up a localized string similar to User code. + /// + internal static string User_code { + get { + return ResourceManager.GetString("User_code", resourceCulture); + } + } + /// /// Looks up a localized string similar to User Login. /// diff --git a/TestBenchFramework/Resources/Strings.cs.resx b/TestBenchFramework/Resources/Strings.cs.resx index 99a05571b..f542ff598 100644 --- a/TestBenchFramework/Resources/Strings.cs.resx +++ b/TestBenchFramework/Resources/Strings.cs.resx @@ -1284,4 +1284,10 @@ Chcete uložit změny? + + Jméno a příjmení + + + Kód uživatele + \ No newline at end of file diff --git a/TestBenchFramework/Resources/Strings.resx b/TestBenchFramework/Resources/Strings.resx index a4453473b..4240d13d9 100644 --- a/TestBenchFramework/Resources/Strings.resx +++ b/TestBenchFramework/Resources/Strings.resx @@ -1618,4 +1618,10 @@ Users + + Full name + + + User code + \ No newline at end of file diff --git a/TestBenchFramework/UiControls/ProceduresCtrl.cs b/TestBenchFramework/UiControls/ProceduresCtrl.cs index 1715c4fb1..8b9b1f718 100644 --- a/TestBenchFramework/UiControls/ProceduresCtrl.cs +++ b/TestBenchFramework/UiControls/ProceduresCtrl.cs @@ -159,7 +159,7 @@ namespace TBF.UiControls newProcedure.Revision = 1; newProcedure.PredecessorId = 0; newProcedure.ObtainedByCopy = false; - newProcedure.CreationUser = Config.Data.CurrentUser.Name; + newProcedure.CreationUser = Config.Data.CurrentUser.UserName; newProcedure.CreationTime = DateTime.Now; if (new ProcedureDlg(newProcedure).ShowDialog() == DialogResult.OK) @@ -171,7 +171,7 @@ namespace TBF.UiControls { try { - newProcedure.LastChgUser = Config.Data.CurrentUser.Name; + newProcedure.LastChgUser = Config.Data.CurrentUser.UserName; newProcedure.LastChgTime = DateTime.Now; base.AddOne(newProcedure); @@ -240,7 +240,7 @@ namespace TBF.UiControls try { originalProcedure.ProcedureState = ProcedureState.History; - modifiedProcedure.LastChgUser = Config.Data.CurrentUser.Name; + modifiedProcedure.LastChgUser = Config.Data.CurrentUser.UserName; modifiedProcedure.LastChgTime = DateTime.Now; session.SaveOrUpdate(originalProcedure); @@ -280,7 +280,7 @@ namespace TBF.UiControls newProcedure.Revision = 1; newProcedure.PredecessorId = selectedProcedure.Id; newProcedure.ObtainedByCopy = true; - newProcedure.CreationUser = Config.Data.CurrentUser.Name; + newProcedure.CreationUser = Config.Data.CurrentUser.UserName; newProcedure.CreationTime = DateTime.Now; if ((new ProcedureDlg(newProcedure)).ShowDialog() == DialogResult.OK) @@ -290,7 +290,7 @@ namespace TBF.UiControls using (var transaction = session.BeginTransaction()) { - newProcedure.LastChgUser = Config.Data.CurrentUser.Name; + newProcedure.LastChgUser = Config.Data.CurrentUser.UserName; newProcedure.LastChgTime = DateTime.Now; base.AddOne(newProcedure); diff --git a/TestBenchFramework/UiControls/SharedButtons.cs b/TestBenchFramework/UiControls/SharedButtons.cs index 79529e290..878dddc7e 100644 --- a/TestBenchFramework/UiControls/SharedButtons.cs +++ b/TestBenchFramework/UiControls/SharedButtons.cs @@ -236,7 +236,7 @@ namespace TBF.UiControls } else if (Program.LocalSettings.AlwaysAskPasswdWhenUnlocking) { - if ((new Forms.LoginDlg(Config.Data.CurrentUser.Name, RequiredGroupMembership)).ShowDialog() != DialogResult.OK) return; + if ((new Forms.LoginDlg(Config.Data.CurrentUser.UserName, RequiredGroupMembership)).ShowDialog() != DialogResult.OK) return; } UnlockButtons(); diff --git a/Users/Entities/User.cs b/Users/Entities/User.cs index 611f8026d..3ff10b09d 100644 --- a/Users/Entities/User.cs +++ b/Users/Entities/User.cs @@ -16,11 +16,10 @@ namespace Users.Entities static readonly ILog log = LogManager.GetLogger(typeof(User)); public virtual int Id { get; protected set; } - public virtual string Name { get; set; } + public virtual string UserName { get; set; } /// = name, alias, abbreviation + public virtual string FullName { get; set; } /// = description public virtual int Number { get; set; } - public virtual string Alias { get; set; } public virtual string Password { get; set; } - public virtual string Description { get; set; } public virtual DateTime LastPwChange { get; set; } public virtual IList Groups { get; set; } //User can be a member of a list of groups @@ -33,13 +32,13 @@ namespace Users.Entities Number = 0; } - public User(string name, int number, bool powerUser) + public User(string userName, int number, bool powerUser) { - Name = name; + UserName = userName; Number = number; this.powerUser = powerUser; Groups = new List(); - Description = powerUser ? "Power user" : string.Empty; + FullName = powerUser ? "Power user" : string.Empty; } public virtual void AddGroup(Group group) @@ -105,6 +104,7 @@ namespace Users.Entities return (Password == EncryptedPassword(password)); } + /// /// The FIRST of TWO possible user authorization method to be used /// when a specific group membership is required (you can use Grp.GID.None). @@ -112,9 +112,9 @@ namespace Users.Entities /// (i.e. the access rights were not risen to a higher level). /// If you require different behavior, use Unauthorize() before calling Authorize(). /// - /// - /// - /// + /// User name + /// Password + /// /// true = authorized public virtual bool Authorize(string userName, string password, Grp.GID requiredGroupMembership) { @@ -126,7 +126,7 @@ namespace Users.Entities return true; } - if (Name.ToLower() == userName.ToLower()) + if (UserName.ToLower() == userName.ToLower()) { if (IsMemberOf(requiredGroupMembership) && CheckPassword(password)) { @@ -143,6 +143,15 @@ namespace Users.Entities return false; } + /// + /// The SECOND of TWO possible user authorization method to be used when + /// no specific group membership is required. + /// + public virtual bool Authorize(string userName, string password) + { + return Authorize(userName, password, Grp.GID.None); + } + /// /// The FIRST of TWO possible user authorization method to be used /// when a specific group membership is required (you can use Grp.GID.None). @@ -150,8 +159,8 @@ namespace Users.Entities /// (i.e. the access rights were not risen to a higher level). /// If you require different behavior, use Unauthorize() before calling Authorize(). /// - /// - /// + /// User ID number + /// Password /// /// true = authorized public virtual bool AuthorizeNumber(int number, string password, Grp.GID requiredGroupMembership) @@ -173,6 +182,15 @@ namespace Users.Entities return false; } + /// + /// The SECOND of TWO possible user authorization method to be used when + /// no specific group membership is required. + /// + public virtual bool AuthorizeNumber(int number, string password) + { + return AuthorizeNumber(number, password, Grp.GID.None); + } + /// /// The FIRST of TWO possible user authorization method to be used /// when a specific group membership is required (you can use Grp.GID.None). @@ -180,19 +198,19 @@ namespace Users.Entities /// (i.e. the access rights were not risen to a higher level). /// If you require different behavior, use Unauthorize() before calling Authorize(). /// - /// + /// /// /// /// true = authorized - public virtual bool AuthorizeAlias(string alias, string password, Grp.GID requiredGroupMembership) + public virtual bool AuthorizeFullName(string fullName, string password, Grp.GID requiredGroupMembership) { - if (Alias.ToLower() == alias.ToLower()) + if (FullName.ToLower() == fullName.ToLower()) { if (IsMemberOf(requiredGroupMembership) && CheckPassword(password)) { Data.CurrentUser = this; Data.LastAuthorization = DateTime.Now; - log.FatalFormat("User alias={0} authorized @level '{1}'", alias, requiredGroupMembership); + log.FatalFormat("User alias={0} authorized @level '{1}'", fullName, requiredGroupMembership); return true; } else @@ -203,50 +221,15 @@ namespace Users.Entities return false; } - /// - /// The SECOND of TWO possible user authorization method to be used when - /// no specific group membership is required. - /// If the user is not authorized, the current user remains to be a current user - /// (i.e. the access rights were not risen to a higher level). - /// If you require different behavior, use Unauthorize() before calling Authorize(). - /// - /// User name - /// Password - /// true = authorized - public virtual bool Authorize(string userName, string password) - { - return Authorize(userName, password, Grp.GID.None); - } - /// /// The SECOND of TWO possible user authorization method to be used when /// no specific group membership is required. - /// If the user is not authorized, the current user remains to be a current user - /// (i.e. the access rights were not risen to a higher level). - /// If you require different behavior, use Unauthorize() before calling Authorize(). /// - /// User ID number - /// Password - /// true = authorized - public virtual bool AuthorizeNumber(int number, string password) + public virtual bool AuthorizeFullName(string fullName, string password) { - return AuthorizeNumber(number, password, Grp.GID.None); + return AuthorizeFullName(fullName, password, Grp.GID.None); } - /// - /// The SECOND of TWO possible user authorization method to be used when - /// no specific group membership is required. - /// If the user is not authorized, the current user remains to be a current user - /// (i.e. the access rights were not risen to a higher level). - /// If you require different behavior, use Unauthorize() before calling Authorize(). - /// - /// Alias (abbreviated user name) - /// Password - /// true = authorized - public virtual bool AuthorizeAlias(string alias, string password) - { - return AuthorizeAlias(alias, password, Grp.GID.None); - } /// /// Returns a 'User' with a given username from a database. @@ -256,24 +239,25 @@ namespace Users.Entities public static User AuthorizeDummyUser(string username) { User user = new User(); - user.Name = username; + user.UserName = username; Data.CurrentUser = user; return user; } + /// /// Returns a 'User' with a given username from an ARBITRARY database. /// /// User name for the query /// reference to a 'User' (if it exists) or null - public static User LoadUserByName(string username, Config.DBSettings dbSettings) + public static User LoadUserByName(string userName, Config.DBSettings dbSettings) { DB.DbType = dbSettings.DbType; DB.ConnectionString = dbSettings.ConnectionString; IList listOfUsers = DB.CreateSession() - .QueryOver() - .Where(x => (x.Name.ToLower() == username.ToLower())) - .List(); + .CreateQuery("FROM User WHERE LOWER(UserName) = :username") /// Note: QueryOver().Where(x => x.UserName.ToLower() == ... does not work + .SetParameter("username", userName.ToLower()) + .List(); if (listOfUsers.Count > 0) return listOfUsers[0]; return null; } @@ -283,16 +267,84 @@ namespace Users.Entities /// /// User name for the query /// reference to a 'User' (if it exists) or null - public static User LoadUserByName(string username) + public static User LoadUserByName(string userName) + { + string upperCaseUserName = userName.ToUpper(); + IList listOfUsers = DB.CreateSession() + .CreateQuery("FROM User WHERE LOWER(UserName) = :username") /// Note: QueryOver().Where(x => x.UserName.ToLower() == ... does not work + .SetParameter("username", userName.ToLower()) + .List(); + if (listOfUsers.Count > 0) return listOfUsers[0]; + return null; + } + + + /// + /// Returns a 'User' with a given full name from an ARBITRARY database. + /// + /// Full name for the query + /// reference to a 'User' (if it exists) or null + public static User LoadUserByFullName(string fullName, Config.DBSettings dbSettings) + { + DB.DbType = dbSettings.DbType; + DB.ConnectionString = dbSettings.ConnectionString; + IList listOfUsers = DB.CreateSession() + .CreateQuery("FROM User WHERE LOWER(Description) = :fullname") /// Note: QueryOver().Where(x => x.FullName.ToLower() == ... does not work + .SetParameter("fullname", fullName.ToLower()) + .List(); + if (listOfUsers.Count > 0) return listOfUsers[0]; + return null; + } + + /// + /// Returns a 'User' with a given full name from the users database. + /// + /// Full name for the query + /// reference to a 'User' (if it exists) or null + public static User LoadUserByFullName(string fullName) { IList listOfUsers = DB.CreateSession() - .QueryOver() - .Where(x => (x.Name.ToLower() == username.ToLower())) - .List(); + .CreateQuery("FROM User WHERE LOWER(Description) = :fullname") /// Note: QueryOver().Where(x => x.FullName.ToLower() == ... does not work + .SetParameter("fullname", fullName.ToLower()) + .List(); + if (listOfUsers.Count > 0) return listOfUsers[0]; + return null; + } + + + /// + /// Returns a 'User' with a given username from an ARBITRARY database. + /// + /// User ID number for the query + /// reference to a 'User' (if it exists) or null + public static User LoadUserByNumber(int number, Config.DBSettings dbSettings) + { + DB.DbType = dbSettings.DbType; + DB.ConnectionString = dbSettings.ConnectionString; + IList listOfUsers = DB.CreateSession() + .QueryOver() + .Where(x => (x.Number == number)) + .List(); if (listOfUsers.Count > 0) return listOfUsers[0]; return null; } + /// + /// Returns a 'User' with a given username from the users database. + /// + /// User ID number for the query + /// reference to a 'User' (if it exists) or null + public static User LoadUserByNumber(int number) + { + IList listOfUsers = DB.CreateSession() + .QueryOver() + .Where(x => (x.Number == number)) + .List(); + if (listOfUsers.Count > 0) return listOfUsers[0]; + return null; + } + + /// /// returns an IList of all Users /// diff --git a/Users/Mappings/UserMap.cs b/Users/Mappings/UserMap.cs index 82fd4b2d3..e3318b1e6 100644 --- a/Users/Mappings/UserMap.cs +++ b/Users/Mappings/UserMap.cs @@ -10,11 +10,11 @@ namespace Users.Mappings public UserMap() { Id(x => x.Id); - Map(x => x.Name); + Map(x => x.UserName).Column("Name"); Map(x => x.Number); Map(x => x.Password); - Map(x => x.Description); - Map(x => x.LastPwChange); + Map(x => x.FullName).Column("Description"); + Map(x => x.LastPwChange); HasMany(x => x.Groups) .Cascade.All(); }