async private void OnRefreshButtonClick(object sender, EventArgs e) { refreshButton.Enabled = false; // Disable refresh button and show loading loadingLabel.Show(); loadingLabel.Text = "Loading your homework, please wait..."; progressBar.Show(); label3.Show(); tabController.Hide(); Homework[] tasks = await APIHandler.GetHomework(student : user, groupHardRefresh : true); tabController.UpdateTabs(disposeCurrentTabs: true, newTasks: tasks); // Provide new data to the tab controller this.user = await APIHandler.GetStudent(id : this.user.id); // Update student DecorateForm(); // Update the form accordingly (e.g. new ALPs grade, username) // TODO: Show error to re-sign-in if a teacher changes username whilst student using the program refreshButton.Enabled = true; loadingLabel.Hide(); progressBar.Hide(); label3.Hide(); tabController.Show(); }
async private void studentSignInClick(object sender, EventArgs e) { /// <summary> /// Subroutine that is executed when a student wants to sign into the program. /// It sends a GET request to the API to try and obtain student details. /// </summary> string username = usernameTextBox.Text; string password = passwordTextBox.Text; flushTextBoxes(); if (checkBox1.Checked) { if (username == "") { MessageBox.Show("Username cannot be left blank!"); return; } StudentGetPassword passwordForm = new StudentGetPassword(); var dialog = passwordForm.ShowDialog(); if (dialog == DialogResult.OK) { password = passwordForm.passwordResult; } else { MessageBox.Show("An error has occurred, please try again."); return; } // Send request to API to change password of `username` to `password` try { await APIHandler.ResetPassword(username, password); string newCredentials = WebRequestHandler.ConvertToBase64(username + ":" + password); WebRequestHandler.SetAuthorizationHeader(newCredentials); Student student = await APIHandler.GetStudent(username : username); // Get the student with username `username` from the API closedByProgram = true; // Set boolean to prevent Application.Exit() call this.Close(); // Close current form FormController.studentMain = new StudentMainForm(student); // Open the new form } catch (HttpStatusUnauthorized) { MessageBox.Show("Your account already has a password - please ask a teacher to reset your password."); return; } } else { if (username == "" || password == "") { MessageBox.Show("Username or password cannot be left blank!"); //TODO: Does this need a messagebox? Nicer way of showing error? return; // Do not execute more of the subroutine } string credentials = WebRequestHandler.ConvertToBase64(username + ":" + password); APIHandler.SetAuthorizationHeader(credentials); if (await APIHandler.IsUserValid(UserType.Student, username, password)) { Student student = await APIHandler.GetStudent(username : username); // Get the student with username `username` from the API closedByProgram = true; // Set boolean to prevent Application.Exit() call this.Close(); // Close current form FormController.studentMain = new StudentMainForm(student); // Open the new form } else { MessageBox.Show("Your account doesn't exist."); } } }