Skip to content

Commit

Permalink
controller avance
Browse files Browse the repository at this point in the history
  • Loading branch information
TheophileZT committed Nov 13, 2023
1 parent 484b49e commit f2c3d6c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
3 changes: 2 additions & 1 deletion createtable.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
-- Active: 1697465824993@@srv-bdens.insa-toulouse.fr@3306@projet_gei_011
CREATE TABLE IF NOT EXISTS USER(
IdUser INT PRIMARY KEY AUTO_INCREMENT,
UserName VARCHAR(45) NOT NULL UNIQUE,
UserFirstName VARCHAR(20) NOT NULL UNIQUE,
UserLastName VARCHAR(20) NOT NULL UNIQUE,
BirthDate DATETIME NOT NULL,
Email VARCHAR(45) NOT NULL UNIQUE,
UserType ENUM('Helper','Validator','Needer'),
Expand Down
32 changes: 26 additions & 6 deletions src/main/java/controller/Controller.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
package controller;
import java.sql.*;

public class Controller {
Class.forName("com.mysql.jdbc.Driver");
Connection connect = DriverManager.getConnection("srv-bdens.insa-toulouse.fr", "projet_gei_011", "shu6AeNg");
Statement state = connect.createStatement();

Connection connect = Controller.getConnection(srv-bdens.insa-toulouse.fr, projet_gei_011, shu6AeNg);
Statement statement = connect.createStatement();
String query = "SELECT * FROM User";
public static void logIn(String text, char[] password) {

public static int logIn(String email char[] password) {
int logStatus = 0;
String loginAttempt = "EXISTS (SELECT * FROM USER WHERE Email = " + email + " AND Password = " + password + ")";
}
public static void createNewUser(String firstName, String lastName, String email, String password, boolean isNeeder, boolean isVolunteer, boolean isValidator) {
public static int createNewUser(String firstName, String lastName, String email, String password, boolean isNeeder, boolean isVolunteer, boolean isValidator) {
String createUserAttempt = "EXISTS (SELECT * FROM USER WHERE EMAIL = " + email + ")";
ResultSet userExists = state.executeQuery(createUserAttempt);
if (userExists != null){
system.out.println("User already exists");
return 1;
}
String userType = "";
if (isNeeder) {
userType = "Needer";
} else if (isVolunteer) {
userType = "Volunteer";
} else if (isValidator) {
userType = "Validator";
}
String userCreationQuery = "INSERT INTO USER (FirstName, LastName, Email, Password, UserType) VALUES (" + firstName + ", " + lastName + ", " + email + ", " + password + ", " + userType + ")";
ResultSet userCreation = state.executeQuery(userCreationQuery);
return 0;


}
}
24 changes: 6 additions & 18 deletions src/main/java/view/Vue.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,9 @@ private static void createAndShowSignUpForm() {
//Create all the components.
JPanel typePanel = new JPanel();
JPanel formPanel = new JPanel();
JPanel namePanel = new JPanel();
JLabel labelTitle = new JLabel("Sign Up", JLabel.CENTER);
JLabel labelFirstName = new JLabel("First Name");
JTextField textFieldFirstName = new JTextField();
JLabel labelLastName = new JLabel("Last Name");
JTextField textFieldLastName = new JTextField();
JLabel labelName = new JLabel("Name");
JTextField textFieldName = new JTextField();
JLabel labelEmail = new JLabel("Email");
JTextField textFieldEmail = new JTextField();
JLabel labelPassword = new JLabel("Password");
Expand All @@ -61,24 +58,15 @@ private static void createAndShowSignUpForm() {
formPanel.setLayout(new BoxLayout(formPanel, BoxLayout.Y_AXIS));
frame.getContentPane().add(formPanel, "North");
frame.getContentPane().add(validateButton, "South");
namePanel.setLayout(new BoxLayout(namePanel, BoxLayout.X_AXIS));
labelFirstName.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
labelLastName.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));


//Add the components to the panel.
typePanel.add(checkBoxIsNeeder);
typePanel.add(checkBoxIsVolunteer);
typePanel.add(checkBoxIsValidator);

namePanel.add(labelFirstName);
namePanel.add(textFieldFirstName);
namePanel.add(labelLastName);
namePanel.add(textFieldLastName);


formPanel.add(labelTitle);
formPanel.add(namePanel);
formPanel.add(labelName);
formPanel.add(textFieldName);
formPanel.add(typePanel);
formPanel.add(labelEmail);
formPanel.add(textFieldEmail);
Expand Down Expand Up @@ -115,8 +103,8 @@ private static void createAndShowSignUpForm() {
}
});

validateButton.addActionListener(actionEvent -> Controller.createNewUser(textFieldFirstName.getText(),
textFieldLastName.getText(),
validateButton.addActionListener(actionEvent -> Controller.createNewUser(labelTitle.getText(),
textFieldName.getText(),
textFieldEmail.getText(),
Arrays.toString(passwordField.getPassword()),
checkBoxIsNeeder.isSelected(),
Expand Down

0 comments on commit f2c3d6c

Please sign in to comment.