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 10 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
Binary file added javax.mail.jar
Binary file not shown.
Empty file.
21 changes: 4 additions & 17 deletions src/main/java/UserDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,16 @@
public class UserDatabase implements UserExists, UserRetriever, UserCreator, IRetrieveList{
File accounts;
List<User> accountList;
public UserDatabase(){
this.accounts = new File("UserAccounts.csv");
this.accountList = this.getList();
}
public UserDatabase(File accounts){
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 Down
2 changes: 2 additions & 0 deletions src/main/java/UserRegLoginButton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public class UserRegLoginButton {
}
103 changes: 103 additions & 0 deletions src/main/java/UserRegistrationUI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import junit.framework.JUnit4TestAdapter;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import java.io.File;

public class UserRegistrationUI implements UserRegistrationUseCase, ActionListener {
private final UserDatabase database;
private JLabel registrationSuccess;
private JTextField usernameText;
private JTextField passwordText;
private JTextField emailText;
private JButton register;

private final int code;

public UserRegistrationUI(UserDatabase database) {
this.database = database;
/*TODO: For now the code is 389 for testing purposes, but once UserVerificationUI.sendVerificationCode() is
implemented this will be a random integer.
*/
/*code = new Random().nextInt(1244254);*/
code = 389;
}
void GetUserCredentials(){
//Front end related objects
JFrame registerFrame = new JFrame();
registerFrame.setSize(500, 300);
registerFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel registerPanel = new JPanel();
registerFrame.add(registerPanel);

//The textbox for entering the Username
registerPanel.setLayout(null);
JLabel usernameLabel = new JLabel("Username");
usernameLabel.setBounds(10, 25, 100, 25);
registerPanel.add(usernameLabel);

usernameText = new JTextField(20);
usernameText.setBounds(100, 20, 165, 25);
registerPanel.add(usernameText);

//The textbox for entering the password
JLabel passwordLabel = new JLabel("Password");
passwordLabel.setBounds(10, 55, 100, 25);
registerPanel.add(passwordLabel);

passwordText = new JPasswordField();
passwordText.setBounds(100, 50, 165, 25);
registerPanel.add(passwordText);

//The textbox for entering the email
JLabel emailLabel = new JLabel("Email");
emailLabel.setBounds(10, 85, 100, 25);
registerPanel.add(emailLabel);

emailText = new JTextField(20);
emailText.setBounds(100, 80, 165, 25);
registerPanel.add(emailText);

//The Button
register = new JButton("Register");
register.setBounds(100, 110, 165, 25);
register.addActionListener(this);
registerPanel.add(register);

//Success/Failure Label
registrationSuccess = new JLabel("");
registrationSuccess.setBounds(10, 140, 350, 25);
registerPanel.add(registrationSuccess);

registerFrame.setVisible(true);
}
@Override
public void registerUser(String username, String password, String email) {
if(database.UserExists(username, email)){
registrationSuccess.setText("The username or password is already in use, please try again");
}else{
database.createUser(username, password, email, "Basic");
registrationSuccess.setText("Your account has been created, please verify to login");
UserVerificationUI verifyUser = new UserVerificationUI(code);
verifyUser.verify(email);
}
}
//For Testing purposes
public static void main(String[] args){
UserDatabase testDB = new UserDatabase(new File("TestUserDatabase3.csv"));
System.out.println(testDB.UserExists("RandomUser", "[email protected]"));
UserRegistrationUI testUI = new UserRegistrationUI(testDB);
testUI.GetUserCredentials();
}

@Override
public void actionPerformed(ActionEvent e) {
String username = usernameText.getText();
String password = passwordText.getText();
String email = emailText.getText();
this.registerUser(username, password, email);

}
}
3 changes: 3 additions & 0 deletions src/main/java/UserRegistrationUseCase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public interface UserRegistrationUseCase {
void registerUser(String username, String password, String email);
}
69 changes: 69 additions & 0 deletions src/main/java/UserVerificationUI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
public class UserVerificationUI implements UserVerifier, ActionListener {
Random random;
private final int code;
private JTextField verificationCodeText;
private JLabel success;

public UserVerificationUI(int code){
this.code = code;
}

//Asks for the verification code from the user, and matches it with this.code to potentially verify the user
public void verify(String email){
//Creating the UI to input the verification code
JFrame verificationFrame = new JFrame();
verificationFrame.setSize(400, 200);
verificationFrame.setDefaultCloseOperation(JFrame.EXIT_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);

this.sendVerificationCode(email);
}
//Sends this.code to the email address given by String email
public void sendVerificationCode(String email){
/*TODO: When this is implemented, a verification code(this.code) will be sent to email with email address "email",
The code will be a random number that is generated, when the user presses the register
button(see UserRegistrationUI).*/
}

//For testing purposes
/*public static void main(String[] args){
UserVerificationUI ver = new UserVerificationUI(389);
ver.verify("abc");
}*/

@Override
public void actionPerformed(ActionEvent e) {
int verCode = Integer.parseInt(verificationCodeText.getText());
if(code == verCode){
//TODO: Going to change below to a label, and will link to LoginUI
success.setText("verified!");
}else{
success.setText("Try again");
}
}
}
3 changes: 3 additions & 0 deletions src/main/java/UserVerifier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public interface UserVerifier {
void verify(String email);
}
Empty file.