mirror of
https://github.com/kmitresse/Cards-Rush.git
synced 2026-05-13 17:11:49 +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.EntityManagerFactory;
|
||||
import jakarta.persistence.Persistence;
|
||||
import uppa.project.Global;
|
||||
|
||||
/**
|
||||
* Fournisseur d'EntityManager
|
||||
@@ -18,7 +19,7 @@ import jakarta.persistence.Persistence;
|
||||
* @see jakarta.persistence.EntityManager
|
||||
*/
|
||||
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 EntityManagerFactory factory;
|
||||
|
||||
@@ -14,6 +14,7 @@ import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
import javax.mail.Message;
|
||||
import uppa.project.Global;
|
||||
import uppa.project.dao.DAO;
|
||||
import uppa.project.dao.DAOException;
|
||||
import uppa.project.dao.jpa.DAO_JPA_User;
|
||||
@@ -23,8 +24,6 @@ import uppa.project.pojo.User;
|
||||
import java.util.Properties;
|
||||
import javax.mail.*;
|
||||
import javax.mail.internet.*;
|
||||
import uppa.project.provider.DotenvProvider;
|
||||
import io.github.cdimascio.dotenv.Dotenv;
|
||||
|
||||
|
||||
@WebServlet(name = "forgottenPasswordServlet", value = "/forgotten-password")
|
||||
@@ -67,11 +66,10 @@ public class ForgottenPasswordServlet extends HttpServlet {
|
||||
* @param token
|
||||
*/
|
||||
public void sendRecoveryEmail(String email, String token) {
|
||||
Dotenv dotEnv = DotenvProvider.getInstance();
|
||||
String host = dotEnv.get("MAIL_HOST");
|
||||
String port = dotEnv.get("MAIL_PORT");
|
||||
String username = dotEnv.get("MAIL_USERNAME");
|
||||
String password = dotEnv.get("MAIL_PASSWORD");
|
||||
String host = Global.MAIL_HOST;
|
||||
String port = Global.MAIL_PORT;
|
||||
String username = Global.MAIL_USERNAME;
|
||||
String password = Global.MAIL_PASSWORD;
|
||||
|
||||
Properties props = new Properties();
|
||||
props.put("mail.smtp.auth", "true");
|
||||
@@ -87,7 +85,7 @@ public class ForgottenPasswordServlet extends HttpServlet {
|
||||
});
|
||||
|
||||
try {
|
||||
String tomcatHost = dotEnv.get("TOMCAT_HOST");
|
||||
String tomcatHost = Global.TOMCAT_PORT;
|
||||
// Création du message
|
||||
Message message = new MimeMessage(session);
|
||||
message.setFrom(new InternetAddress(username));
|
||||
@@ -95,7 +93,7 @@ public class ForgottenPasswordServlet extends HttpServlet {
|
||||
message.setSubject("Réinitialisation de votre mot de passe");
|
||||
message.setText("Bonjour,\n\n" +
|
||||
"Vous avez demandé la réinitialisation de votre mot de passe.\n" +
|
||||
"Pour cela, veuillez cliquer sur le lien suivant : http://localhost:"+tomcatHost+"/project_war_exploded/reset-password?token=" + token + "\n\n" +
|
||||
"Pour cela, veuillez cliquer sur le lien suivant : http://localhost:"+ tomcatHost +"/project_war_exploded/reset-password?token=" + token + "\n\n" +
|
||||
"Cordialement,\n" +
|
||||
"L'équipe CardRush");
|
||||
// Envoi du message
|
||||
|
||||
Reference in New Issue
Block a user