draft(DevWeb): Create newGame form

This commit is contained in:
Lucàs
2024-04-17 16:54:25 +02:00
parent 469b037232
commit cb8659b63a
11 changed files with 86 additions and 45 deletions
+2 -2
View File
@@ -32,7 +32,7 @@
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
<version>2.9.1</version>
</dependency>
<dependency>
@@ -52,7 +52,7 @@
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
@@ -5,6 +5,7 @@ import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
@@ -16,7 +17,7 @@ public class AuthenticationFilter implements Filter {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
HttpSession session = httpRequest.getSession(false);
HttpSession session = httpRequest.getSession(true);
// Vérifier si l'utilisateur est connecté en vérifiant la présence d'une session
boolean isLoggedIn = (session != null && session.getAttribute("user") != null);
@@ -28,10 +28,7 @@ public class MainMenuServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
User user = (User) request.getSession().getAttribute("user");
// if (user == null) {
// response.sendRedirect(request.getContextPath() + "/login");
// return;
// }
request.setAttribute("current", "main-menu");
manageNewGame(request, response, user);
manageStatistics(request, response, user);
@@ -1,30 +0,0 @@
<%@ page import="uppa.project.database.pojo.User" %>
<%@ page pageEncoding="UTF-8" %>
<%--
Created by IntelliJ IDEA.
User: kmitr
Date: 19/03/2024
Time: 11:42
To change this template use File | Settings | File Templates.
--%>
<%--<%@ page contentType="text/html;charset=UTF-8" language="java" %>--%>
<% String currentPage =(String) request.getAttribute("current"); %>
<style><%@include file="/static/css/navbar.css"%></style>
<nav>
<a href="${pageContext.request.contextPath}/index"><img src="${pageContext.request.contextPath}/static/img/CardsRushLogo.png" alt="Logo CardsRush"> </a>
<% if (currentPage.equals("register") || currentPage.equals("forgotten-password") || currentPage.equals("reset-password")) { %>
<a class="button" href="${pageContext.request.contextPath}/login">Se connecter</a>
<% }
if (currentPage.equals("login") || currentPage.equals("forgotten-password") || currentPage.equals("reset-password")) { %>
<a class="button" href="${pageContext.request.contextPath}/register">S'inscrire</a>
<% } else if (currentPage.equals("main-menu")){ %>
<div class="nav-content">
<% User user = (User) session.getAttribute("user"); %>
<p class="user">
<%= user != null ? user.getUsername() : "anonyme"%> <br/>
<%= user != null ? user.getNbWin() : "0" %> victoires
</p>
<a class="button" href="${pageContext.request.contextPath}/logout">Se déconnecter</a>
</div>
<% } %>
</nav>
@@ -6,7 +6,7 @@
<layout:base>
<jsp:attribute name="title">Cards Rush - Connexion</jsp:attribute>
<jsp:body>
<div class="hero is-light is-fullheight-with-navbar">
<div class="hero is-primary is-fullheight-with-navbar">
<div class="hero-body">
<div class="container">
<div class="columns is-centered">
@@ -6,7 +6,7 @@
<layout:base>
<jsp:attribute name="title">Menu principal</jsp:attribute>
<jsp:body>
<div class="hero is-light is-fullheight-with-navbar">
<div class="hero is-primary is-fullheight-with-navbar">
<div class="hero-body">
<div class="container">
<div class="columns is-centered">
@@ -16,7 +16,7 @@
</jsp:attribute>
<jsp:attribute name="card_content">
<%-- <form:newGame/>--%>
<form:newGame/>
</jsp:attribute>
</component:card>
</div>
@@ -22,10 +22,10 @@
<%if (session.getAttribute("user") != null) {%>
<%-- TODO: Profil de l'utilisateur--%>
<a href="${pageContext.request.contextPath}/profile" class="button is-primary"><strong>Profil</strong></a>
<a href="${pageContext.request.contextPath}/profile" class="button is-primary has-text-white"><strong>Profil</strong></a>
<a href="${pageContext.request.contextPath}/logout" class="button is-danger is-light">Déconnexion</a>
<% } else {%>
<a href="${pageContext.request.contextPath}/register" class="button is-primary"><strong>Inscription</strong></a>
<a href="${pageContext.request.contextPath}/register" class="button is-primary has-text-white"><strong>Inscription</strong></a>
<a href="${pageContext.request.contextPath}/login" class="button is-light">Connexion</a>
<% } %>
</div>
@@ -11,7 +11,7 @@
</div>
<p class="content has-text-right"><a href="${pageContext.request.contextPath}/forgotten-password" class="link">Mot de passe oublié ?</a>
</p>
<input type="submit" class="button is-primary is-fullwidth" value="Connexion">
<input type="submit" class="button is-primary has-text-white is-fullwidth" value="Connexion">
<hr/>
<p class="content has-text-centered"><a href="${pageContext.request.contextPath}/register">S'inscrire</a></p>
@@ -1,12 +1,67 @@
<%@tag description="form/newGame" pageEncoding="UTF-8" %>
<form id="newGame-form" action="${pageContext.request.contextPath}/main-menu" method="post">
<div>
<h2 class="title is-5">Paramètre Général</h2>
<div class="field">
<label class="label">Difficulté</label>
<div class="control columns">
<div class="column">
<label class="radio button is-fullwidth is-primary is-light">
<input type="radio" name="difficulty" checked/>
Facile
</label>
</div>
<div class="column">
<label class="radio button is-fullwidth is-light">
<input type="radio" name="difficulty"/>
Difficile
</label>
</div>
</div>
</div>
<hr/>
<h2 class="title is-5">Paramètre des Manches</h2>
<div class="columns">
<div class="column">
<div class="field">
<label class="label">Nombre de manche</label>
</div>
</div>
<div class="column">
<div class="field">
<label class="label">Durée d'une manche</label>
</div>
</div>
</div>
<hr/>
<h2 class="title is-5">Paramètre du Deck</h2>
<div class="columns">
<div class="column">
<div class="field">
<label class="label">Nombre de valeur par deck</label>
</div>
</div>
<div class="column">
<div class="field">
<label class="label">Nombre de couleur par deck</label>
</div>
</div>
</div>
</form>
<style>
label.radio.button > input[type="radio"] {
display: none;
}
.notification {
position: absolute;
bottom: 0;
@@ -51,6 +106,16 @@
</style>
<script defer type="module">
const radioButtons = document.querySelectorAll('input[type="radio"]');
// if radio is checked, add class 'is-primary' to the parent label
radioButtons.forEach(radio => {
radio.addEventListener('change', () => {
radioButtons.forEach(radio => {
radio.parentElement.classList.remove('is-primary');
});
radio.parentElement.classList.add('is-primary');
});
});
</script>
@@ -38,7 +38,7 @@
</div>
</div>
<input type="submit" class="button is-primary is-fullwidth" value="S'inscrire">
<input type="submit" class="button has-text-white is-primary is-fullwidth" value="S'inscrire">
<hr/>
<p class="content has-text-centered">Déjà inscrit ? <a href="${pageContext.request.contextPath}/login">Se connecter</a></p>
</form>
@@ -14,6 +14,14 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@1.0.0/css/bulma.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css">
<style>
:root {
--bulma-primary-h: 0;
--bulma-primary-s: 70%;
--bulma-primary-l: 35%;
}
</style>
<jsp:invoke fragment="head"/>
</head>
<body>