Skip to content
Snippets Groups Projects
Commit 4d4ce506 authored by Adrien's avatar Adrien
Browse files

modifs + bootstrap

parent 8ffe9c61
No related branches found
No related tags found
No related merge requests found
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
......@@ -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
}
......@@ -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;
}
}
}
<%@ 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>
......@@ -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>
<%@ 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
<%@ 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment