-
Notifications
You must be signed in to change notification settings - Fork 0
User Registration Refactoring #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Madhavan7
wants to merge
15
commits into
main
Choose a base branch
from
user-registration-refactoring
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
09b8d6a
Reorganized classes to follow clean architecture
Madhavan7 e6e3cd0
minor changes
Madhavan7 c29211c
minor changes, now verificationMethodFactory implements an interface.…
Madhavan7 5ec3195
Almost completely tested UserExistsInteractor and UserVerificationInt…
Madhavan7 922eeda
Refactored UserExistsInteractor so that it satisfies single responsib…
Madhavan7 5b517bf
Added comments to the code
Madhavan7 aa560c5
Added comments to the code
Madhavan7 d07586b
Refactoring
Madhavan7 aa10e64
Massive Refactoring, implemented Login Use case according to the MVP …
Madhavan7 dd97bbc
Minor changes
Madhavan7 8d3341b
Minor changes
Madhavan7 5c3d0fc
Implemented UserLoginInteractor2
Madhavan7 070078b
Tested UserLoginInteractor2
Madhavan7 d07c498
merging changes from main
Madhavan7 58eecf8
Added a lot of comments, and deleted some fields
Madhavan7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/interface_adapters/login_interface_adapters/UserChatsPresenter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package interface_adapters.login_interface_adapters; | ||
|
||
import use_cases.user_login_use_cases.UserLoginOutputBoundary; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class UserChatsPresenter implements UserLoginOutputBoundary { | ||
private List<String> chats; | ||
private boolean notExists; | ||
private boolean notMatched; | ||
private String username; | ||
|
||
public UserChatsPresenter(){ | ||
this.chats = new ArrayList<>(); | ||
} | ||
|
||
@Override | ||
public void setUsername(String username) { | ||
this.username = username; | ||
} | ||
|
||
@Override | ||
public void setChats(List<String> chats) { | ||
this.chats = chats; | ||
} | ||
public List<String> getChats(){ | ||
return this.chats; | ||
} | ||
|
||
@Override | ||
public void setUserNotExists(boolean notExists) { | ||
this.notExists = notExists; | ||
} | ||
|
||
public boolean isNotExists() { | ||
return notExists; | ||
} | ||
|
||
@Override | ||
public void setPasswordNotMatched(boolean notMatched) { | ||
this.notMatched = notMatched; | ||
} | ||
|
||
@Override | ||
public String getUsername() { | ||
return this.username; | ||
} | ||
|
||
public boolean isNotMatched() { | ||
return notMatched; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/interface_adapters/login_interface_adapters/UserLoginPresenter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package interface_adapters.login_interface_adapters; | ||
|
||
import data_access.Database; | ||
import use_cases.user_login_use_cases.UserLoginInputBoundary; | ||
|
||
public class UserLoginPresenter { | ||
private final UserLoginInputBoundary loginGuard; | ||
private String username; | ||
private String password; | ||
Database database; | ||
private UserLoginViewI loginView; | ||
|
||
public UserLoginPresenter(Database database, UserLoginInputBoundary loginGuard){ | ||
this.database = database; | ||
this.loginGuard = loginGuard; | ||
} | ||
|
||
public void tryLogin() { | ||
loginGuard.login(this.username, this.password); | ||
loginView.setChatsPresenter(loginGuard.getChatsPresenter()); | ||
loginView.display(); | ||
} | ||
|
||
public void setLoginCredentials(String username, String password) { | ||
this.username = username; | ||
this.password = password; | ||
} | ||
public void setLoginView(UserLoginViewI loginView){ | ||
this.loginView = loginView; | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/interface_adapters/login_interface_adapters/UserLoginViewI.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package interface_adapters.login_interface_adapters; | ||
|
||
import use_cases.user_login_use_cases.UserLoginOutputBoundary; | ||
|
||
public interface UserLoginViewI { | ||
void display(); | ||
void setChatsPresenter(UserLoginOutputBoundary outputBoundary); | ||
} |
26 changes: 26 additions & 0 deletions
26
...in/java/interface_adapters/user_registration_interface_adapters/UserExistsOutputView.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package interface_adapters.user_registration_interface_adapters; | ||
/** | ||
* Presenter interface that presents information, or gets input from user | ||
* */ | ||
public interface UserExistsOutputView { | ||
/** | ||
* Gets the verification code from the user | ||
* */ | ||
void getVerificationCredentials(); | ||
/** | ||
* Presents that the user exists in the database | ||
* */ | ||
void presentUserExistsMessage(); | ||
/** | ||
* Gets the code from the input boundary object | ||
* @param code Verification code | ||
* */ | ||
void getCode(int code); | ||
/** | ||
* Gets the user credentials from the input boundary object | ||
* @param email Email address of the user | ||
* @param password Password of the user | ||
* @param username Username of the user | ||
* */ | ||
void getUserCredentials(String username, String password, String email); | ||
} |
49 changes: 49 additions & 0 deletions
49
...ain/java/interface_adapters/user_registration_interface_adapters/UserExistsPresenter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package interface_adapters.user_registration_interface_adapters; | ||
|
||
import data_access.Database; | ||
import use_cases.user_registration_use_cases.VerificationCodeDeliveryManager; | ||
import use_cases.user_registration_use_cases.createMailMan; | ||
|
||
/** | ||
* This is the class responsible for getting processing the input given by user, and either allowing verification, | ||
* presenting the 'user exists' message, and sending the verification code, depending on the business logic | ||
* */ | ||
public class UserExistsPresenter { | ||
private final VerificationCodeDeliveryManager verCodeDeliveryManager; | ||
Database database; | ||
UserExistsOutputView existsOutputBoundary; | ||
|
||
public UserExistsPresenter(Database database, UserExistsOutputView existsOutputBoundary, createMailMan mailMan){ | ||
this.database = database; | ||
this.existsOutputBoundary = existsOutputBoundary; | ||
//The responsibility of dealing with verification is passed onto this class | ||
this.verCodeDeliveryManager = new VerificationCodeDeliveryManager(mailMan); | ||
} | ||
/** | ||
* Proceeds to verification and sends code, or presents an error message, depending on whether a user with | ||
* such credentials is in the database. | ||
* @param username Username | ||
* @param email Email | ||
* @param password Password | ||
* */ | ||
|
||
public void register(String username, String password, String email) { | ||
if(!database.UserExists(username, email)){ | ||
//This may need to change if verCodeDeliveryManager decides not to create integer codes. | ||
int code = this.verCodeDeliveryManager.getVerCode(); | ||
existsOutputBoundary.getCode(code); | ||
existsOutputBoundary.getUserCredentials(username, password, email); | ||
existsOutputBoundary.getVerificationCredentials(); | ||
this.verCodeDeliveryManager.deliverCode(email); | ||
}else{ | ||
existsOutputBoundary.presentUserExistsMessage(); | ||
} | ||
} | ||
/** | ||
* Sets the verification stream given by the user, to send the code | ||
* @param type The verification stream | ||
* */ | ||
public void setCodeDeliveryMethod(String type) { | ||
this.verCodeDeliveryManager.setMailMan(type); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...a/interface_adapters/user_registration_interface_adapters/UserVerificationOutputView.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package interface_adapters.user_registration_interface_adapters; | ||
|
||
public interface UserVerificationOutputView { | ||
void getLoginCredentials(); | ||
void cannotVerify(); | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
...va/interface_adapters/user_registration_interface_adapters/UserVerificationPresenter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package interface_adapters.user_registration_interface_adapters; | ||
|
||
import data_access.Database; | ||
|
||
public class UserVerificationPresenter { | ||
private final Database database; | ||
private String username; | ||
private String password; | ||
private String email; | ||
|
||
private final UserVerificationOutputView verificationOutputBoundary; | ||
|
||
private int code; | ||
|
||
public UserVerificationPresenter(Database database, UserVerificationOutputView verificationOutputBoundary){ | ||
this.database = database; | ||
this.verificationOutputBoundary = verificationOutputBoundary; | ||
} | ||
/** | ||
* Compares code with this.code, if they match, the program will proceed to ask for login credentials | ||
* Else, it will present a message that verification is not possible | ||
* @param code code inputted by the user | ||
* */ | ||
public void verify(int code) { | ||
System.out.println(this.code); | ||
if(code == this.code){ | ||
database.createUser(this.username, this.password, this.email, "Basic"); | ||
verificationOutputBoundary.getLoginCredentials(); | ||
}else{ | ||
verificationOutputBoundary.cannotVerify(); | ||
} | ||
|
||
} | ||
/** | ||
* Sets the code to compare for verification | ||
* @param code verification code*/ | ||
public void setCode(int code) { | ||
this.code = code; | ||
} | ||
/** | ||
* Sets the user credentials for this object | ||
* */ | ||
public void setCredentials(String username, String password, String email){ | ||
this.username = username; | ||
this.password = password; | ||
this.email = email; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...se_cases/userRegCredentialsRetriever.java → ...adapters/userRegCredentialsRetriever.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package screens.login_screen; | ||
import interface_adapters.appscreen.AppScreenLoader; | ||
import interface_adapters.login_interface_adapters.UserChatsPresenter; | ||
import interface_adapters.login_interface_adapters.UserLoginViewI; | ||
import screens.appscreen.AppScreen; | ||
import use_cases.user_login_use_cases.UserLoginOutputBoundary; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class AppScreenCreator implements UserLoginViewI { | ||
private boolean userNotExists; | ||
private boolean passNotMatched; | ||
AppScreenLoader appScreenLoader; | ||
public AppScreenCreator(){ | ||
} | ||
@Override | ||
public void display() { | ||
if(userNotExists|| passNotMatched){ | ||
showUnableToLogin(); | ||
}else{ | ||
/*this.appScreen = new AppScreen(username, chats);*/ | ||
//Could be null pointer exception if setChatsPresenter is not called before the below | ||
appScreenLoader.openScreen(); | ||
} | ||
} | ||
|
||
private void showUnableToLogin() { | ||
System.out.println("unable to login"); | ||
} | ||
@Override | ||
public void setChatsPresenter(UserLoginOutputBoundary chatsPresenter){ | ||
String username = chatsPresenter.getUsername(); | ||
ArrayList<String> chats = (ArrayList<String>) chatsPresenter.getChats(); | ||
this.userNotExists = chatsPresenter.isNotExists(); | ||
this.passNotMatched = chatsPresenter.isNotMatched(); | ||
appScreenLoader = new AppScreenLoader(username, chats); | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.