Skip to content

Commit 33eab38

Browse files
committed
Almost done implementation of UserRegistrationUI and UserVerificationUI
1 parent cb07aea commit 33eab38

File tree

5 files changed

+116
-11
lines changed

5 files changed

+116
-11
lines changed

javax.mail.jar

644 KB
Binary file not shown.

src/main/java/Changeable.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public interface Changeable {
2+
void changeFeature(String feature, String newFeature);
3+
}
Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,68 @@
1+
import junit.framework.JUnit4TestAdapter;
2+
13
import javax.swing.*;
4+
import java.awt.event.ActionEvent;
5+
import java.awt.event.ActionListener;
6+
import java.io.File;
27

3-
public class UserRegistrationUI implements UserRegistrationUseCase{
8+
public class UserRegistrationUI implements UserRegistrationUseCase, ActionListener {
49
private UserDatabase database;
510

6-
public UserRegistrationUI(UserDatabase database){
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;
17+
private JTextField usernameText;
18+
private JTextField passwordText;
19+
private JTextField emailText;
20+
private JButton register;
21+
22+
public UserRegistrationUI(UserDatabase database) {
723
this.database = database;
824
}
925
void GetUserCredentials(){
10-
JFrame RegisterFrame = new JFrame();
11-
RegisterFrame.setSize(1000, 1000);
26+
RegisterFrame = new JFrame();
27+
RegisterFrame.setSize(300, 300);
1228
RegisterFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
13-
JPanel RegisterPanel = new JPanel();
29+
RegisterPanel = new JPanel();
1430
RegisterFrame.add(RegisterPanel);
1531

1632
//The textbox for entering the Username
1733
RegisterPanel.setLayout(null);
18-
JLabel usernameLabel = new JLabel("Username");
34+
usernameLabel = new JLabel("Username");
1935
usernameLabel.setBounds(10, 25, 100, 25);
36+
RegisterPanel.add(usernameLabel);
2037

21-
JTextField usernameText = new JTextField(20);
38+
usernameText = new JTextField(20);
2239
usernameText.setBounds(100, 20, 165, 25);
2340
RegisterPanel.add(usernameText);
2441

2542
//The textbox for entering the password
26-
JPasswordField passwordText = new JPasswordField();
43+
passwordLabel = new JLabel("Password");
44+
passwordLabel.setBounds(10, 55, 100, 25);
45+
RegisterPanel.add(passwordLabel);
46+
47+
passwordText = new JPasswordField();
2748
passwordText.setBounds(100, 50, 165, 25);
2849
RegisterPanel.add(passwordText);
2950

3051
//The textbox for entering the email
31-
JLabel
52+
emailLabel = new JLabel("Email");
53+
emailLabel.setBounds(10, 85, 100, 25);
54+
RegisterPanel.add(emailLabel);
55+
56+
emailText = new JTextField(20);
57+
emailText.setBounds(100, 80, 165, 25);
58+
RegisterPanel.add(emailText);
59+
60+
//The Button
61+
register = new JButton("Register");
62+
register.setBounds(100, 110, 165, 25);
63+
RegisterPanel.add(register);
64+
65+
3266

3367
RegisterFrame.setVisible(true);
3468
}
@@ -39,6 +73,8 @@ public void registerUser(String username, String password, String email) {
3973
}else{
4074
database.createUser(username, password, email, "Basic");
4175
System.out.println("Your account has been created, please verify to login");
76+
UserVerificationUI verifyUser = new UserVerificationUI(389);
77+
verifyUser.verify(email);
4278
}
4379
}
4480

@@ -47,4 +83,13 @@ public static void main(String[] args){
4783
UserRegistrationUI testUI = new UserRegistrationUI(testDB);
4884
testUI.GetUserCredentials();
4985
}
86+
87+
@Override
88+
public void actionPerformed(ActionEvent e) {
89+
String username = usernameText.getText();
90+
String password = passwordText.getText();
91+
String email = emailText.getText();
92+
this.registerUser(username, password, email);
93+
94+
}
5095
}
Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,60 @@
1-
public class UserVerificationUI implements UserVerifier{
1+
import javax.swing.*;
2+
import java.awt.event.ActionEvent;
3+
import java.awt.event.ActionListener;
4+
import java.util.Random;
5+
import java.util.Properties;
6+
public class UserVerificationUI implements UserVerifier, ActionListener {
7+
Random random;
8+
private int code;
9+
private JFrame verificationFrame;
10+
private JPanel verificationPanel;
11+
private JLabel verificationLabel;
12+
private JTextField verificationCodeText;
13+
private JButton verifyButton;
14+
public UserVerificationUI(int code){
15+
this.code = code;
16+
}
17+
public void verify(String email){
18+
//Creating the UI to input the verification code
19+
verificationFrame = new JFrame();
20+
verificationFrame.setSize(400, 200);
21+
verificationFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
22+
verificationPanel = new JPanel();
23+
verificationFrame.add(verificationPanel);
224

25+
verificationPanel.setLayout(null);
26+
verificationLabel = new JLabel("Verification Code");
27+
verificationLabel.setBounds(10,25, 200, 25);
28+
verificationCodeText = new JTextField();
29+
verificationCodeText.setBounds(125, 20, 165, 25);
30+
31+
verificationPanel.add(verificationLabel);
32+
verificationPanel.add(verificationCodeText);
33+
34+
verifyButton = new JButton("verify");
35+
verifyButton.setBounds(125, 50, 100, 25);
36+
verificationPanel.add(verifyButton);
37+
verifyButton.addActionListener(this);
38+
verificationFrame.setVisible(true);
39+
}
40+
41+
public static void sendVerificationCode(String email){
42+
//When this is implemented, a verification code(this.code) will be sent to email with email address "email",
43+
//The code will be a random number that is generated, when the user presses the register
44+
// button(see UserRegistrationUI).
45+
}
46+
public static void main(String[] args){
47+
UserVerificationUI ver = new UserVerificationUI(389);
48+
ver.verify("abc");
49+
}
50+
51+
@Override
52+
public void actionPerformed(ActionEvent e) {
53+
int verCode = Integer.parseInt(verificationCodeText.getText());
54+
if(code == verCode){
55+
System.out.println("verified");
56+
}else{
57+
System.out.println("verification unsuccessful");
58+
}
59+
}
360
}

src/main/java/UserVerifier.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
public interface UserVerifier {
2-
void verify(UserDatabase database, String username);
2+
void verify(String email);
33
}

0 commit comments

Comments
 (0)