Skip to content

Commit 5b517bf

Browse files
committed
Added comments to the code
1 parent 922eeda commit 5b517bf

File tree

11 files changed

+87
-22
lines changed

11 files changed

+87
-22
lines changed

src/main/java/screens/user_registration_screen/UserRegistrationUI.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ public class UserRegistrationUI implements ActionListener, userRegCredentialsRet
2626
public UserRegistrationUI(UserExistsInputBoundary existsInputBoundary) {
2727
this.verifyUser = existsInputBoundary;
2828
}
29+
/**
30+
* Creates the frame on which the user inputs account registration credentials
31+
* **/
2932
@Override
3033
public void getUserCredentials(){
3134
//Front end related objects
@@ -97,6 +100,7 @@ public void actionPerformed(ActionEvent e) {
97100
String password = passwordText.getText();
98101
String email = emailText.getText();
99102

103+
// Makes sure that the credentials entered are of the correct format, may use regex to correct this
100104
if(username.equals("")|| password.equals("")|| email.equals("")){
101105
missingCredentials();
102106
}else{
@@ -105,7 +109,9 @@ public void actionPerformed(ActionEvent e) {
105109
verifyUser.register(username, password, email);
106110
}
107111
}
108-
112+
/**
113+
* The frame that shows up when the credentials entered are not of the right format
114+
* **/
109115
public void missingCredentials(){
110116
JFrame credentialsMissing = new JFrame();
111117
credentialsMissing.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

src/main/java/use_cases/user_registration_use_cases/EmailDelivery.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
import javax.mail.*;
55
import javax.mail.internet.InternetAddress;
66
import javax.mail.internet.MimeMessage;
7-
7+
/**
8+
* This is the class that implements Email verification*/
89
public class EmailDelivery implements ISendVerificationCode {
10+
/**
11+
* The method that implements email verification
12+
* @param email Email address
13+
* @param code Verification Code
14+
* */
915
public void sendVerificationCode(String email, int code){
10-
/*TODO: When this is implemented, the verification code will be sent to the email specified by String email*/
11-
System.out.println("Verification code sent to " + email);
12-
1316
//email address we will send the code to
1417
String to = email;
1518

@@ -42,7 +45,6 @@ protected PasswordAuthentication getPasswordAuthentication() {
4245
message.setText("The verification code for your account is " + code + ". If this was not you, you can safely " +
4346
"ignore this email");
4447
Transport.send(message);
45-
System.out.println("success");
4648
} catch (MessagingException e) {
4749
throw new RuntimeException(e);
4850
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package use_cases.user_registration_use_cases;
2-
//This is an output boundary object for the user registration use case.
2+
/**
3+
* Interface that has a method which represents the sending of the verification code to the user
4+
* */
35
public interface ISendVerificationCode {
46
void sendVerificationCode(String email, int code);
57
}

src/main/java/use_cases/user_registration_use_cases/PhoneDelivery.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package use_cases.user_registration_use_cases;
22

3-
import use_cases.user_registration_use_cases.ISendVerificationCode;
4-
3+
/**
4+
* Class that represents Phone verification. Currently unimplemented
5+
* */
56
public class PhoneDelivery implements ISendVerificationCode {
7+
/**
8+
* The function that is supposed to implement phone verification. Currently unimplemented
9+
* */
610
public void sendVerificationCode(String phoneNumber, int code){
711
/*TODO: When this is implemented properly, the verification code will be sent to phone number specified by
812
* String phoneNumber*/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11

22
package use_cases.user_registration_use_cases;
3+
/**
4+
* Interface that has a method which represents the creation of a user
5+
* */
36
public interface UserCreator {
47
void createUser(String username, String password, String email, String type);
58
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11

22
package use_cases.user_registration_use_cases;
33
public interface UserExists {
4+
/**
5+
* Method that checks if a user exists in the database
6+
* @param email Email address of the user
7+
* @param username Username of the user
8+
* */
49
boolean UserExists(String username, String email);
10+
/**
11+
* Method that checks if a user exists in the database
12+
* @param username Username of the user
13+
* */
514
boolean UserExists(String username);
615
}

src/main/java/use_cases/user_registration_use_cases/UserExistsInputBoundary.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@ public interface UserExistsInputBoundary {
44

55
void register(String username, String password, String email);
66
void setCodeDeliveryMethod(String type);
7-
8-
void setOutputBoundary(UserExistsOutputBoundary existsOutputBoundary);
97
}

src/main/java/use_cases/user_registration_use_cases/UserExistsInteractor.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import data_access.Database;
44

5-
import java.util.Random;
6-
5+
/**
6+
* This is the class responsible for getting processing the input given by user, and either allowing verification,
7+
* presenting the 'user exists' message, and sending the verification code, depending on the business logic
8+
* */
79
public class UserExistsInteractor implements UserExistsInputBoundary{
810
private final VerificationCodeDeliveryManager verCodeDeliveryManager;
911
Database database;
@@ -15,9 +17,17 @@ public UserExistsInteractor(Database database, UserExistsOutputBoundary existsOu
1517
//The responsibility of dealing with verification is passed onto this class
1618
this.verCodeDeliveryManager = new VerificationCodeDeliveryManager(mailMan);
1719
}
20+
/**
21+
* Proceeds to verification and sends code, or presents an error message, depending on whether a user with
22+
* such credentials is in the database.
23+
* @param username Username
24+
* @param email Email
25+
* @param password Password
26+
* */
1827
@Override
1928
public void register(String username, String password, String email) {
2029
if(!database.UserExists(username, email)){
30+
//This may need to change if verCodeDeliveryManager decides not to create integer codes.
2131
int code = this.verCodeDeliveryManager.getVerCode();
2232
existsOutputBoundary.getCode(code);
2333
existsOutputBoundary.getUserCredentials(username, password, email);
@@ -27,14 +37,12 @@ public void register(String username, String password, String email) {
2737
existsOutputBoundary.presentUserExistsMessage();
2838
}
2939
}
30-
40+
/**
41+
* Sets the verification stream given by the user, to send the code
42+
* @param type The verification stream
43+
* */
3144
@Override
3245
public void setCodeDeliveryMethod(String type) {
3346
this.verCodeDeliveryManager.setMailMan(type);
3447
}
35-
36-
@Override
37-
public void setOutputBoundary(UserExistsOutputBoundary existsOutputBoundary) {
38-
this.existsOutputBoundary = existsOutputBoundary;
39-
}
4048
}
Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
11
package use_cases.user_registration_use_cases;
2-
2+
/**
3+
* Presenter interface that presents information, or gets input from user
4+
* */
35
public interface UserExistsOutputBoundary {
6+
/**
7+
* Gets the verification code from the user
8+
* */
49
void getVerificationCredentials();
10+
/**
11+
* Presents that the user exists in the database
12+
* */
513
void presentUserExistsMessage();
14+
/**
15+
* Gets the code from the input boundary object
16+
* @param code Verification code
17+
* */
618
void getCode(int code);
19+
/**
20+
* Gets the user credentials from the input boundary object
21+
* @param email Email address of the user
22+
* @param password Password of the user
23+
* @param username Username of the user
24+
* */
725
void getUserCredentials(String username, String password, String email);
826
}

src/main/java/use_cases/user_registration_use_cases/VerificationCodeDeliveryManager.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package use_cases.user_registration_use_cases;
22

33
import java.util.Random;
4-
4+
/**
5+
* This class is responsible for managing aspects related to verification, such as creating the verification code
6+
* and sending the code to the user
7+
* */
58
public class VerificationCodeDeliveryManager {
69
private final int code = new Random().nextInt(134134);
710
private final createMailMan mailManFactory;
@@ -11,12 +14,23 @@ public VerificationCodeDeliveryManager(createMailMan mailManFactory){
1114
//By default, the type will be email.
1215
this.setMailMan("Email");
1316
}
17+
/**
18+
* Sets the verification stream
19+
* @param type String that represents how the code is delivered
20+
* */
1421
public void setMailMan(String type){
1522
this.mailMan = mailManFactory.getVerificationMethod(type);
1623
}
24+
/**
25+
* Sends the verification code
26+
* @param email Represents the email
27+
* */
1728
public void deliverCode(String email){
1829
this.mailMan.sendVerificationCode(email, this.code);
1930
}
31+
/**
32+
* returns the verification code
33+
* */
2034
public int getVerCode(){
2135
return this.code;
2236
}

0 commit comments

Comments
 (0)