Skip to content

Commit

Permalink
Merge pull request #71 from CSC207-2022F-UofT/5-feature-1-user-regist…
Browse files Browse the repository at this point in the history
…ration-&-log-in

5 feature 1 user registration & log in
  • Loading branch information
CC-3636 authored Dec 5, 2022
2 parents 3f503f1 + 5b4e35f commit 055a04a
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 141 deletions.
9 changes: 2 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
plugins {
id 'groovy'
id 'java'
}

Expand All @@ -8,10 +7,8 @@ repositories {
}

dependencies {
implementation 'junit:junit:4.13.2'
//testImplementation('org.junit.jupiter:junit-jupiter:5.9.0')
testImplementation(enforcedPlatform('org.junit:junit-bom:5.9.0')) // JUnit 5 BOM
testImplementation("org.junit.jupiter:junit-jupiter")
implementation 'junit:junit:4.13.1'
testImplementation('org.junit.jupiter:junit-jupiter:5.6.0')
}

test {
Expand All @@ -20,5 +17,3 @@ test {
events "passed", "skipped", "failed"
}
}

ext['junit-jupiter.version'] = '5.9.0'
14 changes: 12 additions & 2 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
import use_cases.login_registration.login_usecase.LoginInputBoundary;
import use_cases.login_registration.login_usecase.LoginInteractor;
import use_cases.login_registration.login_usecase.LoginPresenter;
import use_cases.login_registration.logout_usecase.LogoutGateway;
import use_cases.login_registration.logout_usecase.LogoutInputBoundary;
import use_cases.login_registration.logout_usecase.LogoutInteractor;
import use_cases.login_registration.logout_usecase.LogoutPresenter;
import use_cases.login_registration.user_register_usecase.*;
import screens.task_management.FileTaskMap;

Expand Down Expand Up @@ -93,6 +97,12 @@ public static void main(String[] args) throws IOException, ClassNotFoundExceptio
CourseEnrolmentInputBoundary enrolmentInteractor = new CourseEnrolmentInteractor(enrolCourse, tasksToTodolist, enrolmentPresenter);
CourseEnrolmentController enrolmentController = new CourseEnrolmentController(enrolmentInteractor);

// Adding in logout use case
LogoutGateway logoutUser = new FileUser("src/main/java/data/users.ser");
LogoutInputBoundary logoutInteractor = new LogoutInteractor(logoutUser);
LogoutController logoutController = new LogoutController(logoutInteractor);
//

// Build the GUI
StudentChooseTaskCreateScreen chooseStudentTask = new StudentChooseTaskCreateScreen(schedulerPresenter, scheduleConflictPresenter,
screens, cardLayout);
Expand All @@ -116,7 +126,7 @@ public static void main(String[] args) throws IOException, ClassNotFoundExceptio
CourseEnrolmentScreen courseEnrolmentScreen = new CourseEnrolmentScreen(enrolmentController, screens, cardLayout);
screens.add("courseEnrol", courseEnrolmentScreen);

StudentMainScreen studentMainScreen = new StudentMainScreen((StudentUser)user, screens, cardLayout);
StudentMainScreen studentMainScreen = new StudentMainScreen(screens, cardLayout, logoutController);
screens.add("StudentMain", studentMainScreen);

RegisterScreen registerScreen = new RegisterScreen(userRegisterController, cardLayout, screens);
Expand All @@ -125,7 +135,7 @@ public static void main(String[] args) throws IOException, ClassNotFoundExceptio
LoginScreen loginScreen = new LoginScreen(loginController, cardLayout, screens);
screens.add("login", loginScreen);

InstructorMainScreen instructorMainScreen = new InstructorMainScreen(screens, cardLayout);
InstructorMainScreen instructorMainScreen = new InstructorMainScreen(screens, cardLayout, logoutController);
screens.add("InstructorMain", instructorMainScreen);

WelcomeScreen welcomeScreen = new WelcomeScreen(cardLayout, screens);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/data/courses.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
course_name,course_instructor,tasks?
29 changes: 21 additions & 8 deletions src/main/java/screens/InstructorMainScreen.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
package screens;

import screens.login_registration.LoginFailed;
import screens.login_registration.LogoutController;
import screens.login_registration.LogoutFailed;
import use_cases.login_registration.login_usecase.LoginResponseModel;
import use_cases.login_registration.logout_usecase.LogoutResponseModel;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import static javax.swing.JOptionPane.showMessageDialog;

