diff --git a/sae/WEB-INF/src/controleur/Login.java b/sae/WEB-INF/src/controleur/Login.java new file mode 100644 index 0000000000000000000000000000000000000000..9a6205905f431dcf6e95fd3d688b7f600be78a31 --- /dev/null +++ b/sae/WEB-INF/src/controleur/Login.java @@ -0,0 +1,30 @@ +package controleur; + +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import modele.UtilisateurDao; +import jakarta.servlet.ServletException; +import java.io.IOException; + +@WebServlet("/login") +public class Login extends HttpServlet { + public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { + req.getRequestDispatcher("/WEB-INF/vue/login.jsp").forward(req, res); + } + + public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { + String email = req.getParameter("email"); + String motdepasse = req.getParameter("motdepasse"); + UtilisateurDao udao = new UtilisateurDao(); + if (udao.check(email, motdepasse)) { + System.out.println("Connexion réussie"); + req.getSession().setAttribute("email", email); + res.sendRedirect(req.getContextPath() + "/accueil"); + } else { + System.out.println("Connexion échouée"); + res.sendRedirect(req.getContextPath() + "/login"); + } + } +} \ No newline at end of file diff --git a/sae/WEB-INF/src/controleur/AjoutUtilisateur.java b/sae/WEB-INF/src/controleur/Register.java similarity index 78% rename from sae/WEB-INF/src/controleur/AjoutUtilisateur.java rename to sae/WEB-INF/src/controleur/Register.java index f71113cfc20116d2788b3417e266541ff05c3d82..8cded3d8ebd138c1f620a3b1d381c789ca87164b 100644 --- a/sae/WEB-INF/src/controleur/AjoutUtilisateur.java +++ b/sae/WEB-INF/src/controleur/Register.java @@ -10,12 +10,12 @@ import java.io.IOException; import modele.Utilisateur; import modele.UtilisateurDao; -@WebServlet("/ajoutUtilisateur") -public class AjoutUtilisateur extends HttpServlet { +@WebServlet("/register") +public class Register extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { - req.getRequestDispatcher("/WEB-INF/vue/ajoutUtilisateur.jsp").forward(req, res); + req.getRequestDispatcher("/WEB-INF/vue/register.jsp").forward(req, res); } @Override @@ -27,6 +27,6 @@ public class AjoutUtilisateur extends HttpServlet { req.getParameter("motdepasse"), LocalDateTime.now() )); - res.sendRedirect(req.getContextPath() + "/ajoutUtilisateur"); + res.sendRedirect(req.getContextPath() + "/login.jsp"); } -} \ No newline at end of file +} diff --git a/sae/WEB-INF/src/modele/UtilisateurDao.java b/sae/WEB-INF/src/modele/UtilisateurDao.java index aec07343d0474e1a997d677049a8fbec20e488b7..ee5243c9c92e17fc7a3fc98357c990626108a1c4 100644 --- a/sae/WEB-INF/src/modele/UtilisateurDao.java +++ b/sae/WEB-INF/src/modele/UtilisateurDao.java @@ -59,4 +59,17 @@ public class UtilisateurDao { System.out.println(e.getMessage()); } } + + public boolean check(String email, String motDePasse) { + try(Connection con = DS.instance.getConnection()) { + PreparedStatement ps = con.prepareStatement("SELECT * FROM Utilisateur WHERE email = ? AND motDePasse = MD5(?)"); + ps.setString(1, email); + ps.setString(2, motDePasse); + ResultSet rs = ps.executeQuery(); + return rs.next(); + } catch (Exception e) { + System.out.println(e.getMessage()); + return false; + } + } } diff --git a/sae/WEB-INF/vue/ajoutUtilisateur.jsp b/sae/WEB-INF/vue/ajoutUtilisateur.jsp deleted file mode 100644 index 0580ca6cbc9efa5d721a0959b23061cc563f111c..0000000000000000000000000000000000000000 --- a/sae/WEB-INF/vue/ajoutUtilisateur.jsp +++ /dev/null @@ -1,21 +0,0 @@ -<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> - -<!DOCTYPE html> -<html lang="fr"> -<head> - <meta charset="UTF-8"> - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <title>Ajout utilisateur</title> -</head> -<body> - <form action="ajoutUtilisateur" method="post"> - <label for="nom">Nom</label> - <input type="text" name="nom" id="nom"> - <label for="email">Email</label> - <input type="email" name="email" id="email"> - <label for="motdepasse">Mot de passe</label> - <input type="password" name="motdepasse" id="motdepasse"> - <input type="submit" value="Ajouter"> - </form> -</body> -</html> diff --git a/sae/WEB-INF/vue/creationFil.jsp b/sae/WEB-INF/vue/creationFil.jsp index 95a60fc46554a39fa10c91f8682a312285801701..19a38cc5c9b4919efc84d31c22488fa381cdcbb9 100644 --- a/sae/WEB-INF/vue/creationFil.jsp +++ b/sae/WEB-INF/vue/creationFil.jsp @@ -6,15 +6,23 @@ <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Liste des Fils</title> + <!-- Bootstrap CSS --> + <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"> </head> <body> - <h1>Créer un nouveau fil de discussion</h1> - <form action= "creationFil" method="post"> - <label for="nom">Nom du fil:</label> - <input type="text" id="nom" name="nom" required><br><br> - <label for="createuremail">ID du créateur:</label> - <input type="text" id="createuremail" name="createuremail"><br><br> - <input type="submit" value="Créer"> - </form> + <div class="container"> + <h1 class="mt-5">Créer un nouveau fil de discussion</h1> + <form action="creationFil" method="post" class="mt-4"> + <div class="form-group"> + <label for="nom">Nom du fil:</label> + <input type="text" class="form-control" id="nom" name="nom" required> + </div> + <div class="form-group"> + <label for="createuremail">Email du créateur:</label> + <input type="text" class="form-control" id="createuremail" name="createuremail"> + </div> + <button type="submit" class="btn btn-primary">Créer</button> + </form> + </div> </body> -</html> \ No newline at end of file +</html> diff --git a/sae/WEB-INF/vue/login.jsp b/sae/WEB-INF/vue/login.jsp new file mode 100644 index 0000000000000000000000000000000000000000..ea730405671484d9ed873a3d2eb6ad2c100dee79 --- /dev/null +++ b/sae/WEB-INF/vue/login.jsp @@ -0,0 +1,52 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> + +<!DOCTYPE html> +<html lang="fr"> +<head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>CampusTalk - Accueil</title> + <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"> + <style> + body { + background-color: #f8f9fa; + } + .login-container { + max-width: 400px; + margin: 100px auto; + padding: 20px; + background-color: #ffffff; + border-radius: 10px; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); + } + .login-container h2 { + margin-bottom: 20px; + font-weight: bold; + } + </style> +</head> +<body> + <div class="login-container"> + <h2 class="text-center">Bienvenue sur CampusTalk</h2> + <!-- formulaire pour se connecter --> + <form action="login" method="post"> + <div class="form-group"> + <label for="email">Adresse e-mail</label> + <input type="email" class="form-control" name="email" id="email" placeholder="Entrez votre e-mail" required> + </div> + <div class="form-group"> + <label for="motdepasse">Mot de passe</label> + <input type="password" class="form-control" name="motdepasse" id="motdepasse" placeholder="Entrez votre mot de passe" required> + </div> + <button type="submit" class="btn btn-primary btn-block">Se connecter</button> + </form> + <div class="text-center mt-3"> + <p>Vous n'avez pas de compte ? <a href="<%= request.getContextPath() %>/register">S'inscrire</a></p> + </div> + </div> + + <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script> + <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js"></script> + <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script> +</body> +</html> \ No newline at end of file diff --git a/sae/WEB-INF/vue/register.jsp b/sae/WEB-INF/vue/register.jsp new file mode 100644 index 0000000000000000000000000000000000000000..0a2f1c192a9b44bfa5e57eca80d72854059bf748 --- /dev/null +++ b/sae/WEB-INF/vue/register.jsp @@ -0,0 +1,56 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> + +<!DOCTYPE html> +<html lang="fr"> +<head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>CampusTalk - Inscription</title> + <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"> + <style> + body { + background-color: #f8f9fa; + } + .register-container { + max-width: 400px; + margin: 100px auto; + padding: 20px; + background-color: #ffffff; + border-radius: 10px; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); + } + .register-container h2 { + margin-bottom: 20px; + font-weight: bold; + } + </style> +</head> +<body> + <div class="register-container"> + <h2 class="text-center">Inscription</h2> + <!-- Formulaire pour s'inscrire --> + <form action="ajoutUtilisateur" method="post"> + <div class="form-group"> + <label for="nom">Nom</label> + <input type="text" class="form-control" name="nom" id="nom" placeholder="Entrez votre nom" required> + </div> + <div class="form-group"> + <label for="email">Adresse e-mail</label> + <input type="email" class="form-control" name="email" id="email" placeholder="Entrez votre e-mail" required> + </div> + <div class="form-group"> + <label for="motdepasse">Mot de passe</label> + <input type="password" class="form-control" name="motdepasse" id="motdepasse" placeholder="Choisissez un mot de passe" required> + </div> + <button type="submit" class="btn btn-primary btn-block">S'inscrire</button> + </form> + <div class="text-center mt-3"> + <p>Vous avez déjà un compte ? <a href="<%= request.getContextPath() %>/login">Se connecter</a></p> + </div> + </div> + + <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script> + <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js"></script> + <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script> +</body> +</html> \ No newline at end of file