mirror of
https://github.com/kmitresse/Cards-Rush.git
synced 2026-07-09 13:27:45 +00:00
fix: dev-web - fix .Env access
This commit is contained in:
@@ -0,0 +1,14 @@
|
|||||||
|
package uppa.project;
|
||||||
|
|
||||||
|
public class Global {
|
||||||
|
|
||||||
|
public static final String PERSISTENCE_UNIT_NAME = "prod";
|
||||||
|
public static final String PERSISTENCE_UNIT_NAME_TEST = "test";
|
||||||
|
public static final String TOMCAT_PORT = "8088";
|
||||||
|
public static final String MAIL_USERNAME = "kmitresse@gmail.com";
|
||||||
|
public static final String MAIL_PASSWORD = "xwos ujwf cesq ocyt";
|
||||||
|
public static final String MAIL_PORT = "587";
|
||||||
|
public static final String MAIL_HOST = "smtp.gmail.com";
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
package uppa.project.provider;
|
|
||||||
|
|
||||||
import io.github.cdimascio.dotenv.Dotenv;
|
|
||||||
|
|
||||||
public class DotenvProvider {
|
|
||||||
static Dotenv instance;
|
|
||||||
|
|
||||||
public static Dotenv getInstance() {
|
|
||||||
if (instance == null) {
|
|
||||||
instance = Dotenv.configure().load();
|
|
||||||
}
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,6 +9,7 @@ package uppa.project.provider;
|
|||||||
import jakarta.persistence.EntityManager;
|
import jakarta.persistence.EntityManager;
|
||||||
import jakarta.persistence.EntityManagerFactory;
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
import jakarta.persistence.Persistence;
|
import jakarta.persistence.Persistence;
|
||||||
|
import uppa.project.Global;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fournisseur d'EntityManager
|
* Fournisseur d'EntityManager
|
||||||
@@ -18,7 +19,7 @@ import jakarta.persistence.Persistence;
|
|||||||
* @see jakarta.persistence.EntityManager
|
* @see jakarta.persistence.EntityManager
|
||||||
*/
|
*/
|
||||||
public final class EntityManagerProvider {
|
public final class EntityManagerProvider {
|
||||||
private static final String PERSISTENCE_UNIT_NAME = DotenvProvider.getInstance().get("PERSISTENCE_UNIT_NAME");
|
private static final String PERSISTENCE_UNIT_NAME = Global.PERSISTENCE_UNIT_NAME;
|
||||||
|
|
||||||
private static EntityManager instance;
|
private static EntityManager instance;
|
||||||
private static EntityManagerFactory factory;
|
private static EntityManagerFactory factory;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import jakarta.servlet.http.HttpServletResponse;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import javax.mail.Message;
|
import javax.mail.Message;
|
||||||
|
import uppa.project.Global;
|
||||||
import uppa.project.dao.DAO;
|
import uppa.project.dao.DAO;
|
||||||
import uppa.project.dao.DAOException;
|
import uppa.project.dao.DAOException;
|
||||||
import uppa.project.dao.jpa.DAO_JPA_User;
|
import uppa.project.dao.jpa.DAO_JPA_User;
|
||||||
@@ -23,8 +24,6 @@ import uppa.project.pojo.User;
|
|||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import javax.mail.*;
|
import javax.mail.*;
|
||||||
import javax.mail.internet.*;
|
import javax.mail.internet.*;
|
||||||
import uppa.project.provider.DotenvProvider;
|
|
||||||
import io.github.cdimascio.dotenv.Dotenv;
|
|
||||||
|
|
||||||
|
|
||||||
@WebServlet(name = "forgottenPasswordServlet", value = "/forgotten-password")
|
@WebServlet(name = "forgottenPasswordServlet", value = "/forgotten-password")
|
||||||
@@ -67,11 +66,10 @@ public class ForgottenPasswordServlet extends HttpServlet {
|
|||||||
* @param token
|
* @param token
|
||||||
*/
|
*/
|
||||||
public void sendRecoveryEmail(String email, String token) {
|
public void sendRecoveryEmail(String email, String token) {
|
||||||
Dotenv dotEnv = DotenvProvider.getInstance();
|
String host = Global.MAIL_HOST;
|
||||||
String host = dotEnv.get("MAIL_HOST");
|
String port = Global.MAIL_PORT;
|
||||||
String port = dotEnv.get("MAIL_PORT");
|
String username = Global.MAIL_USERNAME;
|
||||||
String username = dotEnv.get("MAIL_USERNAME");
|
String password = Global.MAIL_PASSWORD;
|
||||||
String password = dotEnv.get("MAIL_PASSWORD");
|
|
||||||
|
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
props.put("mail.smtp.auth", "true");
|
props.put("mail.smtp.auth", "true");
|
||||||
@@ -87,7 +85,7 @@ public class ForgottenPasswordServlet extends HttpServlet {
|
|||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String tomcatHost = dotEnv.get("TOMCAT_HOST");
|
String tomcatHost = Global.TOMCAT_PORT;
|
||||||
// Création du message
|
// Création du message
|
||||||
Message message = new MimeMessage(session);
|
Message message = new MimeMessage(session);
|
||||||
message.setFrom(new InternetAddress(username));
|
message.setFrom(new InternetAddress(username));
|
||||||
|
|||||||
Reference in New Issue
Block a user