Skip to content

Commit cb22ff8

Browse files
committed
Major changes: Refactored to make it aligned to clean architecture, need to improve UI to make it look better
1 parent f20dc52 commit cb22ff8

25 files changed

+272
-364
lines changed

src/main/java/data_access/Database.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
import use_cases.user_registration_use_cases.UserExists;
55
import use_cases.user_registration_use_cases.UserCreator;
66

7-
public abstract class Database implements UserCreator, UserRetriever, UserExists {
7+
public interface Database extends UserCreator, UserRetriever, UserExists {
88
}

src/main/java/data_access/UserDatabase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import java.io.*;
1111
import java.util.ArrayList;
1212
import java.util.List;
13-
public class UserDatabase extends Database implements IRetrieveList, UserModificationGateway, UserChatGateway {
13+
public class UserDatabase implements Database, IRetrieveList, UserModificationGateway, UserChatGateway {
1414
File accounts;
1515
List<User> accountList;
1616
public UserDatabase(){

src/main/java/entities/user_entities/User.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
import data_access.UserDatabase;
44
import entities.chat.Chat;
55
import interface_adapters.profile_modification_IA.UserAuthenticationI;
6-
import interface_adapters.login_interface_adapters.Login;
76
import use_cases.user_attribute_modification_use_case.Changeable;
87
import interface_adapters.app_screen_interface_adapters.UserAppScreenGateway;
8+
import use_cases.user_login_use_cases.Loginable;
99

1010
import java.io.File;
1111
import java.io.Serializable;
1212
import java.util.ArrayList;
1313

14-
public abstract class User implements Serializable, Changeable, Login, UserAuthenticationI {
14+
public abstract class User implements Serializable, Changeable, Loginable, UserAuthenticationI {
1515
protected String username;
1616
protected String password;
1717
protected String email;

src/main/java/interface_adapters/user_registration_interface_adapters/UserRegistrationGateway.java

Lines changed: 0 additions & 61 deletions
This file was deleted.

src/main/java/interface_adapters/user_registration_interface_adapters/UserRegistrationPresenter.java

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
package screens.login_screen;
2-
import data_access.Database;
3-
import use_cases.user_login_use_cases.UserLoginInteractor;
4-
import interface_adapters.login_interface_adapters.UserLoginGateway;
5-
import data_access.UserDatabase;
6-
import use_cases.user_login_use_cases.loginCredentialsRetriever;
2+
import use_cases.user_login_use_cases.UserLoginInputBoundary;
3+
import use_cases.user_registration_use_cases.UserVerificationOutputBoundary;
74

85
import javax.swing.*;
96
import java.awt.event.ActionEvent;
107
import java.awt.event.ActionListener;
11-
import java.io.File;
12-
/** This is the screen on which the user enters his credentials in order to login **/
13-
public class UserLoginUI implements ActionListener, loginCredentialsRetriever {
148

15-
private JTextField credentialText;
16-
private JLabel passwordLabel;
17-
private JPasswordField passwordText;
9+
/** This is the screen on which the user enters his credentials in order to login **/
10+
public class UserLoginUI implements ActionListener, UserVerificationOutputBoundary {
1811

19-
private final Database database;
12+
private final UserLoginInputBoundary loginInteractor;
13+
JTextField credentialText;
14+
JPasswordField passwordText;
2015

21-
public UserLoginUI(Database database){
22-
this.database = database;
16+
public UserLoginUI(UserLoginInputBoundary loginInteractor){
17+
this.loginInteractor = loginInteractor;
2318
}
2419
@Override
2520
public void getLoginCredentials(){
@@ -38,7 +33,7 @@ public void getLoginCredentials(){
3833
loginPanel.add(credentialLabel);
3934
loginPanel.add(credentialText);
4035

41-
passwordLabel = new JLabel("Enter Password:");
36+
JLabel passwordLabel = new JLabel("Enter Password:");
4237
passwordLabel.setBounds(10,55, 200, 25);
4338
passwordText = new JPasswordField();
4439
passwordText.setBounds(210, 55, 100, 25);
@@ -54,16 +49,27 @@ public void getLoginCredentials(){
5449

5550
}
5651

57-
public static void main(String[] args){
58-
Database testDB = new UserDatabase(new File("user_accounts"));
59-
UserLoginUI screen = new UserLoginUI(testDB);
60-
screen.getLoginCredentials();
52+
@Override
53+
public void cannotVerify() {
54+
JFrame cannotVerifyFrame = new JFrame();
55+
cannotVerifyFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
56+
cannotVerifyFrame.setSize(300, 200);
57+
JPanel cannotVerifyPanel = new JPanel();
58+
cannotVerifyPanel.setLayout(null);
59+
cannotVerifyFrame.add(cannotVerifyPanel);
60+
61+
JLabel accountExists = new JLabel("The verification code you have entered is incorrect, please try again");
62+
accountExists.setBounds(10, 150, 200, 30);
63+
64+
cannotVerifyFrame.setVisible(true);
65+
6166
}
67+
6268
@Override
6369
public void actionPerformed(ActionEvent e) {
64-
UserLoginGateway properties = new UserLoginGateway(credentialText.getText(), passwordText.getText(), this.database);
65-
UserLoginInteractor guard = new UserLoginInteractor(properties);
66-
guard.allowLogin();
67-
70+
String username = credentialText.getText();
71+
String password = passwordText.getText();
72+
loginInteractor.setLoginCredentials(username, password);
73+
loginInteractor.tryLogin();
6874
}
6975
}

src/main/java/screens/user_registration_screen/LoginRegisterScreen.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@
1010
/** This is the screen in which the user chooses to either register or login. **/
1111
public class LoginRegisterScreen implements ActionListener {
1212

13+
private final UserRegistrationUI registrationUI;
14+
private final UserLoginUI loginUI;
1315
JButton login = new JButton("login");
1416
JButton register = new JButton("register");
1517

16-
public LoginRegisterScreen(){
18+
public LoginRegisterScreen(UserRegistrationUI registrationUI, UserLoginUI loginUI){
19+
this.registrationUI = registrationUI;
20+
this.loginUI = loginUI;
1721
JFrame loginRegFrame = new JFrame();
1822
loginRegFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
1923
loginRegFrame.setSize(400, 200);
@@ -31,16 +35,14 @@ public LoginRegisterScreen(){
3135
loginRegFrame.setVisible(true);
3236

3337
}
34-
public static void main(String[] args){
38+
/*public static void main(String[] args){
3539
LoginRegisterScreen screen = new LoginRegisterScreen();
36-
}
40+
}*/
3741
@Override
3842
public void actionPerformed(ActionEvent e) {
3943
if(e.getSource().equals(login)){
40-
UserLoginUI loginUI = new UserLoginUI(new UserDatabase());
4144
loginUI.getLoginCredentials();
4245
}else{
43-
UserRegistrationUI registrationUI = new UserRegistrationUI(new UserDatabase());
4446
registrationUI.getUserCredentials();
4547
}
4648
}
Lines changed: 28 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,26 @@
11
package screens.user_registration_screen;
2-
3-
import use_cases.user_registration_use_cases.UserRegistrationInteractor;
4-
import interface_adapters.user_registration_interface_adapters.UserRegistrationGateway;
2+
import data_access.Database;
53
import data_access.UserDatabase;
4+
import use_cases.user_registration_use_cases.UserExistsInputBoundary;
5+
import use_cases.user_registration_use_cases.UserExistsInteractor;
66
import use_cases.user_registration_use_cases.userRegCredentialsRetriever;
77

88
import javax.swing.*;
99
import java.awt.event.ActionEvent;
1010
import java.awt.event.ActionListener;
1111
import java.io.File;
12-
import java.util.Random;
12+
1313
/** This is screen on which the User enters his credentials in order to login**/
1414
public class UserRegistrationUI implements ActionListener, userRegCredentialsRetriever {
15-
private final UserDatabase database;
16-
private JLabel registrationSuccess;
15+
private final UserExistsInputBoundary verifyUser;
1716
private JTextField usernameText;
1817
private JTextField passwordText;
1918
private JTextField emailText;
20-
private JButton register;
21-
private static JButton phoneVerify = new JButton("Phone");
22-
private static JButton emailVerify = new JButton("Email");
23-
private final int code;
2419

25-
public UserRegistrationUI(UserDatabase database) {
26-
this.database = database;
27-
/*TODO: For now the code is 389 for testing purposes, but once UI.UserVerificationUI.sendVerificationCode() is
28-
implemented this will be a random integer.
29-
*/
30-
code = new Random().nextInt(1244254);
20+
private JTextField deliveryText;
21+
22+
public UserRegistrationUI(UserExistsInputBoundary verifyUser) {
23+
this.verifyUser = verifyUser;
3124
}
3225
@Override
3326
public void getUserCredentials(){
@@ -66,68 +59,37 @@ public void getUserCredentials(){
6659
emailText.setBounds(100, 80, 165, 25);
6760
registerPanel.add(emailText);
6861

69-
//The Button
70-
register = new JButton("Register");
71-
register.setBounds(100, 110, 165, 25);
72-
register.addActionListener(this);
73-
registerPanel.add(register);
62+
//The textbox for entering verification path
63+
JLabel deliveryLabel = new JLabel("Choose verification Path(0 for email, 1 for phone)");
64+
deliveryLabel.setBounds(10, 115, 200, 25);
7465

75-
//Success/Failure Label
76-
registrationSuccess = new JLabel("");
77-
registrationSuccess.setBounds(10, 140, 350, 25);
78-
registerPanel.add(registrationSuccess);
66+
deliveryText = new JTextField(20);
67+
deliveryText.setBounds(100, 110, 50, 25);
68+
registerPanel.add(deliveryLabel);
69+
registerPanel.add(deliveryText);
7970

71+
//The Button
72+
JButton registerButton = new JButton("Register");
73+
registerButton.setBounds(100, 140, 165, 25);
74+
registerButton.addActionListener(this);
75+
registerPanel.add(registerButton);
8076
registerFrame.setVisible(true);
8177
}
8278

83-
public void getPreferredDeliveryMethod(){
84-
JFrame preference = new JFrame();
85-
preference.setSize(400, 200);
86-
JPanel preferancePanel = new JPanel();
87-
preference.add(preferancePanel);
88-
89-
JLabel message = new JLabel("Send verification code via:");
90-
message.setBounds(30, 120, 300, 20);
91-
preferancePanel.add(message);
92-
93-
emailVerify.setBounds(30, 150, 140, 25);
94-
emailVerify.addActionListener(this);
95-
phoneVerify.setBounds(150, 150, 140, 25);
96-
phoneVerify.addActionListener(this);
97-
preferancePanel.add(emailVerify);
98-
preferancePanel.add(phoneVerify);
99-
preference.setVisible(true);
100-
101-
}
102-
10379
public static void main(String[] args){
104-
UserDatabase testDB = new UserDatabase(new File("user_accounts"));
105-
System.out.println(testDB.UserExists("RandomUser", "[email protected]"));
106-
System.out.println(testDB.getList().size());
107-
UserRegistrationUI testUI = new UserRegistrationUI(testDB);
108-
109-
testUI.getUserCredentials();
80+
Database testDB = new UserDatabase(new File("test20123"));
81+
UserExistsInputBoundary interactor = new UserExistsInteractor(testDB);
82+
new UserRegistrationUI(interactor).getUserCredentials();
11083
}
111-
11284
@Override
11385
public void actionPerformed(ActionEvent e) {
86+
//Need if statements for cases
11487
String username = usernameText.getText();
11588
String password = passwordText.getText();
11689
String email = emailText.getText();
90+
String type = deliveryText.getText();
11791

118-
UserRegistrationGateway properties = new UserRegistrationGateway();
119-
properties.setUsername(username);
120-
properties.setPassword(password);
121-
properties.setEmail(email);
122-
properties.setUserExists(database.UserExists(username, email));
123-
properties.setCode(code);
124-
properties.setDatabase(this.database);
125-
getPreferredDeliveryMethod();
126-
//Not an error below, we just have not implemented sending code via phone yet.
127-
if(e.getSource() == emailVerify || e.getSource() == phoneVerify){
128-
properties.setPreference("Email");
129-
UserRegistrationInteractor verifyUser = new UserRegistrationInteractor(properties);
130-
verifyUser.registerUser();
131-
}
92+
verifyUser.setCodeDeliveryMethod(type);
93+
verifyUser.register(username, password, email);
13294
}
13395
}

0 commit comments

Comments
 (0)