Skip to content

Commit a6560d9

Browse files
committed
added import statements to allow access to packages
2 parents ed14eb0 + 233994e commit a6560d9

File tree

17 files changed

+488
-0
lines changed

17 files changed

+488
-0
lines changed

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ repositories {
77
}
88

99
dependencies {
10+
implementation 'javax.mail:javax.mail-api:1.6.2'
11+
implementation 'com.sun.mail:javax.mail:1.6.2'
1012
implementation 'junit:junit:4.13.1'
1113
testImplementation('org.junit.jupiter:junit-jupiter:5.6.0')
1214
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package entities.user_entities;
2+
3+
import entities.user_entities.User;
4+
public class BasicUser extends User{
5+
public BasicUser(String Username, String Password, String Email){
6+
super(Username, Password, Email);
7+
}
8+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package entities.user_entities;
2+
3+
import use_cases.user_attribute_modification_use_case.Changeable;
4+
5+
import java.io.Serializable;
6+
public abstract class User implements Serializable, Changeable {
7+
protected String username;
8+
protected String password;
9+
protected String email;
10+
boolean verified = false;
11+
boolean online = false;
12+
public User(String username, String password, String email){
13+
this.username = username;
14+
this.password = password;
15+
this.email = email;
16+
}
17+
public String getEmail(){
18+
return this.email;
19+
}
20+
public String getUsername(){
21+
return this.username;
22+
}
23+
private String getPassword(){
24+
return this.password;
25+
}
26+
27+
@Override
28+
// from Changeable
29+
public void changeFeature(String feature, String newFeature){
30+
if (feature == "Username"){
31+
this.username = newFeature;
32+
} else if (feature == "Password"){
33+
this.password = newFeature;
34+
} else if (feature == "Email"){
35+
this.email = newFeature;
36+
}
37+
}
38+
39+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package entities.user_entities;
2+
3+
public class UserFactory {
4+
//Following the factory design pattern, just in case in the future we decide to add various different types of Users
5+
public static User BirthUser(String Username, String Password, String Email, String type){
6+
return new BasicUser(Username, Password, Email);
7+
}
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package interface_adapters;
2+
import entities.user_entities.User;
3+
import java.util.List;
4+
5+
public interface IRetrieveList {
6+
List<User> getList();
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package interface_adapters;
2+
3+
import entities.user_entities.User;
4+
import interface_adapters.user_registration_interface_adapters.UserExists;
5+
6+
public interface UserRetriever extends UserExists {
7+
User getUser(String username);
8+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package interface_adapters.user_registration_interface_adapters;
2+
3+
public interface UserExists {
4+
boolean UserExists(String username, String password);
5+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
package interface_adapters.user_registration_interface_adapters;
2+
3+
import use_cases.user_login_use_case.UserCreator;
4+
import interface_adapters.user_registration_interface_adapters.UserVerifier;
5+
import use_cases.user_login_use_case.verificationMethodFactory;
6+
7+
import javax.swing.*;
8+
import java.awt.event.ActionEvent;
9+
import java.awt.event.ActionListener;
10+
import java.util.Random;
11+
public class UserRegistrationController implements UserVerifier, ActionListener, UserRegistrator {
12+
private final String username;
13+
private final String password;
14+
private final String email;
15+
private String preference;
16+
private boolean userExists = false;
17+
private UserCreator database;
18+
Random random;
19+
private final int code;
20+
private JTextField verificationCodeText;
21+
private JLabel success;
22+
23+
/*public UserRegistrationController(int code, String Username, String Password, String email, UserDatabase database){
24+
this.code = code;
25+
this.username = Username;
26+
this.password = Password;
27+
this.email = email;
28+
this.database = database;
29+
}*/
30+
31+
public UserRegistrationController(UserRegistrationGateway properties){
32+
this.username = properties.getUsername();
33+
this.password = properties.getPassword();
34+
this.email = properties.getEmail();
35+
this.userExists = properties.isUserExists();
36+
this.code = properties.getCode();
37+
this.database = properties.getDatabase();
38+
}
39+
40+
//Asks for the verification code from the user, and matches it with this.code to potentially verify the user
41+
public void verify(String email){
42+
JFrame verificationFrame = new JFrame();
43+
verificationFrame.setSize(400, 200);
44+
verificationFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
45+
JPanel verificationPanel = new JPanel();
46+
verificationFrame.add(verificationPanel);
47+
48+
verificationPanel.setLayout(null);
49+
JLabel verificationLabel = new JLabel("Verification Code");
50+
verificationLabel.setBounds(10,25, 200, 25);
51+
verificationCodeText = new JTextField();
52+
verificationCodeText.setBounds(125, 20, 165, 25);
53+
54+
verificationPanel.add(verificationLabel);
55+
verificationPanel.add(verificationCodeText);
56+
57+
//Success/Failure Labels
58+
success = new JLabel("");
59+
success.setBounds(10, 50, 100, 25);
60+
verificationPanel.add(success);
61+
62+
JButton verifyButton = new JButton("verify");
63+
verifyButton.setBounds(125, 50, 100, 25);
64+
verificationPanel.add(verifyButton);
65+
verifyButton.addActionListener(this);
66+
verificationFrame.setVisible(true);
67+
68+
verificationMethodFactory mailMan = new verificationMethodFactory(email, "Email", code);
69+
mailMan.deliverCode();
70+
}
71+
72+
public void registerUser() {
73+
if(this.userExists){
74+
System.out.println("An account with this username or email already exists");
75+
accountExistsMessage();
76+
}else{
77+
this.verify(email);
78+
}
79+
}
80+
81+
public static void accountExistsMessage(){
82+
JFrame accountExistsFrame = new JFrame();
83+
accountExistsFrame.setSize(400, 100);
84+
accountExistsFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
85+
JPanel accountExistsPanel = new JPanel();
86+
accountExistsPanel.setLayout(null);
87+
accountExistsFrame.add(accountExistsPanel);
88+
JLabel errorMessage = new JLabel("An account with this username or email already exists");
89+
errorMessage.setBounds(10,20, 350, 20);
90+
accountExistsPanel.add(errorMessage);
91+
accountExistsFrame.setVisible(true);
92+
}
93+
94+
public static void verificationSuccessMessage(){
95+
JFrame verificationSuccessFrame = new JFrame();
96+
verificationSuccessFrame.setSize(400, 100);
97+
verificationSuccessFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
98+
JPanel verificationSuccessPanel = new JPanel();
99+
verificationSuccessPanel.setLayout(null);
100+
verificationSuccessFrame.add(verificationSuccessPanel);
101+
JLabel errorMessage = new JLabel("Could not verify please try again");
102+
errorMessage.setBounds(10,20, 350, 20);
103+
verificationSuccessPanel.add(errorMessage);
104+
verificationSuccessFrame.setVisible(true);
105+
}
106+
107+
@Override
108+
public void actionPerformed(ActionEvent e) {
109+
int verCode = Integer.parseInt(verificationCodeText.getText());
110+
if(verCode == this.code){
111+
database.createUser(this.username, this.password, this.email, "Basic");
112+
System.out.println("Verification successful");
113+
}else{
114+
verificationSuccessMessage();
115+
}
116+
}
117+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package interface_adapters.user_registration_interface_adapters;
2+
3+
import use_cases.user_login_use_case.UserCreator;
4+
5+
public class UserRegistrationGateway {
6+
private String username;
7+
private String password;
8+
private String email;
9+
private boolean userExists = false;
10+
private int code;
11+
private UserCreator database;
12+
13+
private String preference;
14+
15+
public void setUsername(String username){
16+
this.username = username;
17+
}
18+
public String getUsername(){
19+
return this.username;
20+
}
21+
22+
public void setPassword(String password){
23+
this.password = password;
24+
}
25+
public String getPassword(){
26+
return this.password;
27+
}
28+
29+
public void setEmail(String email){
30+
this.email = email;
31+
}
32+
public String getEmail(){
33+
return this.email;
34+
}
35+
36+
public void setUserExists(boolean userExists) {
37+
this.userExists = userExists;
38+
}
39+
40+
public boolean isUserExists() {
41+
return userExists;
42+
}
43+
44+
public int getCode() {
45+
return code;
46+
}
47+
public void setCode(int code){
48+
this.code = code;
49+
}
50+
51+
public void setDatabase(UserCreator database) {
52+
this.database = database;
53+
}
54+
55+
public UserCreator getDatabase(){
56+
return this.database;
57+
}
58+
59+
public void setPreference(String preference) {
60+
this.preference = preference;
61+
}
62+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package interface_adapters.user_registration_interface_adapters;
2+
3+
public interface UserRegistrator {
4+
void registerUser();
5+
}

0 commit comments

Comments
 (0)