Ejemplo n.º 1
0
        private void sendFeedbackButtonClick(object sender, EventArgs e)
        {
            string feedback = feedbackTextBox.Text;
            int    score    = -1;

            if (!Int32.TryParse(scoreTextBox.Text, out score))
            {
                MessageBox.Show("Score must be an integer.");
                return;
            }
            if (score > assignment.maxScore)
            {
                MessageBox.Show("You cannot have a score higher than the maximum score.");
                return;
            }
            if (feedback.Length > 511)
            {
                MessageBox.Show("Your feedback must be shorter. Please shorten it and try again.");
                return;
            }

            APIHandler.GiveFeedback(currentStudent, assignment, score, feedback);
            MessageBox.Show("Feedback provided!");
        }
Ejemplo n.º 2
0
        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();
        }
Ejemplo n.º 3
0
        private void editLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            EditTask     edit   = new EditTask(assignment);
            DialogResult dialog = edit.ShowDialog();

            if (dialog != DialogResult.OK)
            {
                return;
            }
            // Make these local vars to prevent  "marshal-by-reference" classes - https://stackoverflow.com/questions/4178576/accessing-a-member-on-form-may-cause-a-runtime-exception-because-it-is-a-field-o
            int      newScore   = edit.newScore;
            DateTime newDueDate = edit.newDueDate;

            Dictionary <string, string> formData = new Dictionary <string, string> {
                { "title", edit.newTitle },
                { "description", edit.newDescription },
                { "max_score", newScore.ToString() },
                { "date_due", newDueDate.ToString("dd/MM/yyyy|HH:mm") }
            };

            APIHandler.EditAssignment(assignment, formData);
            ParentRefreshList();
            MessageBox.Show("Edited task successfully!");
        }
Ejemplo n.º 4
0
        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.");
                }
            }
        }
Ejemplo n.º 5
0
        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();
        }