Skip to content
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

9-feature-1-user-registration #17

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e71f7da
Minor Changes, just added some of the objects which I will implement …
Madhavan7 Nov 9, 2022
26632a1
Added a few methods, pending implementation
Madhavan7 Nov 10, 2022
0b25139
Added the required objects and wrote some code
Madhavan7 Nov 12, 2022
cb07aea
Wrote some code for the UI
Madhavan7 Nov 12, 2022
33eab38
Almost done implementation of UserRegistrationUI and UserVerificationUI
Madhavan7 Nov 12, 2022
b8f86ab
Minor changes
Madhavan7 Nov 12, 2022
e4efd7e
added changes made to another branch and brought it here
Madhavan7 Nov 13, 2022
5c4b5c9
added changes made to another branch and resolved conflicts
Madhavan7 Nov 13, 2022
bf8afc7
Made changes to UserRegistrationUI and UserVerificationUI the only is…
Madhavan7 Nov 13, 2022
a2a33b7
When tested using "TestUserDatabase3.csv" everything seems to work
Madhavan7 Nov 13, 2022
f837d19
Used Factory design pattern to change the method "sendVerificationCod…
Madhavan7 Nov 14, 2022
9c471f0
Figured out and corrected the bug in UserDatabase.createUser now its …
Madhavan7 Nov 17, 2022
776765e
Made changes to the gradle dependencies in order to facilitate email …
Madhavan7 Nov 17, 2022
f19fb12
Packaged all the files
Madhavan7 Nov 17, 2022
2f00f3a
There was design problems with user verification, so I changed the de…
Madhavan7 Nov 18, 2022
45271e7
Implemented Email verification
Madhavan7 Nov 19, 2022
bf563b5
Changed the Packaging Structure
Madhavan7 Nov 20, 2022
bbd6f94
Minor Changes
Madhavan7 Nov 20, 2022
73d358a
Merge branch 'main' into 9-feature-1-user-registration
Madhavan7 Nov 21, 2022
1007a1e
Minor Changes
Madhavan7 Nov 21, 2022
1da907a
Minor Changes
Madhavan7 Nov 21, 2022
705b6c9
Minor Changes
Madhavan7 Nov 21, 2022
6e91e27
Minor Changes
Madhavan7 Nov 21, 2022
a86bb7d
Merged conflicts from the main branch
Madhavan7 Nov 29, 2022
a6d0b75
Merged conflicts from the main branch
Madhavan7 Nov 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
# entities.user_entities.User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
# AWS entities.user_entities.User-specific
.idea/**/aws.xml

# Generated files
Expand Down
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ repositories {
}