public class InstructorMainScreen extends JPanel implements ActionListener {


Expand All @@ -24,13 +32,16 @@ public class InstructorMainScreen extends JPanel implements ActionListener {
CardLayout cardLayout;
JPanel screens;

LogoutController logoutController;

/**
* The window of the main screen with buttons connecting to each use case
*/
public InstructorMainScreen(JPanel screens, CardLayout cardLayout) {
public InstructorMainScreen(JPanel screens, CardLayout cardLayout, LogoutController controller) {

this.cardLayout = cardLayout;
this.screens = screens;
this.logoutController = controller;

// Create label for title of screen
JLabel title = new JLabel("32 Things To Do");
Expand All @@ -40,21 +51,18 @@ public InstructorMainScreen(JPanel screens, CardLayout cardLayout) {
taskCreate = new JButton("New Task");
calendar = new JButton("Calendar");
courses = new JButton("Courses");
// scheduleCT = new JButton("Schedule Collaborative Task");
logout = new JButton("Logout");

taskCreate.addActionListener(this);
calendar.addActionListener(this);
courses.addActionListener(this);
// scheduleCT.addActionListener(this);
logout.addActionListener(this);

// Create panel for buttons
JPanel buttons = new JPanel();
buttons.add(taskCreate);
buttons.add(calendar);
buttons.add(courses);
// buttons.add(scheduleCT);
buttons.add(logout);

// Add all components to the panel
Expand All @@ -77,11 +85,16 @@ public void actionPerformed(ActionEvent evt) {
if (evt.getSource() == courses) {
cardLayout.show(screens, "course");
}
// if (evt.getSource() == scheduleCT) {
// cardLayout.show(screens, "scheduleCT");
// }

if (evt.getSource() == logout) {
cardLayout.show(screens, "welcome");
try {
logoutController.create();
showMessageDialog(this, "Successfully logged out");
cardLayout.show(screens, "welcome");
} catch (Exception e) {
showMessageDialog(this, "Logout failed");
}

}

}
Expand Down
25 changes: 21 additions & 4 deletions src/main/java/screens/StudentMainScreen.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package screens;

import entities.StudentUser;
import screens.login_registration.LogoutController;
import screens.task_management.todolist_screens.ToDoListPresenter;
import screens.task_management.todolist_screens.ToDoListScreen;
import use_cases.task_management.todolist_use_case.ToDoListInteractor;
Expand All @@ -10,6 +10,8 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import static javax.swing.JOptionPane.showMessageDialog;

public class StudentMainScreen extends JPanel implements ActionListener {

/**
Expand All @@ -22,22 +24,24 @@ public class StudentMainScreen extends JPanel implements ActionListener {
JButton courses;
JButton scheduleCT;

JButton logout;

/**
* Objects for connecting to the other screens
*/
CardLayout cardLayout;
JPanel screens;

StudentUser user;
LogoutController logoutController;

/**
* The window of the main screen with buttons connecting to each use case
*/
public StudentMainScreen(StudentUser user, JPanel screens, CardLayout cardLayout) {
public StudentMainScreen(JPanel screens, CardLayout cardLayout, LogoutController controller) {

this.user = user;
this.cardLayout = cardLayout;
this.screens = screens;
this.logoutController = controller;

// Create label for title of screen
JLabel title = new JLabel("32 Things To Do");
Expand All @@ -50,13 +54,15 @@ public StudentMainScreen(StudentUser user, JPanel screens, CardLayout cardLayout
progressTracker = new JButton("Progress Tracker");
courses = new JButton("Courses");
scheduleCT = new JButton("Schedule Collaborative Task");
logout = new JButton("Logout");

createTask.addActionListener(this);
todoList.addActionListener(this);
calendar.addActionListener(this);
progressTracker.addActionListener(this);
courses.addActionListener(this);
scheduleCT.addActionListener(this);
logout.addActionListener(this);

// Create panel for buttons
JPanel buttons = new JPanel();
Expand All @@ -66,6 +72,7 @@ public StudentMainScreen(StudentUser user, JPanel screens, CardLayout cardLayout
buttons.add(progressTracker);
buttons.add(courses);
buttons.add(scheduleCT);
buttons.add(logout);

// Add all components to the panel
this.add(title);
Expand Down Expand Up @@ -103,5 +110,15 @@ public void actionPerformed(ActionEvent evt) {
if (evt.getSource() == scheduleCT) {
cardLayout.show(screens, "scheduleCT");
}
if (evt.getSource() == logout) {
try {
logoutController.create();
showMessageDialog(this, "Successfully logged out");
cardLayout.show(screens, "welcome");
} catch (Exception e) {
showMessageDialog(this, "Logout failed");
}
}

}
}
8 changes: 1 addition & 7 deletions src/main/java/screens/login_registration/LoginScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,11 @@ public LoginScreen(LoginController controller, CardLayout cardLayout, JPanel scr
logIn.addActionListener(this);
cancel.addActionListener(this);

// JPanel main = new JPanel();
// main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS));
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

// this.add(title);
this.add(usernameInfo);
this.add(passwordInfo);
this.add(buttons);
// this.setContentPane(main);
//
// this.pack();
}

/**
Expand All @@ -73,7 +67,7 @@ public void actionPerformed(ActionEvent evt) {
try {
LoginResponseModel l = loginController.create(username.getText(),
String.valueOf(password.getPassword()));
showMessageDialog(this, "% logged in.".format(username.getText()));
showMessageDialog(this, "Successfully logged in.");
if (l.getTypeOfUser().equals("Instructor")) {
cardLayout.show(screens, "InstructorMain");
} else {
Expand Down
12 changes: 4 additions & 8 deletions src/main/java/screens/login_registration/LogoutController.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
package screens.login_registration;

import use_cases.login_registration.logout_usecase.LogoutInputBoundary;
import use_cases.login_registration.logout_usecase.LogoutRequestModel;
import use_cases.login_registration.logout_usecase.LogoutResponseModel;

import java.io.IOException;

public class LogoutController {

final LogoutInputBoundary userInput;
final LogoutInputBoundary interactor;

public LogoutController(LogoutInputBoundary accGateway) {
this.userInput = accGateway;
this.interactor = accGateway;
}

LogoutResponseModel create(String name, String timeOfLogout) throws IOException {
LogoutRequestModel request = new LogoutRequestModel();

return userInput.create(request);
public void create() throws IOException {
interactor.create();
}
}
8 changes: 8 additions & 0 deletions src/main/java/screens/login_registration/LogoutFailed.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package screens.login_registration;

public class LogoutFailed extends Throwable {

public LogoutFailed(String error) {
super(error);
}
}

This file was deleted.

16 changes: 1 addition & 15 deletions src/main/java/screens/login_registration/RegisterScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ public RegisterScreen(UserRegController controller, CardLayout cardLayout, JPane
JLabel title = new JLabel("Register Screen");
title.setAlignmentX(Component.CENTER_ALIGNMENT);

// JPanel userButtons = new JPanel();
// userButtons.add(instructor);
// userButtons.add(student);

LabelTextPanel usernameInfo = new LabelTextPanel(
new JLabel("Choose username"), username);
LabelTextPanel passwordInfo = new LabelTextPanel(
Expand All @@ -65,8 +61,6 @@ public RegisterScreen(UserRegController controller, CardLayout cardLayout, JPane
new JLabel("Enter password again"), repeatPassword);
LabelTextPanel chooseTypeOfUser = new LabelTextPanel(
new JLabel("I am a (type 'Instructor' or 'Student')") , typeOfUser);
// JLabel chooseTypeOfUser = new JLabel("I am a:");
// userButtons.add(chooseTypeOfUser);

JButton signUp = new JButton("Sign up");
JButton cancel = new JButton("Cancel");
Expand All @@ -75,11 +69,8 @@ public RegisterScreen(UserRegController controller, CardLayout cardLayout, JPane
buttons.add(signUp);
buttons.add(cancel);

// typeOfUser.addActionListener(this);
signUp.addActionListener(this);
cancel.addActionListener(this);
// instructor.addActionListener(this);
// student.addActionListener(this);

this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

Expand All @@ -89,13 +80,8 @@ public RegisterScreen(UserRegController controller, CardLayout cardLayout, JPane
this.add(repeatPasswordInfo);
this.add(chooseTypeOfUser);
this.add(buttons);
// this.add(userButtons);

}

// private void add(LabelTextPanel usernameInfo) {
// }

/**
* React to a button click that results in event.
*/
Expand All @@ -110,7 +96,7 @@ public void actionPerformed(ActionEvent evt) {
String.valueOf(password.getPassword()),
String.valueOf(repeatPassword.getPassword()),
String.valueOf(typeOfUser.getText()));
showMessageDialog(this, "%s created.".format(username.getText()));
showMessageDialog(this, "Registration successful and logged in");
if (String.valueOf(typeOfUser.getText()).equals("Student")) {
cardLayout.show(screens, "StudentMain");
} else if (String.valueOf(typeOfUser.getText()).equals("Instructor")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

public interface LogoutInputBoundary {

/**
* @param request the request to logout
* @return the logout response
* @throws IOException
/** Save a User's information into the database before they log out
* @throws IOException if saving not successful
*/
LogoutResponseModel create(LogoutRequestModel request) throws IOException;
void create() throws IOException;
}
Loading

0 comments on commit 055a04a

Please sign in to comment.