Ongoing plethora of changes, making initial form

This commit is contained in:
Tim Young 2017-07-27 17:02:52 -05:00
parent 7151d222f8
commit 400a246d0b
5 changed files with 188 additions and 14 deletions

View File

@ -51,6 +51,8 @@ namespace EduNetworkBuilder
private List<NetworkDevice> ItemsSelected = new List<NetworkDevice>();
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();
}
}
}

View File

@ -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="";
/// <summary>
@ -21,7 +21,7 @@ namespace EduNetworkBuilder
/// </summary>
public string FullName = "";
List<string> Passwords;
List<string> Passwords = new List<string>();
string PasswordHint = "";
/// <summary>
@ -32,12 +32,36 @@ namespace EduNetworkBuilder
/// <summary>
/// Used to determine if the user we are working with is the admin account.
/// </summary>
bool isAdmin = false;
public bool isAdmin { get; private set; }
/// <summary>
/// EverCompletedPuzzles is a list of puzzles that they have completed once.
/// </summary>
List<string> EverCompletedPuzzles = new List<string>();
List<SchoolworkClass> Projects = new List<SchoolworkClass>();
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
}
}
}

View File

@ -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
//

View File

@ -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);
}
}
}

View File

@ -1693,4 +1693,52 @@
<value>Class Setup</value>
<comment>NB_ClassSetup = Class Setup</comment>
</data>
<data name="PPF_EnterUserName" xml:space="preserve">
<value>Enter a username for the teacher</value>
<comment>PPF_EnterUserName = Enter a username for the teacher</comment>
</data>
<data name="PPF_FullName" xml:space="preserve">
<value>Full Name</value>
<comment>PPF_FullName = Full Name</comment>
</data>
<data name="PPF_NewPass" xml:space="preserve">
<value>Please enter a new password</value>
<comment>PPF_NewPass = Please enter a new password</comment>
</data>
<data name="PPF_OldPassword" xml:space="preserve">
<value>Enter Old Password</value>
<comment>PPF_OldPassword = Enter Old Password</comment>
</data>
<data name="PPF_PassDidNotChange" xml:space="preserve">
<value>Password did not change. Try again.</value>
<comment>PPF_PassDidNotChange = Password did not change. Try again.</comment>
</data>
<data name="PPF_PassMismatch" xml:space="preserve">
<value>Password does not match. Try again.</value>
<comment>PPF_PassMismatch = Password does not match. Try again.</comment>
</data>
<data name="PPF_PassTooShort" xml:space="preserve">
<value>Password was too short. Try again.</value>
<comment>PPF_PassTooShort = Password was too short. Try again.</comment>
</data>
<data name="PPF_PassValidateMismatch" xml:space="preserve">
<value>Passwords did not match. Please try again.</value>
<comment>PPF_PassValidateMismatch = Passwords did not match. Please try again.</comment>
</data>
<data name="PPF_TabClasswork" xml:space="preserve">
<value>Classwork</value>
<comment>PPF_TabClasswork = Classwork</comment>
</data>
<data name="PPF_TabProfile" xml:space="preserve">
<value>Profile</value>
<comment>PPF_TabProfile = Profile</comment>
</data>
<data name="PPF_UserName" xml:space="preserve">
<value>User Name</value>
<comment>PPF_UserName = User Name</comment>
</data>
<data name="PPF_VerifyPass" xml:space="preserve">
<value>Re-Enter that same password</value>
<comment>PPF_VerifyPass = Re-Enter that same password</comment>
</data>
</root>