From 400a246d0b32a2c6dd5dc28934bc5b6796099ffe Mon Sep 17 00:00:00 2001 From: Tim Young Date: Thu, 27 Jul 2017 17:02:52 -0500 Subject: [PATCH] Ongoing plethora of changes, making initial form --- EduNetworkBuilder/NetworkBuilder.cs | 18 +++- EduNetworkBuilder/PersonClass.cs | 32 +++++- .../PersonProfileForm.Designer.cs | 2 + EduNetworkBuilder/PersonProfileForm.cs | 102 ++++++++++++++++-- .../Resources/languages/edustrings.resx | 48 +++++++++ 5 files changed, 188 insertions(+), 14 deletions(-) diff --git a/EduNetworkBuilder/NetworkBuilder.cs b/EduNetworkBuilder/NetworkBuilder.cs index 4796b31..dc59285 100644 --- a/EduNetworkBuilder/NetworkBuilder.cs +++ b/EduNetworkBuilder/NetworkBuilder.cs @@ -51,6 +51,8 @@ namespace EduNetworkBuilder private List ItemsSelected = new List(); private Point OrigClickPoint = new Point(-1, -1); + private PersonClass CurrentUser; + public BuilderWindow() { InitializeComponent(); @@ -380,6 +382,17 @@ namespace EduNetworkBuilder { reloadToolStripMenuItem.Enabled = false; } + + //If we already have a class setup + if (CurrentUser == null) + { + classSetupToolStripMenuItem.Visible = true; + } + else + { + classSetupToolStripMenuItem.Visible = false; + this.Text = "EduNetworkBuilder : " + CurrentUser.FullName; + } } public void UpdateLinks() @@ -1802,9 +1815,8 @@ namespace EduNetworkBuilder private void classSetupToolStripMenuItem_Click(object sender, EventArgs e) { PersonProfileForm PPF = new PersonProfileForm(); - this.Hide(); - PPF.ShowDialog(); - this.Show(); + CurrentUser = PPF.Edit(); + UpdateMenu(); } } } \ No newline at end of file diff --git a/EduNetworkBuilder/PersonClass.cs b/EduNetworkBuilder/PersonClass.cs index 525c500..e6186a0 100644 --- a/EduNetworkBuilder/PersonClass.cs +++ b/EduNetworkBuilder/PersonClass.cs @@ -6,9 +6,9 @@ using System.Threading.Tasks; namespace EduNetworkBuilder { - class PersonClass + public class PersonClass { - string filepath=""; //the path of the file. We use the username as the file-name. + public string filepath=""; //the path of the file. We use the username as the file-name. string _UserName=""; /// @@ -21,7 +21,7 @@ namespace EduNetworkBuilder /// public string FullName = ""; - List Passwords; + List Passwords = new List(); string PasswordHint = ""; /// @@ -32,12 +32,36 @@ namespace EduNetworkBuilder /// /// Used to determine if the user we are working with is the admin account. /// - bool isAdmin = false; + public bool isAdmin { get; private set; } /// /// EverCompletedPuzzles is a list of puzzles that they have completed once. /// List EverCompletedPuzzles = new List(); List Projects = new List(); + + public PersonClass(String User, bool MakeAdmin) + { + _UserName = User; + isAdmin = MakeAdmin; + } + + public string Password(int index = 0) + { + if (Passwords.Count == 0) return ""; + if (index < 0) return ""; + if (index >= Passwords.Count) return ""; + return Passwords[index]; + } + + public void ChangePassword(string NewPassword) + { + Passwords.Insert(0, NewPassword); + int maxPWs = 1; + if (isAdmin) + maxPWs = 10; //Admins store the last 10 passwords. If the admin changed his PW, we still need to decrypt the student's files + for (int a = Passwords.Count - 1; a >= maxPWs; a--) + Passwords.RemoveAt(a); //Remove all but the one password + } } } diff --git a/EduNetworkBuilder/PersonProfileForm.Designer.cs b/EduNetworkBuilder/PersonProfileForm.Designer.cs index 9f73677..703d4cd 100644 --- a/EduNetworkBuilder/PersonProfileForm.Designer.cs +++ b/EduNetworkBuilder/PersonProfileForm.Designer.cs @@ -124,6 +124,7 @@ this.btnChangePassword.TabIndex = 4; this.btnChangePassword.Text = "Change Password"; this.btnChangePassword.UseVisualStyleBackColor = true; + this.btnChangePassword.Click += new System.EventHandler(this.btnChangePassword_Click); // // btnExit // @@ -134,6 +135,7 @@ this.btnExit.TabIndex = 1; this.btnExit.Text = "Exit"; this.btnExit.UseVisualStyleBackColor = true; + this.btnExit.Click += new System.EventHandler(this.btnExit_Click); // // tvClasswork // diff --git a/EduNetworkBuilder/PersonProfileForm.cs b/EduNetworkBuilder/PersonProfileForm.cs index 6ba46c8..aada252 100644 --- a/EduNetworkBuilder/PersonProfileForm.cs +++ b/EduNetworkBuilder/PersonProfileForm.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using System.IO; namespace EduNetworkBuilder { @@ -18,17 +19,26 @@ namespace EduNetworkBuilder public PersonProfileForm(string filename = "") { InitializeComponent(); - - Icon = Properties.Resources.NBIco; - LanguagifyComponents(); FileName = filename; //We do LocalSetup at load time. This saves us some grief. } + public PersonProfileForm(PersonClass User) + { + InitializeComponent(); + CurrentUser = User; + if (CurrentUser != null) + { + FileName = Path.Combine(CurrentUser.filepath, CurrentUser.UserName); + } + //We do LocalSetup at load time. This saves us some grief. + } + private void PersonProfileForm_Load(object sender, EventArgs e) { LocalSetup(); + UpdateFormFromUser(); } private void LanguagifyComponents() @@ -42,19 +52,97 @@ namespace EduNetworkBuilder private void LocalSetup() { - if(FileName == "") + Icon = Properties.Resources.NBIco; + LanguagifyComponents(); + + if (CurrentUser == null && FileName == "") { //Prompt for a username - String Dest = NB.TextPromptBox("Enter a username for the teacher."); + String Dest = NB.TextPromptBox(NB.Translate("PPF_EnterUserName")); if (Dest == "") Close();//No name given or canceled. - + if (Dest[0] != '_') Dest = "_Teacher_" + Dest; //Make sure it begins with _ //Find a directory for it. + CurrentUser = new PersonClass(Dest, true); //Make an admin person class } - else + else if (CurrentUser == null) { //Try to load the file. Close form & give error if it fails } + + //Make sure we update any profile settings they change + tbFullName.LostFocus += SaveUserInfoFromForm; } + public PersonClass Edit() + { + BuilderWindow BW = NB.GetBuilderWin(); + if(BW != null) + { + BW.Hide(); + this.ShowDialog(); + BW.Show(); + } + return CurrentUser; + } + + private void UpdateFormFromUser() + { + if (CurrentUser == null) return; + + tbFullName.Text = CurrentUser.FullName; + tbUsername.Text = CurrentUser.UserName; + if (CurrentUser.isAdmin) this.Text = "Admin: " + CurrentUser.UserName; + else this.Text = "Student: " + CurrentUser.UserName; + } + + private void SaveUserInfoFromForm() + { + CurrentUser.FullName = tbFullName.Text; + } + + private void SaveUserInfoFromForm(object sender, EventArgs e) + { + SaveUserInfoFromForm(); + } + + private void btnExit_Click(object sender, EventArgs e) + { + //Save during closing + Close(); + } + + private void btnChangePassword_Click(object sender, EventArgs e) + { + string OldPassword = ""; + if (CurrentUser.Password() != "") + { + OldPassword = NB.TextPromptBox(NB.Translate("PPF_OldPassword"), Properties.Resources.NBIco, true); + if(OldPassword != CurrentUser.Password()) + { + MessageBox.Show(NB.Translate("PPF_PassMismatch")); + return; + } + } + //The passwords match, or there was no initial password. + string Password1 = NB.TextPromptBox(NB.Translate("PPF_NewPass"), Properties.Resources.NBIco, true); + if(Password1.Length < 4) + { + MessageBox.Show(NB.Translate("PPF_PassTooShort")); + return; + } + if(Password1 == OldPassword) + { + MessageBox.Show(NB.Translate("PPF_PassDidNotChange")); + return; + } + string Password2 = NB.TextPromptBox(NB.Translate("PPF_VerifyPass"), Properties.Resources.NBIco, true); + if(Password1 != Password2) + { + MessageBox.Show(NB.Translate("PPF_PassValidateMismatch")); + return; + } + + CurrentUser.ChangePassword(Password1); + } } } \ No newline at end of file diff --git a/EduNetworkBuilder/Resources/languages/edustrings.resx b/EduNetworkBuilder/Resources/languages/edustrings.resx index 17c376e..90e49b6 100644 --- a/EduNetworkBuilder/Resources/languages/edustrings.resx +++ b/EduNetworkBuilder/Resources/languages/edustrings.resx @@ -1693,4 +1693,52 @@ Class Setup NB_ClassSetup = Class Setup + + Enter a username for the teacher + PPF_EnterUserName = Enter a username for the teacher + + + Full Name + PPF_FullName = Full Name + + + Please enter a new password + PPF_NewPass = Please enter a new password + + + Enter Old Password + PPF_OldPassword = Enter Old Password + + + Password did not change. Try again. + PPF_PassDidNotChange = Password did not change. Try again. + + + Password does not match. Try again. + PPF_PassMismatch = Password does not match. Try again. + + + Password was too short. Try again. + PPF_PassTooShort = Password was too short. Try again. + + + Passwords did not match. Please try again. + PPF_PassValidateMismatch = Passwords did not match. Please try again. + + + Classwork + PPF_TabClasswork = Classwork + + + Profile + PPF_TabProfile = Profile + + + User Name + PPF_UserName = User Name + + + Re-Enter that same password + PPF_VerifyPass = Re-Enter that same password + \ No newline at end of file