Skip to content

Commit b8f86ab

Browse files
committed
Minor changes
1 parent 33eab38 commit b8f86ab

File tree

2 files changed

+40
-38
lines changed

2 files changed

+40
-38
lines changed

src/main/java/UserRegistrationUI.java

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,83 +3,87 @@
33
import javax.swing.*;
44
import java.awt.event.ActionEvent;
55
import java.awt.event.ActionListener;
6+
import java.util.Random;
67
import java.io.File;
78

89
public class UserRegistrationUI implements UserRegistrationUseCase, ActionListener {
9-
private UserDatabase database;
10-
11-
//Front end related objects
12-
private JFrame RegisterFrame;
13-
private JPanel RegisterPanel;
14-
private JLabel usernameLabel;
15-
private JLabel passwordLabel;
16-
private JLabel emailLabel;
10+
private final UserDatabase database;
11+
1712
private JTextField usernameText;
1813
private JTextField passwordText;
1914
private JTextField emailText;
2015
private JButton register;
2116

17+
private final int code;
18+
2219
public UserRegistrationUI(UserDatabase database) {
2320
this.database = database;
21+
code = new Random().nextInt(1244254);
2422
}
2523
void GetUserCredentials(){
26-
RegisterFrame = new JFrame();
27-
RegisterFrame.setSize(300, 300);
28-
RegisterFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
29-
RegisterPanel = new JPanel();
30-
RegisterFrame.add(RegisterPanel);
24+
//Front end related objects
25+
JFrame registerFrame = new JFrame();
26+
registerFrame.setSize(300, 300);
27+
registerFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
28+
JPanel registerPanel = new JPanel();
29+
registerFrame.add(registerPanel);
3130

3231
//The textbox for entering the Username
33-
RegisterPanel.setLayout(null);
34-
usernameLabel = new JLabel("Username");
32+
registerPanel.setLayout(null);
33+
JLabel usernameLabel = new JLabel("Username");
3534
usernameLabel.setBounds(10, 25, 100, 25);
36-
RegisterPanel.add(usernameLabel);
35+
registerPanel.add(usernameLabel);
3736

3837
usernameText = new JTextField(20);
3938
usernameText.setBounds(100, 20, 165, 25);
40-
RegisterPanel.add(usernameText);
39+
registerPanel.add(usernameText);
4140

4241
//The textbox for entering the password
43-
passwordLabel = new JLabel("Password");
42+
JLabel passwordLabel = new JLabel("Password");
4443
passwordLabel.setBounds(10, 55, 100, 25);
45-
RegisterPanel.add(passwordLabel);
44+
registerPanel.add(passwordLabel);
4645

4746
passwordText = new JPasswordField();
4847
passwordText.setBounds(100, 50, 165, 25);
49-
RegisterPanel.add(passwordText);
48+
registerPanel.add(passwordText);
5049

5150
//The textbox for entering the email
52-
emailLabel = new JLabel("Email");
51+
JLabel emailLabel = new JLabel("Email");
5352
emailLabel.setBounds(10, 85, 100, 25);
54-
RegisterPanel.add(emailLabel);
53+
registerPanel.add(emailLabel);
5554

5655
emailText = new JTextField(20);
5756
emailText.setBounds(100, 80, 165, 25);
58-
RegisterPanel.add(emailText);
57+
registerPanel.add(emailText);
5958

6059
//The Button
6160
register = new JButton("Register");
6261
register.setBounds(100, 110, 165, 25);
63-
RegisterPanel.add(register);
62+
register.addActionListener(this);
63+
registerPanel.add(register);
6464

6565

6666

67-
RegisterFrame.setVisible(true);
67+
registerFrame.setVisible(true);
6868
}
6969
@Override
7070
public void registerUser(String username, String password, String email) {
7171
if(database.UserExists(username, email)){
72+
//Will change below to be a label
7273
System.out.println("The username or password is already in use, please try again");
7374
}else{
7475
database.createUser(username, password, email, "Basic");
76+
//Will change below to be a label
7577
System.out.println("Your account has been created, please verify to login");
76-
UserVerificationUI verifyUser = new UserVerificationUI(389);
78+
UserVerificationUI verifyUser = new UserVerificationUI(code);
79+
verifyUser.sendVerificationCode(email);
7780
verifyUser.verify(email);
7881
}
7982
}
8083

8184
public static void main(String[] args){
82-
UserDatabase testDB = new UserDatabase();
85+
UserDatabase testDB = new UserDatabase(new File("TestUserDatabase2.csv"));
86+
System.out.println(testDB.UserExists("RandomUser", "[email protected]"));
8387
UserRegistrationUI testUI = new UserRegistrationUI(testDB);
8488
testUI.GetUserCredentials();
8589
}

src/main/java/UserVerificationUI.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,39 @@
22
import java.awt.event.ActionEvent;
33
import java.awt.event.ActionListener;
44
import java.util.Random;
5-
import java.util.Properties;
65
public class UserVerificationUI implements UserVerifier, ActionListener {
76
Random random;
8-
private int code;
9-
private JFrame verificationFrame;
10-
private JPanel verificationPanel;
11-
private JLabel verificationLabel;
7+
private final int code;
128
private JTextField verificationCodeText;
13-
private JButton verifyButton;
9+
1410
public UserVerificationUI(int code){
1511
this.code = code;
1612
}
1713
public void verify(String email){
1814
//Creating the UI to input the verification code
19-
verificationFrame = new JFrame();
15+
JFrame verificationFrame = new JFrame();
2016
verificationFrame.setSize(400, 200);
2117
verificationFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
22-
verificationPanel = new JPanel();
18+
JPanel verificationPanel = new JPanel();
2319
verificationFrame.add(verificationPanel);
2420

2521
verificationPanel.setLayout(null);
26-
verificationLabel = new JLabel("Verification Code");
22+
JLabel verificationLabel = new JLabel("Verification Code");
2723
verificationLabel.setBounds(10,25, 200, 25);
2824
verificationCodeText = new JTextField();
2925
verificationCodeText.setBounds(125, 20, 165, 25);
3026

3127
verificationPanel.add(verificationLabel);
3228
verificationPanel.add(verificationCodeText);
3329

34-
verifyButton = new JButton("verify");
30+
JButton verifyButton = new JButton("verify");
3531
verifyButton.setBounds(125, 50, 100, 25);
3632
verificationPanel.add(verifyButton);
3733
verifyButton.addActionListener(this);
3834
verificationFrame.setVisible(true);
3935
}
4036

41-
public static void sendVerificationCode(String email){
37+
public void sendVerificationCode(String email){
4238
//When this is implemented, a verification code(this.code) will be sent to email with email address "email",
4339
//The code will be a random number that is generated, when the user presses the register
4440
// button(see UserRegistrationUI).
@@ -52,8 +48,10 @@ public static void main(String[] args){
5248
public void actionPerformed(ActionEvent e) {
5349
int verCode = Integer.parseInt(verificationCodeText.getText());
5450
if(code == verCode){
51+
//Going to change below to a label, and will link to LoginUI
5552
System.out.println("verified");
5653
}else{
54+
//Going to change below to a label
5755
System.out.println("verification unsuccessful");
5856
}
5957
}

0 commit comments

Comments
 (0)