dependencies {
implementation 'javax.mail:javax.mail-api:1.6.2'
implementation 'com.sun.mail:javax.mail:1.6.2'
implementation 'junit:junit:4.13.1'
testImplementation('org.junit.jupiter:junit-jupiter:5.6.0')
}
Expand Down
Binary file added javax.mail.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
public class BasicUser extends User{
package Entities.user_entities;

public class BasicUser extends User {
public BasicUser(String Username, String Password, String Email){
super(Username, Password, Email);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package Entities.user_entities;
import UseCase.Changeable;
import java.io.Serializable;
public abstract class User implements Serializable, Changeable{
public abstract class User implements Serializable, Changeable {
protected String username;
protected String password;
protected String email;
Expand All @@ -21,7 +23,7 @@ private String getPassword(){
}

@Override
// from Changeable
// from UseCase.Changeable
public void changeFeature(String feature, String newFeature){
if (feature == "Username"){
this.username = newFeature;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package Entities.user_entities;

public class UserFactory {
//Following the factory design pattern, just in case in the future we decide to add various different types of Users
public static User BirthUser(String Username, String Password, String Email, String type){
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package UseCase;

public interface Changeable {
void changeFeature(String feature, String newFeature);
}
3 changes: 0 additions & 3 deletions src/main/java/UserRegPresenter.java

This file was deleted.

3 changes: 0 additions & 3 deletions src/main/java/UserRetriever.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
package data_access;

import interface_adapters.IRetrieveList;
import interface_adapters.user_registration_interface_adapters.UserExists;
import Entities.user_entities.User;
import Entities.user_entities.UserFactory;
import use_cases.user_login_use_case.UserCreator;
import interface_adapters.UserRetriever;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
public class UserDatabase implements UserExists, UserRetriever, UserCreator, IRetrieveList{
public class UserDatabase implements UserExists, UserRetriever, UserCreator, IRetrieveList {
File accounts;
List<User> accountList;
public UserDatabase(){
this.accounts = new File("TestUserDatabase3.csv");
this.accountList = this.getList();
}
public UserDatabase(File accounts){
if(!accounts.exists()){
try {
accounts.createNewFile();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
this.accounts = accounts;
this.accountList = this.getList();
}
@Override
public boolean UserExists(String username, String email) {
/*User user = null;
try(FileInputStream fileIn = new FileInputStream(accounts);
ObjectInputStream in = new ObjectInputStream(fileIn)){
do{
try{
user = (User)in.readObject();
}catch(NullPointerException e){
user = null;
break;
}
}while(!user.getEmail().equals(email) && !user.getUsername().equals(username));
}catch(IOException e){
e.printStackTrace();
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
return user != null;*/
for(User user: this.accountList){
if(user.getUsername().equals(username) || user.getEmail().equals(email)){
return true;
Expand All @@ -41,10 +44,10 @@ public boolean UserExists(String username, String email) {
@Override
public void createUser(String username, String password, String email, String type){
User newUser = UserFactory.BirthUser(username, password, email, type);
this.accountList.add(newUser);
try(FileOutputStream fileOut = new FileOutputStream(accounts)){
try(ObjectOutputStream out = new ObjectOutputStream(fileOut)){
out.writeObject(newUser);
this.accountList.add(newUser);
out.writeObject(this.accountList);
out.close();
fileOut.close();
}catch(Exception e){
Expand Down Expand Up @@ -72,19 +75,14 @@ public User getUser(String username) {
public List<User> getList() {
List<User> users = new ArrayList<>();
try(FileInputStream fileIn = new FileInputStream(accounts);
ObjectInputStream in = new ObjectInputStream(fileIn)){
/*User user = (User) in.readObject();*/
while(true){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is correct to delete this while loop since it is not necessary

try{
User user = (User) in.readObject();
users.add(user);}
catch(EOFException e){
break;
}
}
}catch(Exception e){
e.printStackTrace();
ObjectInputStream in = new ObjectInputStream(fileIn)) {

users = (ArrayList<User>) in.readObject();
return users;
}catch(EOFException e){
return users;
} catch (IOException | ClassNotFoundException ex) {
throw new RuntimeException(ex);
}
return users;
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package interface_adapters;
import Entities.user_entities.User;
import java.util.List;

public interface IRetrieveList {
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/interface_adapters/UserRetriever.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package interface_adapters;

import Entities.user_entities.User;
import interface_adapters.user_registration_interface_adapters.UserExists;

public interface UserRetriever extends UserExists {
User getUser(String username);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package interface_adapters.user_registration_interface_adapters;

public interface UserExists {
boolean UserExists(String username, String password);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package interface_adapters.user_registration_interface_adapters;

import use_cases.user_login_use_case.UserCreator;
import use_cases.user_login_use_case.verificationMethodFactory;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
public class UserRegistrationController implements UserVerifier, ActionListener, UserRegistrator {
private final String username;
private final String password;
private final String email;
private String preference;
private boolean userExists = false;
private UserCreator database;
Random random;
private final int code;
private JTextField verificationCodeText;
private JLabel success;

/*public UserRegistrationController(int code, String Username, String Password, String email, UserDatabase database){
this.code = code;
this.username = Username;
this.password = Password;
this.email = email;
this.database = database;
}*/

public UserRegistrationController(UserRegistrationGateway properties){
this.username = properties.getUsername();
this.password = properties.getPassword();
this.email = properties.getEmail();
this.userExists = properties.isUserExists();
this.code = properties.getCode();
this.database = properties.getDatabase();
}

//Asks for the verification code from the user, and matches it with this.code to potentially verify the user
public void verify(String email){
JFrame verificationFrame = new JFrame();
verificationFrame.setSize(400, 200);
verificationFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel verificationPanel = new JPanel();
verificationFrame.add(verificationPanel);

verificationPanel.setLayout(null);
JLabel verificationLabel = new JLabel("Verification Code");
verificationLabel.setBounds(10,25, 200, 25);
verificationCodeText = new JTextField();
verificationCodeText.setBounds(125, 20, 165, 25);

verificationPanel.add(verificationLabel);
verificationPanel.add(verificationCodeText);

//Success/Failure Labels
success = new JLabel("");
success.setBounds(10, 50, 100, 25);
verificationPanel.add(success);

JButton verifyButton = new JButton("verify");
verifyButton.setBounds(125, 50, 100, 25);
verificationPanel.add(verifyButton);
verifyButton.addActionListener(this);
verificationFrame.setVisible(true);

verificationMethodFactory mailMan = new verificationMethodFactory(email, "Email", code);
mailMan.deliverCode();
}

public void registerUser() {
if(this.userExists){
System.out.println("An account with this username or email already exists");
accountExistsMessage();
}else{
this.verify(email);
}
}

public static void accountExistsMessage(){
JFrame accountExistsFrame = new JFrame();
accountExistsFrame.setSize(400, 100);
accountExistsFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel accountExistsPanel = new JPanel();
accountExistsPanel.setLayout(null);
accountExistsFrame.add(accountExistsPanel);
JLabel errorMessage = new JLabel("An account with this username or email already exists");
errorMessage.setBounds(10,20, 350, 20);
accountExistsPanel.add(errorMessage);
accountExistsFrame.setVisible(true);
}

public static void verificationSuccessMessage(){
JFrame verificationSuccessFrame = new JFrame();
verificationSuccessFrame.setSize(400, 100);
verificationSuccessFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel verificationSuccessPanel = new JPanel();
verificationSuccessPanel.setLayout(null);
verificationSuccessFrame.add(verificationSuccessPanel);
JLabel errorMessage = new JLabel("Could not verify please try again");
errorMessage.setBounds(10,20, 350, 20);
verificationSuccessPanel.add(errorMessage);
verificationSuccessFrame.setVisible(true);
}

@Override
public void actionPerformed(ActionEvent e) {
int verCode = Integer.parseInt(verificationCodeText.getText());
if(verCode == this.code){
database.createUser(this.username, this.password, this.email, "Basic");
System.out.println("Verification successful");
}else{
verificationSuccessMessage();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package interface_adapters.user_registration_interface_adapters;

import use_cases.user_login_use_case.UserCreator;

public class UserRegistrationGateway {
private String username;
private String password;
private String email;
private boolean userExists = false;
private int code;
private UserCreator database;

private String preference;

public void setUsername(String username){
this.username = username;
}
public String getUsername(){
return this.username;
}

public void setPassword(String password){
this.password = password;
}
public String getPassword(){
return this.password;
}

public void setEmail(String email){
this.email = email;
}
public String getEmail(){
return this.email;
}

public void setUserExists(boolean userExists) {
this.userExists = userExists;
}

public boolean isUserExists() {
return userExists;
}

public int getCode() {
return code;
}
public void setCode(int code){
this.code = code;
}

public void setDatabase(UserCreator database) {
this.database = database;
}

public UserCreator getDatabase(){
return this.database;
}

public void setPreference(String preference) {
this.preference = preference;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package interface_adapters.user_registration_interface_adapters;

public interface UserRegistrator {
void registerUser();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package interface_adapters.user_registration_interface_adapters;

public interface UserVerifier {
void verify(String email);
}
Loading