|
1 | 1 | 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; |
5 | 3 | import data_access.UserDatabase;
|
| 4 | +import use_cases.user_registration_use_cases.UserExistsInputBoundary; |
| 5 | +import use_cases.user_registration_use_cases.UserExistsInteractor; |
6 | 6 | import use_cases.user_registration_use_cases.userRegCredentialsRetriever;
|
7 | 7 |
|
8 | 8 | import javax.swing.*;
|
9 | 9 | import java.awt.event.ActionEvent;
|
10 | 10 | import java.awt.event.ActionListener;
|
11 | 11 | import java.io.File;
|
12 |
| -import java.util.Random; |
| 12 | + |
13 | 13 | /** This is screen on which the User enters his credentials in order to login**/
|
14 | 14 | public class UserRegistrationUI implements ActionListener, userRegCredentialsRetriever {
|
15 |
| - private final UserDatabase database; |
16 |
| - private JLabel registrationSuccess; |
| 15 | + private final UserExistsInputBoundary verifyUser; |
17 | 16 | private JTextField usernameText;
|
18 | 17 | private JTextField passwordText;
|
19 | 18 | 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; |
24 | 19 |
|
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; |
31 | 24 | }
|
32 | 25 | @Override
|
33 | 26 | public void getUserCredentials(){
|
@@ -66,68 +59,37 @@ public void getUserCredentials(){
|
66 | 59 | emailText.setBounds(100, 80, 165, 25);
|
67 | 60 | registerPanel.add(emailText);
|
68 | 61 |
|
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); |
74 | 65 |
|
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); |
79 | 70 |
|
| 71 | + //The Button |
| 72 | + JButton registerButton = new JButton("Register"); |
| 73 | + registerButton.setBounds(100, 140, 165, 25); |
| 74 | + registerButton.addActionListener(this); |
| 75 | + registerPanel.add(registerButton); |
80 | 76 | registerFrame.setVisible(true);
|
81 | 77 | }
|
82 | 78 |
|
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 |
| - |
103 | 79 | 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(); |
110 | 83 | }
|
111 |
| - |
112 | 84 | @Override
|
113 | 85 | public void actionPerformed(ActionEvent e) {
|
| 86 | + //Need if statements for cases |
114 | 87 | String username = usernameText.getText();
|
115 | 88 | String password = passwordText.getText();
|
116 | 89 | String email = emailText.getText();
|
| 90 | + String type = deliveryText.getText(); |
117 | 91 |
|
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); |
132 | 94 | }
|
133 | 95 | }
|
0 commit comments