Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5 feature 1 user registration & log in #71

Merged
merged 12 commits into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 36 additions & 37 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,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 use_cases.task_management.event_creation_use_case.*;

Expand Down Expand Up @@ -50,35 +54,24 @@ public static void main(String[] args) throws IOException, ClassNotFoundExceptio
LoginPresenter loginPresenter = new LoginResponseFormatter();
LoginInputBoundary loginInteractor = new LoginInteractor(loginUser, loginPresenter);
LoginController loginController = new LoginController(loginInteractor);
//

// initialize User based on whether they log in or register
// if you don't register, then you are logging in:
User user;
if ((((UserRegInteractor) userInteractor).getUser() instanceof StudentUser) |
(((UserRegInteractor) userInteractor).getUser() instanceof InstructorUser)) {
user = ((UserRegInteractor) userInteractor).getUser();
} else {
user = ((LoginInteractor) loginInteractor).getUser();
}


SchedulerPresenter schedulerPresenter = new SchedulerResponseFormatter();
ScheduleConflictPresenter scheduleConflictPresenter = new ScheduleConflictResponseFormatter();

EventCreationPresenter eventPresenter = new EventCreationResponseFormatter();
EventCreationInputBoundary eventInteractor = new EventCreationInteractor(eventPresenter, (StudentUser) user,
schedulerPresenter, scheduleConflictPresenter);
EventCreationController eventCreationController = new EventCreationController(eventInteractor);

ProgressTrackerOutputBoundary trackerPresenter = new ProgressTrackerPresenter();
ProgressTrackerInputBoundary trackerInteractor = new ProgressTrackerInteractor(trackerPresenter);
ProgressTrackerController trackerController = new ProgressTrackerController(trackerInteractor, user, "", allTasks, allUsers, allCourses);

ScheduleCTViewInterface presentOutputInterface = new ScheduleCTView(cardLayout, screens);
ScheduleCTOutputBoundary scheduleCTOutputBoundary = new ScheduleCTPresenter(presentOutputInterface);
ScheduleCTInputBoundary scheduleCTInputBoundary = new ScheduleCTInteractor(scheduleCTOutputBoundary);
ScheduleCTController scheduleCTController = new ScheduleCTController(scheduleCTInputBoundary, allTasks, (StudentUser) user);
// EventCreationPresenter eventPresenter = new EventCreationResponseFormatter();
// EventCreationInputBoundary eventInteractor = new EventCreationInteractor(eventPresenter, (StudentUser) user,
// schedulerPresenter, scheduleConflictPresenter);
// EventCreationController eventCreationController = new EventCreationController(eventInteractor);
//
// ProgressTrackerOutputBoundary trackerPresenter = new ProgressTrackerPresenter();
// ProgressTrackerInputBoundary trackerInteractor = new ProgressTrackerInteractor(trackerPresenter);
// ProgressTrackerController trackerController = new ProgressTrackerController(trackerInteractor, user, "", allTasks, allUsers, allCourses);
//
// ScheduleCTViewInterface presentOutputInterface = new ScheduleCTView(cardLayout, screens);
// ScheduleCTOutputBoundary scheduleCTOutputBoundary = new ScheduleCTPresenter(presentOutputInterface);
// ScheduleCTInputBoundary scheduleCTInputBoundary = new ScheduleCTInteractor(scheduleCTOutputBoundary);
// ScheduleCTController scheduleCTController = new ScheduleCTController(scheduleCTInputBoundary, allTasks, (StudentUser) user);

CourseCreationDsGateway course;
try {
Expand All @@ -91,23 +84,29 @@ public static void main(String[] args) throws IOException, ClassNotFoundExceptio
CourseCreationInputBoundary interactor = new CourseCreationInteractor(course, presenter, courseMap);
CourseCreationController courseCreationController = new CourseCreationController(interactor);

// Build the GUI
EventCreationScreen taskScreen = new EventCreationScreen(eventCreationController, screens, cardLayout);
screens.add("toDoList", taskScreen);

CalendarScreen calendarScreen = new CalendarScreen((StudentUser) user, allTasks, screens, cardLayout);
screens.add("calendar", calendarScreen);

ScheduleCTScreen scheduleCTScreen = new ScheduleCTScreen(scheduleCTController, screens, cardLayout);
screens.add("scheduleCT", scheduleCTScreen);
// 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);
//

ProgressTrackerScreen progressTrackerScreen = new ProgressTrackerScreen(trackerController);
screens.add("tracker", progressTrackerScreen);
// Build the GUI
// EventCreationScreen taskScreen = new EventCreationScreen(eventCreationController, screens, cardLayout);
// screens.add("toDoList", taskScreen);
//
// CalendarScreen calendarScreen = new CalendarScreen((StudentUser) user, allTasks, screens, cardLayout);
// screens.add("calendar", calendarScreen);
//
// ScheduleCTScreen scheduleCTScreen = new ScheduleCTScreen(scheduleCTController, screens, cardLayout);
// screens.add("scheduleCT", scheduleCTScreen);
//
// ProgressTrackerScreen progressTrackerScreen = new ProgressTrackerScreen(trackerController);
// screens.add("tracker", progressTrackerScreen);

CourseCreationScreen courseCreationScreen = new CourseCreationScreen(courseCreationController, screens, cardLayout);
screens.add("course", courseCreationScreen);

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

RegisterScreen registerScreen = new RegisterScreen(userRegisterController, cardLayout, screens);
Expand All @@ -116,7 +115,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?
Binary file modified src/main/java/data/users.ser
Binary file not shown.
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
17 changes: 15 additions & 2 deletions src/main/java/screens/StudentMainScreen.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package screens;

import screens.login_registration.LogoutController;

import javax.swing.*;
import java.awt.*;
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 @@ -24,13 +28,16 @@ public class StudentMainScreen extends JPanel implements ActionListener {
CardLayout cardLayout;
JPanel screens;

LogoutController logoutController;

/**
* The window of the main screen with buttons connecting to each use case
*/
public StudentMainScreen(JPanel screens, CardLayout cardLayout) {
public StudentMainScreen(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 Down Expand Up @@ -86,7 +93,13 @@ public void actionPerformed(ActionEvent evt) {
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
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