Skip to content

Commit bf8afc7

Browse files
committed
Made changes to UserRegistrationUI and UserVerificationUI the only issues that remain are related to persistance, sometimes the accounts are not saved, other times they are.
1 parent 5c4b5c9 commit bf8afc7

File tree

2 files changed

+33
-19
lines changed

2 files changed

+33
-19
lines changed

src/main/java/UserRegistrationUI.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
public class UserRegistrationUI implements UserRegistrationUseCase, ActionListener {
1010
private final UserDatabase database;
11-
11+
private JLabel registrationSuccess;
1212
private JTextField usernameText;
1313
private JTextField passwordText;
1414
private JTextField emailText;
@@ -18,12 +18,16 @@ public class UserRegistrationUI implements UserRegistrationUseCase, ActionListen
1818

1919
public UserRegistrationUI(UserDatabase database) {
2020
this.database = database;
21-
code = new Random().nextInt(1244254);
21+
/*TODO: For now the code is 389 for testing purposes, but once UserVerificationUI.sendVerificationCode() is
22+
implemented this will be a random integer.
23+
*/
24+
/*code = new Random().nextInt(1244254);*/
25+
code = 389;
2226
}
2327
void GetUserCredentials(){
2428
//Front end related objects
2529
JFrame registerFrame = new JFrame();
26-
registerFrame.setSize(300, 300);
30+
registerFrame.setSize(500, 300);
2731
registerFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
2832
JPanel registerPanel = new JPanel();
2933
registerFrame.add(registerPanel);
@@ -62,25 +66,26 @@ void GetUserCredentials(){
6266
register.addActionListener(this);
6367
registerPanel.add(register);
6468

65-
69+
//Success/Failure Label
70+
registrationSuccess = new JLabel("");
71+
registrationSuccess.setBounds(10, 140, 350, 25);
72+
registerPanel.add(registrationSuccess);
6673

6774
registerFrame.setVisible(true);
6875
}
6976
@Override
7077
public void registerUser(String username, String password, String email) {
7178
if(database.UserExists(username, email)){
72-
//Will change below to be a label
73-
System.out.println("The username or password is already in use, please try again");
79+
registrationSuccess.setText("The username or password is already in use, please try again");
7480
}else{
7581
database.createUser(username, password, email, "Basic");
76-
//Will change below to be a label
77-
System.out.println("Your account has been created, please verify to login");
82+
registrationSuccess.setText("Your account has been created, please verify to login");
7883
UserVerificationUI verifyUser = new UserVerificationUI(code);
7984
verifyUser.sendVerificationCode(email);
8085
verifyUser.verify(email);
8186
}
8287
}
83-
88+
//For Testing purposes
8489
public static void main(String[] args){
8590
UserDatabase testDB = new UserDatabase(new File("TestUserDatabase2.csv"));
8691
System.out.println(testDB.UserExists("RandomUser", "[email protected]"));

src/main/java/UserVerificationUI.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ public class UserVerificationUI implements UserVerifier, ActionListener {
66
Random random;
77
private final int code;
88
private JTextField verificationCodeText;
9+
private JLabel success;
910

1011
public UserVerificationUI(int code){
1112
this.code = code;
1213
}
14+
15+
//Asks for the verification code from the user, and matches it with this.code to potentially verify the user
1316
public void verify(String email){
1417
//Creating the UI to input the verification code
1518
JFrame verificationFrame = new JFrame();
@@ -27,32 +30,38 @@ public void verify(String email){
2730
verificationPanel.add(verificationLabel);
2831
verificationPanel.add(verificationCodeText);
2932

33+
//Success/Failure Labels
34+
success = new JLabel("");
35+
success.setBounds(10, 50, 100, 25);
36+
verificationPanel.add(success);
37+
3038
JButton verifyButton = new JButton("verify");
3139
verifyButton.setBounds(125, 50, 100, 25);
3240
verificationPanel.add(verifyButton);
3341
verifyButton.addActionListener(this);
3442
verificationFrame.setVisible(true);
3543
}
36-
44+
//Sends this.code to the email address given by String email
3745
public void sendVerificationCode(String email){
38-
//When this is implemented, a verification code(this.code) will be sent to email with email address "email",
39-
//The code will be a random number that is generated, when the user presses the register
40-
// button(see UserRegistrationUI).
46+
/*TODO: When this is implemented, a verification code(this.code) will be sent to email with email address "email",
47+
The code will be a random number that is generated, when the user presses the register
48+
button(see UserRegistrationUI).*/
4149
}
42-
public static void main(String[] args){
50+
51+
//For testing purposes
52+
/*public static void main(String[] args){
4353
UserVerificationUI ver = new UserVerificationUI(389);
4454
ver.verify("abc");
45-
}
55+
}*/
4656

4757
@Override
4858
public void actionPerformed(ActionEvent e) {
4959
int verCode = Integer.parseInt(verificationCodeText.getText());
5060
if(code == verCode){
51-
//Going to change below to a label, and will link to LoginUI
52-
System.out.println("verified");
61+
//TODO: Going to change below to a label, and will link to LoginUI
62+
success.setText("verified!");
5363
}else{
54-
//Going to change below to a label
55-
System.out.println("verification unsuccessful");
64+
success.setText("Try again");
5665
}
5766
}
5867
}

0 commit comments

Comments
 (0)