async private void usernameAvaliableButtonClick(object sender, EventArgs e) { /// <summary> /// Subroutine that is executed when the "Username avaliable" button is pressed when creating a teacher account. /// </summary> string adminCode = adminCodeTextBox.Text; string username = usernameRegistrationTextBox.Text; if (adminCode == "" || username == "") { MessageBox.Show("Enter the admin code, and/or a username, before you can check if a username is avaliable!"); return; } try { bool taken = await APIHandler.IsUsernameTaken(UserType.Teacher, username, adminCode : adminCode); if (!taken) { usernameAvaliableLabel.Text = "Username avaliable!"; usernameAvaliableLabel.ForeColor = Color.Green; } else { usernameAvaliableLabel.Text = "Username not avaliable, please try another."; usernameAvaliableLabel.ForeColor = Color.Red; } usernameAvaliableLabel.Show(); } catch (HttpStatusUnauthorized) { MessageBox.Show("Incorrect admin code entered."); } }
async private void editStudentButton_Click(object sender, EventArgs e) { newUsername = usernameTextBox.Text; newForename = forenameTextBox.Text; newSurname = surnameTextBox.Text; if (alpsComboBox.SelectedIndex == -1 || newUsername == "" || newForename == "" || newSurname == "") { MessageBox.Show("All fields must be entered, including the ALPs grade combobox."); return; } newAlps = alpsConverter[alpsComboBox.SelectedItem.ToString()]; if (student != null) { isNewUsername = newUsername != student.username; // If the username has changed } if ((isNewUsername && !await APIHandler.IsUsernameTaken(UserType.Student, newUsername)) || !isNewUsername) { this.DialogResult = DialogResult.OK; this.Close(); } else { MessageBox.Show("This username has already been taken, please try another."); return; } }
async private void submitChangedClick(object sender, EventArgs e) { string password = passwordTextbox1.Text; string confirmedPassword = passwordTextbox2.Text; string username = usernameTextbox.Text; string title = titleTextBox.Text; string forename = forenameTextBox.Text; string surname = surnameTextBox.Text; //passwordTextbox1.Text = ""; //passwordTextbox2.Text = ""; // Username checks if (usernameCheckBox.Checked) { if (username == "") { MessageBox.Show("Username field needs filling!"); return; } else if (username.Contains(":")) { MessageBox.Show("Username cannot contain a colon. Please remove it."); } else { bool usernameTaken = await APIHandler.IsUsernameTaken(this.userType, username); if (usernameTaken) { MessageBox.Show("Username has already been taken, please try another!"); return; } else { this.newUsername = username; } } } // Password checks if (passwordCheckBox.Checked) { // Passwords need to be included if (password == "" || confirmedPassword == "") { MessageBox.Show("Password fields need filling!"); return; } if (password != confirmedPassword) { MessageBox.Show("Passwords do not match!"); // TODO: Better way of showing this error return; } if (!User.IsPasswordValid(password)) { MessageBox.Show("Password is not of sufficient complexity!"); return; } // Password is valid at this point this.newPassword = password; } // New name checks if (nameCheckBox.Checked) { if (title == "" || forename == "" || surname == "") { MessageBox.Show("You must not leave any fields blank!"); return; } this.newTitle = title; this.newForename = forename; this.newSurname = surname; } this.DialogResult = DialogResult.OK; this.Close(); }