diff --git a/Authentication/pom.xml b/Authentication/pom.xml
index ccfaf3f..8837193 100644
--- a/Authentication/pom.xml
+++ b/Authentication/pom.xml
@@ -40,6 +40,13 @@
spring-boot-starter-test
test
+
+
+ com.mysql
+ mysql-connector-j
+ 9.1.0
+
+
diff --git a/Authentication/src/main/java/fr/insa_toulouse/mas/benevolat/Authentication/model/User.java b/Authentication/src/main/java/fr/insa_toulouse/mas/benevolat/Authentication/model/User.java
index b5cf1cb..0b6ef3d 100644
--- a/Authentication/src/main/java/fr/insa_toulouse/mas/benevolat/Authentication/model/User.java
+++ b/Authentication/src/main/java/fr/insa_toulouse/mas/benevolat/Authentication/model/User.java
@@ -1,5 +1,10 @@
package fr.insa_toulouse.mas.benevolat.Authentication.model;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
@@ -11,26 +16,67 @@ public class User {
private Boolean isAdmin;
static HashMap users = new HashMap();
+ static Connection connection;
+
+ static {
+ try {
+ User.connection = DriverManager.getConnection("jdbc:mysql://srv-bdens.insa-toulouse.fr:3306/projet_gei_052?user=projet_gei_052&password=ohc1Eet7");
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ }
static public void saveUser(String name, String password, Boolean isAdmin) {
Random rand = new Random();
int id = rand.nextInt(50000);
User user = new User(name, password, id,isAdmin);
- users.put(id, user);
+ try {
+ Statement statement = User.connection.createStatement();
+ statement.addBatch("INSERT INTO user (id, name, password, isAdmin) VALUES (" + id + ", \"" + user.name + "\", \"" + user.password + "\", " + isAdmin + ");");
+ statement.executeBatch();
+ statement.close();
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ // users.put(id, user);
}
static public int getUserId(String name, String password) {
- for(Map.Entry entry: User.users.entrySet()) {
+
+ int result = -1;
+ try {
+ Statement statement = User.connection.createStatement();
+ System.out.println("Select id FROM user WHERE name = \"" + name + "\" and password = \"" + password + "\";");
+
+ ResultSet res = statement.executeQuery("Select id FROM user WHERE name = \"" + name + "\" and password = \"" + password + "\";");
+ System.out.println("We have a result");
+ result = res.getInt(0);
+ System.out.println("result extracted");
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ /* for(Map.Entry entry: User.users.entrySet()) {
User user = entry.getValue();
if (user.name.equals(name) && user.password.equals(password)) {
return entry.getKey();
}
- }
- return -1;
+ }*/
+ return result;
}
static public Boolean isAdmin(int id) {
- return User.users.get(id).isAdmin;
+ Boolean result = false;
+ try {
+ Statement statement = User.connection.createStatement();
+ ResultSet res = statement.executeQuery("Select isAdmin FROM user WHERE id = " + id + ";");
+
+ result = res.getBoolean("isAdmin");
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+
+ // return User.users.get(id).isAdmin;
+ return result;
}
public User(String name, String password, int id, Boolean isAdmin) {
diff --git a/Authentication/src/main/resources/application.properties b/Authentication/src/main/resources/application.properties
index 698f06e..eab390a 100644
--- a/Authentication/src/main/resources/application.properties
+++ b/Authentication/src/main/resources/application.properties
@@ -1,2 +1,2 @@
spring.application.name=Authentication
-server.port=8090
\ No newline at end of file
+server.port=8091
\ No newline at end of file
diff --git a/RestProject/target/m2e-wtp/web-resources/META-INF/maven/fr.insa.rest/RestProject/pom.properties b/RestProject/target/m2e-wtp/web-resources/META-INF/maven/fr.insa.rest/RestProject/pom.properties
index 5bf22bc..107bea2 100644
--- a/RestProject/target/m2e-wtp/web-resources/META-INF/maven/fr.insa.rest/RestProject/pom.properties
+++ b/RestProject/target/m2e-wtp/web-resources/META-INF/maven/fr.insa.rest/RestProject/pom.properties
@@ -1,5 +1,5 @@
#Generated by Maven Integration for Eclipse
-#Fri Nov 08 09:37:25 CET 2024
+#Wed Nov 13 16:53:34 CET 2024
artifactId=RestProject
groupId=fr.insa.rest
m2e.projectLocation=/home/nbillard/Desktop/5A/SOA/SOA/RestProject