diff --git a/S2/DevWeb/Projet/mysql/init.sql b/S2/DevWeb/Projet/mysql/init.sql index fecf4e0..92f7c55 100644 --- a/S2/DevWeb/Projet/mysql/init.sql +++ b/S2/DevWeb/Projet/mysql/init.sql @@ -6,6 +6,7 @@ CREATE TABLE IF NOT EXISTS `user` ( id INT NOT NULL AUTO_INCREMENT, username VARCHAR(255) NOT NULL UNIQUE, + email VARCHAR(255) NOT NULL UNIQUE, password VARCHAR(255) NOT NULL, gender VARCHAR(255) NOT NULL, birth DATE NOT NULL, @@ -15,11 +16,13 @@ CREATE TABLE IF NOT EXISTS `user` -- Table: Game CREATE TABLE IF NOT EXISTS game ( - id INT NOT NULL AUTO_INCREMENT, + id INT NOT NULL AUTO_INCREMENT, + difficulty VARCHAR(255) NOT NULL, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id) ); +-- Table: Player CREATE TABLE IF NOT EXISTS player ( id INT NOT NULL AUTO_INCREMENT, diff --git a/S2/DevWeb/Projet/src/main/java/uppa/project/pojo/Deck.java b/S2/DevWeb/Projet/src/main/java/uppa/project/pojo/Deck.java index cd595f1..e725014 100644 --- a/S2/DevWeb/Projet/src/main/java/uppa/project/pojo/Deck.java +++ b/S2/DevWeb/Projet/src/main/java/uppa/project/pojo/Deck.java @@ -9,16 +9,16 @@ import java.util.Set; public class Deck { private Set cards; - public Deck(){ + public Deck(int nbColors, int nbValues){ cards = new HashSet<>(); - initializeDeck(); + initializeDeck(nbColors, nbValues); shuffleDeck(); } - private void initializeDeck() { - for (Card.Color color : Card.Color.values()){ - for (Card.Value value : Card.Value.values()) { - cards.add(new Card(color, value)); + private void initializeDeck(int nbColors, int nbValues){ + for (int i = 0; i < nbColors; i++) { + for (int j = 0; j < nbValues; j++) { + cards.add(new Card(Card.Color.values()[i], Card.Value.values()[j])); } } } diff --git a/S2/DevWeb/Projet/src/main/java/uppa/project/pojo/Game.java b/S2/DevWeb/Projet/src/main/java/uppa/project/pojo/Game.java index 75b9494..ef1c880 100644 --- a/S2/DevWeb/Projet/src/main/java/uppa/project/pojo/Game.java +++ b/S2/DevWeb/Projet/src/main/java/uppa/project/pojo/Game.java @@ -3,6 +3,8 @@ package uppa.project.pojo; import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; @@ -31,12 +33,28 @@ public class Game implements Serializable { @Column(name="created_at") private Date createdAt; + + @Column(name = "difficulty") + @Enumerated(EnumType.STRING) + private User.Gender difficulty; + @OneToMany(mappedBy = "game", cascade = CascadeType.ALL, fetch = FetchType.LAZY) private Set players; public Game() { } + public Game(User.Gender difficulty) { + this.difficulty = difficulty; + } + + public Game(BigDecimal id, Date createdAt, User.Gender difficulty, Set players) { + this.id = id; + this.createdAt = createdAt; + this.difficulty = difficulty; + this.players = players; + } + @Override public int hashCode() { return Objects.hash(id, createdAt, players); @@ -49,6 +67,14 @@ public class Game implements Serializable { return createdAt; } + public User.Gender getDifficulty() { + return difficulty; + } + + public void setDifficulty(User.Gender difficulty) { + this.difficulty = difficulty; + } + public Set getPlayers() { return players; } @@ -67,4 +93,7 @@ public class Game implements Serializable { public String toString() { return String.format("Game{id=%s, createdAt=%s, players=%s}", id.toString(), createdAt, players); } + + + public static enum difficulty {EASY, HARD} } diff --git a/S2/DevWeb/Projet/src/main/java/uppa/project/pojo/User.java b/S2/DevWeb/Projet/src/main/java/uppa/project/pojo/User.java index add36ed..978c45f 100644 --- a/S2/DevWeb/Projet/src/main/java/uppa/project/pojo/User.java +++ b/S2/DevWeb/Projet/src/main/java/uppa/project/pojo/User.java @@ -32,35 +32,46 @@ public class User implements Serializable { @Column(name = "username") private String username; + + @Column(name = "email") + private String email; + @Column(name = "password") private String password; + @Temporal(TemporalType.DATE) @Column(name = "birth") private Date birth; + @Column(name = "gender") @Enumerated(EnumType.STRING) private Gender gender; + @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.LAZY) private Set playedGame; public User() { } - public User(String username, String password, Date birth, Gender gender) { + public User(String username, String email, String password, Date birth, Gender gender) { this.username = username; + this.email = email; this.password = hashPassword(password); this.birth = birth; this.gender = gender; } - public User(BigDecimal id, String username, String password) { + public User(BigDecimal id, String username, String email, String password, Date birth, Gender gender) { this.id = id; this.username = username; + this.email = email; this.password = password; + this.birth = birth; + this.gender = gender; } @Override public int hashCode() { - return Objects.hash(id, username, password, birth, gender); + return Objects.hash(id, username, email, password, birth, gender); } public BigDecimal getId() { @@ -75,6 +86,14 @@ public class User implements Serializable { this.username = username; } + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + public String getPassword() { return password; } @@ -135,5 +154,5 @@ public class User implements Serializable { return String.format("User{id=%s, username='%s', birth=%s, gender=%s}", id.toString(), username, birth.toString(), gender.toString()); } - public enum Gender {MALE, FEMALE, OTHER} + public static enum Gender {MALE, FEMALE, OTHER} } diff --git a/S2/DevWeb/Projet/src/main/webapp/css/dashboard.css b/S2/DevWeb/Projet/src/main/webapp/css/dashboard.css new file mode 100644 index 0000000..232ae92 --- /dev/null +++ b/S2/DevWeb/Projet/src/main/webapp/css/dashboard.css @@ -0,0 +1,27 @@ +html, body { + width: 100%; + height: 100%; +} + +#main { + display: flex; + flex-direction: column; + align-items: center; +} + +#Title { + text-align: center; + justify-self: center; + font-size: xxx-large; +} + +.main-button { + display: flex; + flex-direction: column; + width: 180px; +} + +input { + font-size: x-large; + margin: 10px 0; +} diff --git a/S2/DevWeb/Projet/src/main/webapp/css/login.css b/S2/DevWeb/Projet/src/main/webapp/css/login.css index c6d78bb..a43afd8 100644 --- a/S2/DevWeb/Projet/src/main/webapp/css/login.css +++ b/S2/DevWeb/Projet/src/main/webapp/css/login.css @@ -16,47 +16,65 @@ main { align-items: center; } +/*Common */ + +hr { + width: 100%; +} + +.border-left { + border-left: ridge; + padding-left: 6%; +} + +/*Section titre*/ #title { width:60%; text-align: center; font-size: xxx-large; } +/*Section login / register*/ #form { - width: 18%; + display: flex; + flex-direction: row; height: 100%; - border-left: ridge; - padding-left: 6%; } h1 { justify-self: center; } -#loginForm, #registerForm { - display: grid; -} - -.field { +.flex-column { display: flex; - flex-direction: row; - width: auto; - justify-content: space-between; - margin: 1%; + flex-direction: column; + justify-content: left; } -#birthdate { - width: 59%; - text-align: right; +.login-gap { + gap: 20px; } -.submit { + +.register-gap { + gap: 75px; +} + + +#login-form, #register-form { + display: grid; + grid-template-columns: 1fr 1fr; + grid-gap: 8% 2%; +} + +#login-submit { + grid-column: 2/2; + grid-row: 3/3; justify-self: right; - width: 35%; - margin: 1%; } -p { - border-top: ridge; - padding-top: 5%; -} +#register-submit { + grid-column: 2/2; + grid-row: 7/7; + justify-self: right; +} diff --git a/S2/DevWeb/Projet/src/main/webapp/css/nav.css b/S2/DevWeb/Projet/src/main/webapp/css/nav.css new file mode 100644 index 0000000..7f4fb65 --- /dev/null +++ b/S2/DevWeb/Projet/src/main/webapp/css/nav.css @@ -0,0 +1,5 @@ +nav { + display: flex; + justify-content: right; + padding: 10px; +} diff --git a/S2/DevWeb/Projet/src/main/webapp/dashboard.jsp b/S2/DevWeb/Projet/src/main/webapp/dashboard.jsp index 78ce09b..a955e5d 100644 --- a/S2/DevWeb/Projet/src/main/webapp/dashboard.jsp +++ b/S2/DevWeb/Projet/src/main/webapp/dashboard.jsp @@ -4,10 +4,20 @@ Dashboard + + - - - +
+ +
+

Titre du jeu

+
+ + + +
+
+
- \ No newline at end of file + diff --git a/S2/DevWeb/Projet/src/main/webapp/index.jsp b/S2/DevWeb/Projet/src/main/webapp/index.jsp index f742a3f..23e6df5 100644 --- a/S2/DevWeb/Projet/src/main/webapp/index.jsp +++ b/S2/DevWeb/Projet/src/main/webapp/index.jsp @@ -1,11 +1,25 @@ +<%@ page import="static jdk.internal.net.http.common.Utils.dump" %> +<%@ page import="uppa.project.pojo.User" %> +<%@ page import="uppa.project.dao.jpa.Game_JPA_DAO_Factory" %> +<%@ page import="uppa.project.dao.DAO" %> <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> +<% + User user = (User) (request.getAttribute("session")); +%> JSP - Hello World - + <% if (user == null) { %> + <%-- Pas de user connecté -> On envoi sur la page de connection --%> + + <% } else { + session.setAttribute("sessionUser", session); + %> + + <% } %> - \ No newline at end of file + diff --git a/S2/DevWeb/Projet/src/main/webapp/js/login.js b/S2/DevWeb/Projet/src/main/webapp/js/login.js index ff21c68..b9c5a69 100644 --- a/S2/DevWeb/Projet/src/main/webapp/js/login.js +++ b/S2/DevWeb/Projet/src/main/webapp/js/login.js @@ -17,9 +17,9 @@ loginForm.addEventListener("submit", (event) => { }) .then(res => res.json()) .then(data => { - if (data) - window.location.href = action; + console.log(data); + if (data.status == 200) window.location.href = action; }) .catch(error => console.error("Error:", error)) ; -}); \ No newline at end of file +}); diff --git a/S2/DevWeb/Projet/src/main/webapp/login.jsp b/S2/DevWeb/Projet/src/main/webapp/login.jsp index e0672df..9048134 100644 --- a/S2/DevWeb/Projet/src/main/webapp/login.jsp +++ b/S2/DevWeb/Projet/src/main/webapp/login.jsp @@ -11,23 +11,27 @@
Titre du jeu
-

Login

-
-
- - +
+ - -
- - -
- - - -

Don't have an account? Register

- -
diff --git a/S2/DevWeb/Projet/src/main/webapp/navBar.jsp b/S2/DevWeb/Projet/src/main/webapp/navBar.jsp new file mode 100644 index 0000000..bdbb3d8 --- /dev/null +++ b/S2/DevWeb/Projet/src/main/webapp/navBar.jsp @@ -0,0 +1,14 @@ +<%-- + 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" %> + diff --git a/S2/DevWeb/Projet/src/main/webapp/newGame.jsp b/S2/DevWeb/Projet/src/main/webapp/newGame.jsp new file mode 100644 index 0000000..d440ca6 --- /dev/null +++ b/S2/DevWeb/Projet/src/main/webapp/newGame.jsp @@ -0,0 +1,43 @@ +<%-- + Created by IntelliJ IDEA. + User: kmitr + Date: 19/03/2024 + Time: 15:47 + To change this template use File | Settings | File Templates. +--%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + Title + + +
+
+

New Game

+
+
+ + + + + + + + +
+
+
+ + + + + + + + <%-- Récuperer les joueurs connecter et les lister sous forme de tableau--%> +
UserGame playedGame wonInvite
+
+
+
+ + diff --git a/S2/DevWeb/Projet/src/main/webapp/register.jsp b/S2/DevWeb/Projet/src/main/webapp/register.jsp index 75b6b5b..98a9de4 100644 --- a/S2/DevWeb/Projet/src/main/webapp/register.jsp +++ b/S2/DevWeb/Projet/src/main/webapp/register.jsp @@ -9,43 +9,44 @@
Titre du jeu
-

Register

-
-
- - +
+
+
+
+

Register

+ + + + + + + + + + + + + + + + + + + + + +
- -
- - +
+
+

Already have an account? Login

- -
- - -
- -
- - -
- - -
- - -
- - - -

Already have an account? Login

- +