ClementColmerauer commited on 2024-10-20 08:22:05
Showing 6374 changed files, with 5027 additions and 0 deletions.
| ... | ... |
@@ -0,0 +1,37 @@ |
| 1 |
+// Top-level build file where you can add configuration options common to all sub-projects/modules. |
|
| 2 |
+apply plugin: 'java' |
|
| 3 |
+apply plugin: 'application' |
|
| 4 |
+ |
|
| 5 |
+mainClassName='com.uca.StartServer' |
|
| 6 |
+ |
|
| 7 |
+repositories {
|
|
| 8 |
+ mavenCentral() |
|
| 9 |
+} |
|
| 10 |
+ |
|
| 11 |
+dependencies {
|
|
| 12 |
+ implementation 'org.freemarker:freemarker:2.3.30' |
|
| 13 |
+ implementation 'com.sparkjava:spark-core:2.9.3' |
|
| 14 |
+ implementation 'com.h2database:h2:1.4.200' |
|
| 15 |
+ implementation 'org.json:json:20211205' |
|
| 16 |
+ implementation 'org.mindrot:jbcrypt:0.4' |
|
| 17 |
+ implementation 'org.slf4j:slf4j-nop:1.7.25' |
|
| 18 |
+ compile 'io.jsonwebtoken:jjwt-api:0.11.2' |
|
| 19 |
+ runtime 'io.jsonwebtoken:jjwt-impl:0.11.2', 'io.jsonwebtoken:jjwt-jackson:0.11.2' |
|
| 20 |
+ compile 'org.mindrot:jbcrypt:0.4' |
|
| 21 |
+ compile 'com.fasterxml.jackson.core:jackson-databind:2.11.1' |
|
| 22 |
+ compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.11.1' |
|
| 23 |
+} |
|
| 24 |
+test {
|
|
| 25 |
+ useJUnitPlatform() |
|
| 26 |
+} |
|
| 27 |
+ |
|
| 28 |
+jar {
|
|
| 29 |
+ manifest {
|
|
| 30 |
+ attributes 'Implementation-Title': 'Gradle Quickstart', |
|
| 31 |
+ 'Implementation-Version': '1.0.0', |
|
| 32 |
+ 'Main-Class': 'com.uca.StartServer' |
|
| 33 |
+ } |
|
| 34 |
+} |
|
| 35 |
+ |
|
| 36 |
+sourceSets.main.java.srcDirs = ['src'] |
|
| 37 |
+sourceSets.test.java.srcDirs = ['src'] |
| ... | ... |
@@ -0,0 +1,78 @@ |
| 1 |
+<!DOCTYPE html> |
|
| 2 |
+<html lang = "fr"> |
|
| 3 |
+<head> |
|
| 4 |
+ <meta charset="utf-8"> |
|
| 5 |
+ <meta name="viewport" content="width=device-width, initial-scale=1"> |
|
| 6 |
+ <link rel="stylesheet" type="text/css" href="style.css" media="screen"> |
|
| 7 |
+ |
|
| 8 |
+ |
|
| 9 |
+ <title></title> |
|
| 10 |
+ |
|
| 11 |
+ |
|
| 12 |
+ |
|
| 13 |
+</head> |
|
| 14 |
+ |
|
| 15 |
+<body> |
|
| 16 |
+ |
|
| 17 |
+ <div class="container"> |
|
| 18 |
+ <div class = logsign> |
|
| 19 |
+ <form action="/signup" method="post" id="signup" class = form> |
|
| 20 |
+ <h1>Signup</h1> |
|
| 21 |
+ <div class="field"> |
|
| 22 |
+ <label for="lastname">Pseudo :</label> |
|
| 23 |
+ <input type="text" id="pseudo" name="pseudo" placeholder="Enter you pseudo" > |
|
| 24 |
+ <small></small> |
|
| 25 |
+ </div> |
|
| 26 |
+ |
|
| 27 |
+ <div class="field"> |
|
| 28 |
+ <label for="userpwd">Password :</label> |
|
| 29 |
+ <input type="password" id="userpwd" name="userpwd" placeholder="Entrez votre mot de passe ici" > |
|
| 30 |
+ <small></small> |
|
| 31 |
+ </div> |
|
| 32 |
+ |
|
| 33 |
+ <div class="field"> |
|
| 34 |
+ <label for="usermail">Email:</label> |
|
| 35 |
+ <input type="text" id="usermail" name="usermail" placeholder="Enter your email address" > |
|
| 36 |
+ <small></small> |
|
| 37 |
+ </div> |
|
| 38 |
+ <div class="field"> |
|
| 39 |
+ <button type="submit" class="full">Signin</button> |
|
| 40 |
+ </div> |
|
| 41 |
+ <div id="zoneSignup"> |
|
| 42 |
+ <span class="Style1"></span> |
|
| 43 |
+ </div> |
|
| 44 |
+ </form> |
|
| 45 |
+ |
|
| 46 |
+ |
|
| 47 |
+ <form action="/login" method="post" id="login" class = form> |
|
| 48 |
+ <h1>Login</h1> |
|
| 49 |
+ |
|
| 50 |
+ <div class="field"> |
|
| 51 |
+ <label for="usermail">Email:</label> |
|
| 52 |
+ <input type="text" id="usermail" name="usermail" placeholder="Enter your email address" > |
|
| 53 |
+ <small></small> |
|
| 54 |
+ </div> |
|
| 55 |
+ |
|
| 56 |
+ <div class="field"> |
|
| 57 |
+ <label for="userpwd">Password :</label> |
|
| 58 |
+ <input type="password" id="userpwd" name="userpwd" placeholder="Entrez votre mot de passe ici" > |
|
| 59 |
+ <small></small> |
|
| 60 |
+ </div> |
|
| 61 |
+ |
|
| 62 |
+ |
|
| 63 |
+ <div class="field"> |
|
| 64 |
+ <button type="submit" class="full">Login</button> |
|
| 65 |
+ </div> |
|
| 66 |
+ <div id="zone"> |
|
| 67 |
+ <span class="Style1"></span> |
|
| 68 |
+ </div> |
|
| 69 |
+ </form> |
|
| 70 |
+ </div> |
|
| 71 |
+ |
|
| 72 |
+ |
|
| 73 |
+ </div> |
|
| 74 |
+ |
|
| 75 |
+ |
|
| 76 |
+ |
|
| 77 |
+</body> |
|
| 78 |
+</html> |
|
| 0 | 79 |
\ No newline at end of file |
| ... | ... |
@@ -0,0 +1,78 @@ |
| 1 |
+body{
|
|
| 2 |
+ display: block; |
|
| 3 |
+ margin: 0; |
|
| 4 |
+} |
|
| 5 |
+ |
|
| 6 |
+ul{
|
|
| 7 |
+ list-style-type: disc; |
|
| 8 |
+ margin-block-start: 0; |
|
| 9 |
+ margin-block-end: 0; |
|
| 10 |
+ padding-inline-start: 0; |
|
| 11 |
+} |
|
| 12 |
+ |
|
| 13 |
+.profil{
|
|
| 14 |
+ position: fixed; |
|
| 15 |
+ height: 300px; |
|
| 16 |
+ width: 98vw; |
|
| 17 |
+ margin : 1vw; |
|
| 18 |
+ border: 2px solid black; |
|
| 19 |
+ bottom: 0; |
|
| 20 |
+ z-index: 10; |
|
| 21 |
+ background-color: lightgray; |
|
| 22 |
+} |
|
| 23 |
+ |
|
| 24 |
+.pkList{
|
|
| 25 |
+ display: grid; |
|
| 26 |
+ grid-template-columns: repeat(6, 1fr); |
|
| 27 |
+ column-gap: 1vw; |
|
| 28 |
+ row-gap: 1vh; |
|
| 29 |
+ margin: 1vw; |
|
| 30 |
+} |
|
| 31 |
+ |
|
| 32 |
+.pkListItem > img{
|
|
| 33 |
+ width: 75%; |
|
| 34 |
+ height: auto; |
|
| 35 |
+ align-content: center; |
|
| 36 |
+} |
|
| 37 |
+ |
|
| 38 |
+li{
|
|
| 39 |
+ list-style-type: none; |
|
| 40 |
+} |
|
| 41 |
+ |
|
| 42 |
+.pkListItem |
|
| 43 |
+{
|
|
| 44 |
+ text-align: center; |
|
| 45 |
+ border : 2px solid black; |
|
| 46 |
+ max-width: 15vw; |
|
| 47 |
+ height: auto; |
|
| 48 |
+} |
|
| 49 |
+ |
|
| 50 |
+.exchange{
|
|
| 51 |
+ display: flex; /* afficher les éléments en ligne */ |
|
| 52 |
+ flex-wrap: wrap; /* permettre aux éléments de passer à la ligne si nécessaire */ |
|
| 53 |
+ justify-content: space-between; /* aligner les éléments en début et fin de ligne */ |
|
| 54 |
+ align-items: center; /* centrer verticalement les éléments */ |
|
| 55 |
+ padding: 10px; /* ajouter un peu d'espace autour de chaque élément */ |
|
| 56 |
+ border: 1px solid #ccc; /* ajouter une bordure pour séparer chaque élément */ |
|
| 57 |
+ margin-bottom: 10px; /* ajouter un peu d'espace entre chaque élément */ |
|
| 58 |
+} |
|
| 59 |
+ |
|
| 60 |
+.exchange{
|
|
| 61 |
+ dsiplay:block; |
|
| 62 |
+} |
|
| 63 |
+ |
|
| 64 |
+.exchangeForm |
|
| 65 |
+{
|
|
| 66 |
+ display: inline-flex; |
|
| 67 |
+} |
|
| 68 |
+ |
|
| 69 |
+.left{
|
|
| 70 |
+ float:left; |
|
| 71 |
+ max-width: 50%; |
|
| 72 |
+ margin:1vw; |
|
| 73 |
+} |
|
| 74 |
+ |
|
| 75 |
+nav{
|
|
| 76 |
+ margin:1vw; |
|
| 77 |
+ float:right; |
|
| 78 |
+} |
| ... | ... |
@@ -0,0 +1,72 @@ |
| 1 |
+<#ftl encoding="utf-8"> |
|
| 2 |
+<!DOCTYPE html> |
|
| 3 |
+<html> |
|
| 4 |
+<head> |
|
| 5 |
+<link rel="stylesheet" type="text/css" href="/style.css" media="screen"> |
|
| 6 |
+ |
|
| 7 |
+<title></title> |
|
| 8 |
+</head> |
|
| 9 |
+<body xmlns="http://www.w3.org/1999/html"> |
|
| 10 |
+ |
|
| 11 |
+<ul> |
|
| 12 |
+ <#list exchanges as exchange> |
|
| 13 |
+ |
|
| 14 |
+ <li class = exchange> |
|
| 15 |
+ <div class = pokemon> |
|
| 16 |
+ <p>By ${(exchange.user1.pseudo)!} </p>
|
|
| 17 |
+ <img src = ${(exchange.pkm1.sprite)!} alt = ${(exchange.pkm1.name)!}</img>
|
|
| 18 |
+ <h3>${(exchange.pkm1.name)!}</h3>
|
|
| 19 |
+ <p>${(exchange.pkm1.lvl)!}</p>
|
|
| 20 |
+ </div> |
|
| 21 |
+ <div class = "pokemon"> |
|
| 22 |
+ <#if exchange.dataPkm2?has_content> |
|
| 23 |
+ <p>By ${(exchange.user2.pseudo)!} </p>
|
|
| 24 |
+ <img src = ${(exchange.dataPkm2.sprite)!} alt = ${(exchange.dataPkm2.name)!}</img>
|
|
| 25 |
+ <h3>${(exchange.dataPkm2.name)!}</h3>
|
|
| 26 |
+ <p>${(exchange.dataPkm2.lvl)!}</p>
|
|
| 27 |
+ </div> |
|
| 28 |
+ <form action = "/exchange/${(exchange.id)!}/accepted" method = "POST">
|
|
| 29 |
+ <button>Accept</button> |
|
| 30 |
+ </form> |
|
| 31 |
+ <#else> |
|
| 32 |
+ <form action = "/exchange/${(exchange.id)!}/selectPokemon" method = "GET" >
|
|
| 33 |
+ <#if exchange.idPkm2?? && exchange.idPkm2.id == 0> |
|
| 34 |
+ <input type="hidden" name="pkmId" value="0"> |
|
| 35 |
+ <img src = "/pokemonSprite/0.png" alt = "Any pokemon"</img> <br> |
|
| 36 |
+ <#else> |
|
| 37 |
+ <input type="hidden" name="pkmId" value="${exchange.idPkm2.id}">
|
|
| 38 |
+ <img src = "${(exchange.idPkm2.sprite)!}" alt = "${(exchange.idPkm2.name)!}"</img>
|
|
| 39 |
+ </#if> |
|
| 40 |
+ <input type="hidden" name="pkmShiny" value="${exchange.idPkm2.shiny?c}">
|
|
| 41 |
+ <#if exchange.idPkm2?? && exchange.idPkm2.name?has_content> |
|
| 42 |
+ |
|
| 43 |
+ <#if exchange.idPkm2.shiny> |
|
| 44 |
+ <h3>Shiny ${(exchange.idPkm2.name)!}</h3>
|
|
| 45 |
+ <#else> |
|
| 46 |
+ <h3>${(exchange.idPkm2.name)!}</h3>
|
|
| 47 |
+ </#if> |
|
| 48 |
+ <#else> |
|
| 49 |
+ <h3>Any pokemon</h3> |
|
| 50 |
+ </#if> |
|
| 51 |
+ <#if exchange.idPkm2?? && exchange.idPkm2.lvl == 0> |
|
| 52 |
+ <input type="hidden" name="pkmLvl" value="0"> |
|
| 53 |
+ <h3>Any level</h3> |
|
| 54 |
+ <#else> |
|
| 55 |
+ <input type="hidden" name="pkmLvl" value="${exchange.idPkm2.lvl}">
|
|
| 56 |
+ <h3>At least level ${(exchange.idPkm2.lvl)!}</h3>
|
|
| 57 |
+ </#if> |
|
| 58 |
+ |
|
| 59 |
+ <button>Choose</button> |
|
| 60 |
+ </form> |
|
| 61 |
+ </div> |
|
| 62 |
+ <div></div> |
|
| 63 |
+ </#if> |
|
| 64 |
+ |
|
| 65 |
+ </div> |
|
| 66 |
+ </li> |
|
| 67 |
+ </#list> |
|
| 68 |
+</ul> |
|
| 69 |
+ |
|
| 70 |
+</body> |
|
| 71 |
+ |
|
| 72 |
+</html> |
| ... | ... |
@@ -0,0 +1,42 @@ |
| 1 |
+<#ftl encoding="utf-8"> |
|
| 2 |
+<!DOCTYPE html> |
|
| 3 |
+<html> |
|
| 4 |
+<head> |
|
| 5 |
+<link rel="stylesheet" type="text/css" href="/style.css" media="screen"> |
|
| 6 |
+ |
|
| 7 |
+<title></title> |
|
| 8 |
+</head> |
|
| 9 |
+<body xmlns="http://www.w3.org/1999/html"> |
|
| 10 |
+ |
|
| 11 |
+<ul> |
|
| 12 |
+ <#list exchanges as exchange> |
|
| 13 |
+ |
|
| 14 |
+ <li class = exchange> |
|
| 15 |
+ <div class = pokemon> |
|
| 16 |
+ <p>From ${(exchange.user1.pseudo)!} </p>
|
|
| 17 |
+ <img src = ${(exchange.pkm1.sprite)!} alt = ${(exchange.pkm1.name)!}</img>
|
|
| 18 |
+ <h3>${(exchange.pkm1.name)!}</h3>
|
|
| 19 |
+ <p>${(exchange.pkm1.lvl)!}</p>
|
|
| 20 |
+ </div> |
|
| 21 |
+ <div class = "pokemon"> |
|
| 22 |
+ <p>Your pokemon </p> |
|
| 23 |
+ <img src = ${(exchange.dataPkm2.sprite)!} alt = ${(exchange.dataPkm2.name)!}</img>
|
|
| 24 |
+ <h3>${(exchange.dataPkm2.name)!}</h3>
|
|
| 25 |
+ <p>${(exchange.dataPkm2.lvl)!}</p>
|
|
| 26 |
+ </div> |
|
| 27 |
+ <div> |
|
| 28 |
+ |
|
| 29 |
+ <form action = "/exchange/${(exchange.id)!}/accepted" method = "POST">
|
|
| 30 |
+ <button>Accept</button> |
|
| 31 |
+ </form> |
|
| 32 |
+ <form action = "/exchange/${(exchange.id)!}/refused" method = "POST">
|
|
| 33 |
+ <button>Refuse</button> |
|
| 34 |
+ </form> |
|
| 35 |
+ </div> |
|
| 36 |
+ </li> |
|
| 37 |
+ </#list> |
|
| 38 |
+</ul> |
|
| 39 |
+ |
|
| 40 |
+</body> |
|
| 41 |
+ |
|
| 42 |
+</html> |
| ... | ... |
@@ -0,0 +1,72 @@ |
| 1 |
+<#ftl encoding="utf-8"> |
|
| 2 |
+<!DOCTYPE html> |
|
| 3 |
+<html> |
|
| 4 |
+<head> |
|
| 5 |
+<link rel="stylesheet" type="text/css" href="/style.css" media="screen"> |
|
| 6 |
+ |
|
| 7 |
+<title></title> |
|
| 8 |
+</head> |
|
| 9 |
+<body xmlns="http://www.w3.org/1999/html"> |
|
| 10 |
+ |
|
| 11 |
+<ul> |
|
| 12 |
+ <#list exchanges as exchange> |
|
| 13 |
+ |
|
| 14 |
+ <li class = exchange> |
|
| 15 |
+ <div class = pokemon> |
|
| 16 |
+ <p>By ${(exchange.user1.pseudo)!} </p>
|
|
| 17 |
+ <img src = ${(exchange.pkm1.sprite)!} alt = ${(exchange.pkm1.name)!}</img>
|
|
| 18 |
+ <h3>${(exchange.pkm1.name)!}</h3>
|
|
| 19 |
+ <p>${(exchange.pkm1.lvl)!}</p>
|
|
| 20 |
+ </div> |
|
| 21 |
+ <div class = "pokemon"> |
|
| 22 |
+ <#if exchange.dataPkm2?has_content> |
|
| 23 |
+ <p>By ${(exchange.user2.pseudo)!} </p>
|
|
| 24 |
+ <img src = ${(exchange.dataPkm2.sprite)!} alt = ${(exchange.dataPkm2.name)!}</img>
|
|
| 25 |
+ <h3>${(exchange.dataPkm2.name)!}</h3>
|
|
| 26 |
+ <p>${(exchange.dataPkm2.lvl)!}</p>
|
|
| 27 |
+ </div> |
|
| 28 |
+ <form action = "/exchange/${(exchange.id)!}/accepted" method = "POST">
|
|
| 29 |
+ <button>Accept</button> |
|
| 30 |
+ </form> |
|
| 31 |
+ <#else> |
|
| 32 |
+ <form action = "/exchange/${(exchange.id)!}/selectPokemon" method = "GET" >
|
|
| 33 |
+ <#if exchange.idPkm2?? && exchange.idPkm2.id == 0> |
|
| 34 |
+ <input type="hidden" name="pkmId" value="0"> |
|
| 35 |
+ <img src = "/pokemonSprite/0.png" alt = "Any pokemon"</img> <br> |
|
| 36 |
+ <#else> |
|
| 37 |
+ <input type="hidden" name="pkmId" value="${exchange.idPkm2.id}">
|
|
| 38 |
+ <img src = "${(exchange.idPkm2.sprite)!}" alt = "${(exchange.idPkm2.name)!}"</img>
|
|
| 39 |
+ </#if> |
|
| 40 |
+ <input type="hidden" name="pkmShiny" value="${exchange.idPkm2.shiny?c}">
|
|
| 41 |
+ <#if exchange.idPkm2?? && exchange.idPkm2.name?has_content> |
|
| 42 |
+ |
|
| 43 |
+ <#if exchange.idPkm2.shiny> |
|
| 44 |
+ <h3>Shiny ${(exchange.idPkm2.name)!}</h3>
|
|
| 45 |
+ <#else> |
|
| 46 |
+ <h3>${(exchange.idPkm2.name)!}</h3>
|
|
| 47 |
+ </#if> |
|
| 48 |
+ <#else> |
|
| 49 |
+ <h3>Any pokemon</h3> |
|
| 50 |
+ </#if> |
|
| 51 |
+ <#if exchange.idPkm2?? && exchange.idPkm2.lvl == 0> |
|
| 52 |
+ <input type="hidden" name="pkmLvl" value="0"> |
|
| 53 |
+ <h3>Any level</h3> |
|
| 54 |
+ <#else> |
|
| 55 |
+ <input type="hidden" name="pkmLvl" value="${exchange.idPkm2.lvl}">
|
|
| 56 |
+ <h3>At least level ${(exchange.idPkm2.lvl)!}</h3>
|
|
| 57 |
+ </#if> |
|
| 58 |
+ |
|
| 59 |
+ <button>Choose</button> |
|
| 60 |
+ </form> |
|
| 61 |
+ </div> |
|
| 62 |
+ <div></div> |
|
| 63 |
+ </#if> |
|
| 64 |
+ |
|
| 65 |
+ </div> |
|
| 66 |
+ </li> |
|
| 67 |
+ </#list> |
|
| 68 |
+</ul> |
|
| 69 |
+ |
|
| 70 |
+</body> |
|
| 71 |
+ |
|
| 72 |
+</html> |
| ... | ... |
@@ -0,0 +1,73 @@ |
| 1 |
+<#ftl encoding="utf-8"> |
|
| 2 |
+<!DOCTYPE html> |
|
| 3 |
+<html> |
|
| 4 |
+<head> |
|
| 5 |
+<link rel="stylesheet" type="text/css" href="/style.css" media="screen"> |
|
| 6 |
+ |
|
| 7 |
+<title></title> |
|
| 8 |
+</head> |
|
| 9 |
+<body xmlns="http://www.w3.org/1999/html"> |
|
| 10 |
+ |
|
| 11 |
+<ul> |
|
| 12 |
+ <#list exchanges as exchange> |
|
| 13 |
+ |
|
| 14 |
+ <li class = exchange> |
|
| 15 |
+ <div class = pokemon> |
|
| 16 |
+ <p>By ${(exchange.user1.pseudo)!} </p>
|
|
| 17 |
+ <img src = ${(exchange.pkm1.sprite)!} alt = ${(exchange.pkm1.name)!}</img>
|
|
| 18 |
+ <h3>${(exchange.pkm1.name)!}</h3>
|
|
| 19 |
+ <p>${(exchange.pkm1.lvl)!}</p>
|
|
| 20 |
+ </div> |
|
| 21 |
+ <div class = "pokemon"> |
|
| 22 |
+ <#if exchange.dataPkm2?has_content> |
|
| 23 |
+ <p>By ${(exchange.user2.pseudo)!} </p>
|
|
| 24 |
+ <img src = ${(exchange.dataPkm2.sprite)!} alt = ${(exchange.dataPkm2.name)!}</img>
|
|
| 25 |
+ <h3>${(exchange.dataPkm2.name)!}</h3>
|
|
| 26 |
+ <p>${(exchange.dataPkm2.lvl)!}</p>
|
|
| 27 |
+ </div> |
|
| 28 |
+ <#else> |
|
| 29 |
+ <form action = "/exchange/${(exchange.id)!}/selectPokemon" method = "GET" >
|
|
| 30 |
+ <#if exchange.idPkm2?? && exchange.idPkm2.id == 0> |
|
| 31 |
+ <input type="hidden" name="pkmId" value="0"> |
|
| 32 |
+ <img src = "/pokemonSprite/0.png" alt = "Any pokemon"</img> <br> |
|
| 33 |
+ <#else> |
|
| 34 |
+ <input type="hidden" name="pkmId" value="${exchange.idPkm2.id}">
|
|
| 35 |
+ <img src = "${(exchange.idPkm2.sprite)!}" alt = "${(exchange.idPkm2.name)!}"</img>
|
|
| 36 |
+ </#if> |
|
| 37 |
+ <input type="hidden" name="pkmShiny" value="${exchange.idPkm2.shiny?c}">
|
|
| 38 |
+ <#if exchange.idPkm2?? && exchange.idPkm2.name?has_content> |
|
| 39 |
+ |
|
| 40 |
+ <#if exchange.idPkm2.shiny> |
|
| 41 |
+ <h3>Shiny ${(exchange.idPkm2.name)!}</h3>
|
|
| 42 |
+ <#else> |
|
| 43 |
+ <h3>${(exchange.idPkm2.name)!}</h3>
|
|
| 44 |
+ </#if> |
|
| 45 |
+ <#else> |
|
| 46 |
+ <h3>Any pokemon</h3> |
|
| 47 |
+ </#if> |
|
| 48 |
+ <#if exchange.idPkm2?? && exchange.idPkm2.lvl == 0> |
|
| 49 |
+ <input type="hidden" name="pkmLvl" value="0"> |
|
| 50 |
+ <h3>Any level</h3> |
|
| 51 |
+ <#else> |
|
| 52 |
+ <input type="hidden" name="pkmLvl" value="${exchange.idPkm2.lvl}">
|
|
| 53 |
+ <h3>At least level ${(exchange.idPkm2.lvl)!}</h3>
|
|
| 54 |
+ </#if> |
|
| 55 |
+ |
|
| 56 |
+ <button>Choose</button> |
|
| 57 |
+ </form> |
|
| 58 |
+ </div> |
|
| 59 |
+ </#if> |
|
| 60 |
+ <div> |
|
| 61 |
+ <form action = "/exchange/${(exchange.id)!}/canceled" method = "POST">
|
|
| 62 |
+ <button>Cancel</button> |
|
| 63 |
+ </form> |
|
| 64 |
+ </div> |
|
| 65 |
+ |
|
| 66 |
+ </div> |
|
| 67 |
+ </li> |
|
| 68 |
+ </#list> |
|
| 69 |
+</ul> |
|
| 70 |
+ |
|
| 71 |
+</body> |
|
| 72 |
+ |
|
| 73 |
+</html> |
| ... | ... |
@@ -0,0 +1,70 @@ |
| 1 |
+<#ftl encoding="utf-8"> |
|
| 2 |
+<!DOCTYPE html> |
|
| 3 |
+<html> |
|
| 4 |
+<head> |
|
| 5 |
+<link rel="stylesheet" type="text/css" href="/style.css" media="screen"> |
|
| 6 |
+ |
|
| 7 |
+<title></title> |
|
| 8 |
+</head> |
|
| 9 |
+<body xmlns="http://www.w3.org/1999/html"> |
|
| 10 |
+ |
|
| 11 |
+ |
|
| 12 |
+<div class = exchange> |
|
| 13 |
+ <div class = pokemon> |
|
| 14 |
+ <p>By ${(exchange.user1.pseudo)!} </p>
|
|
| 15 |
+ <img src = ${(exchange.pkm1.sprite)!} alt = ${(exchange.pkm1.name)!}</img>
|
|
| 16 |
+ <h3>${(exchange.pkm1.name)!}</h3>
|
|
| 17 |
+ <p>${(exchange.pkm1.lvl)!}</p>
|
|
| 18 |
+ </div> |
|
| 19 |
+ <div class = "pokemon"> |
|
| 20 |
+ <#if exchange.dataPkm2?has_content> |
|
| 21 |
+ <p>By ${(exchange.user2.pseudo)!} </p>
|
|
| 22 |
+ <img src = ${(exchange.dataPkm2.sprite)!} alt = ${(exchange.dataPkm2.name)!}</img>
|
|
| 23 |
+ <h3>${(exchange.dataPkm2.name)!}</h3>
|
|
| 24 |
+ <p>${(exchange.dataPkm2.lvl)!}</p>
|
|
| 25 |
+ </div> |
|
| 26 |
+ <form action = "/exchange/${(exchange.id)!}/accepted" method = "POST">
|
|
| 27 |
+ <button>Accept</button> |
|
| 28 |
+ </form> |
|
| 29 |
+ <#else> |
|
| 30 |
+ |
|
| 31 |
+ |
|
| 32 |
+ <#if exchange.idPkm2?? && exchange.idPkm2.id == 0> |
|
| 33 |
+ <input type="hidden" name="pkmId" value="0"> |
|
| 34 |
+ <img src = "/pokemonSprite/0.png" alt = "Any pokemon"</img> <br> |
|
| 35 |
+ <#else> |
|
| 36 |
+ <input type="hidden" name="pkmId" value="${exchange.idPkm2.id}">
|
|
| 37 |
+ <img src = "${(exchange.idPkm2.sprite)!}" alt = "${(exchange.idPkm2.name)!}"</img>
|
|
| 38 |
+ </#if> |
|
| 39 |
+ <input type="hidden" name="pkmShiny" value="${exchange.idPkm2.shiny?c}">
|
|
| 40 |
+ <#if exchange.idPkm2?? && exchange.idPkm2.name?has_content> |
|
| 41 |
+ |
|
| 42 |
+ <#if exchange.idPkm2.shiny> |
|
| 43 |
+ <h3>Shiny ${(exchange.idPkm2.name)!}</h3>
|
|
| 44 |
+ <#else> |
|
| 45 |
+ <h3>${(exchange.idPkm2.name)!}</h3>
|
|
| 46 |
+ </#if> |
|
| 47 |
+ <#else> |
|
| 48 |
+ <h3>Any pokemon</h3> |
|
| 49 |
+ </#if> |
|
| 50 |
+ <#if exchange.idPkm2?? && exchange.idPkm2.lvl == 0> |
|
| 51 |
+ <input type="hidden" name="pkmLvl" value="0"> |
|
| 52 |
+ <h3>Any level</h3> |
|
| 53 |
+ <#else> |
|
| 54 |
+ <input type="hidden" name="pkmLvl" value="${exchange.idPkm2.lvl}">
|
|
| 55 |
+ <h3>At least level ${(exchange.idPkm2.lvl)!}</h3>
|
|
| 56 |
+ </#if> |
|
| 57 |
+ <form action = "/exchange/${(exchange.id)!}/selectPokemon" method = "GET" >
|
|
| 58 |
+ <button name = "exchangeId" value = "${(exchange.id)!}">Choose</button>
|
|
| 59 |
+ </form> |
|
| 60 |
+ </div> |
|
| 61 |
+ <div></div> |
|
| 62 |
+ </#if> |
|
| 63 |
+ |
|
| 64 |
+ </div> |
|
| 65 |
+ |
|
| 66 |
+</div> |
|
| 67 |
+ |
|
| 68 |
+</body> |
|
| 69 |
+ |
|
| 70 |
+</html> |
| ... | ... |
@@ -0,0 +1,64 @@ |
| 1 |
+<#ftl encoding="utf-8"> |
|
| 2 |
+<!DOCTYPE html> |
|
| 3 |
+<html> |
|
| 4 |
+<head> |
|
| 5 |
+<link rel="stylesheet" type="text/css" href="/style.css" media="screen"> |
|
| 6 |
+ |
|
| 7 |
+<title></title> |
|
| 8 |
+</head> |
|
| 9 |
+<body xmlns="http://www.w3.org/1999/html"> |
|
| 10 |
+ |
|
| 11 |
+ |
|
| 12 |
+<div class = exchange> |
|
| 13 |
+ <div class = pokemon> |
|
| 14 |
+ <p>By ${(exchange.user1.pseudo)!} </p>
|
|
| 15 |
+ <img src = ${(exchange.pkm1.sprite)!} alt = ${(exchange.pkm1.name)!}</img>
|
|
| 16 |
+ <h3>${(exchange.pkm1.name)!}</h3>
|
|
| 17 |
+ <p>${(exchange.pkm1.lvl)!}</p>
|
|
| 18 |
+ </div> |
|
| 19 |
+ <div> |
|
| 20 |
+ <#if exchange.dataPkm2?has_content> |
|
| 21 |
+ <img src = ${(exchange.dataPkm2.sprite)!} alt = ${(exchange.dataPkm2.name)!}</img>
|
|
| 22 |
+ <h3>${(exchange.dataPkm2.name)!}</h3>
|
|
| 23 |
+ <p>${(exchange.dataPkm2.lvl)!}</p>
|
|
| 24 |
+ <#else> |
|
| 25 |
+ <form action = "/exchange/${(exchange.id)!}/selectPokemon" method = "GET" >
|
|
| 26 |
+ <#if exchange.idPkm2?? && exchange.idPkm2.id == 0> |
|
| 27 |
+ <input type="hidden" name="pkmId" value="0"> |
|
| 28 |
+ <img src = "/pokemonSprite/0.png" alt = "Any pokemon"</img> <br> |
|
| 29 |
+ <#else> |
|
| 30 |
+ <input type="hidden" name="pkmId" value="${exchange.idPkm2.id}">
|
|
| 31 |
+ <img src = "${(exchange.idPkm2.sprite)!}" alt = "${(exchange.idPkm2.name)!}"</img>
|
|
| 32 |
+ </#if> |
|
| 33 |
+ <input type="hidden" name="pkmShiny" value="${exchange.idPkm2.shiny?c}">
|
|
| 34 |
+ <#if exchange.idPkm2?? && exchange.idPkm2.name?has_content> |
|
| 35 |
+ |
|
| 36 |
+ <#if exchange.idPkm2.shiny> |
|
| 37 |
+ <h3>Shiny ${(exchange.idPkm2.name)!}</h3>
|
|
| 38 |
+ <#else> |
|
| 39 |
+ <h3>${(exchange.idPkm2.name)!}</h3>
|
|
| 40 |
+ </#if> |
|
| 41 |
+ <#else> |
|
| 42 |
+ <h3>Any pokemon</h3> |
|
| 43 |
+ </#if> |
|
| 44 |
+ <#if exchange.idPkm2?? && exchange.idPkm2.lvl == 0> |
|
| 45 |
+ <input type="hidden" name="pkmLvl" value="0"> |
|
| 46 |
+ <h3>Any level</h3> |
|
| 47 |
+ <#else> |
|
| 48 |
+ <input type="hidden" name="pkmLvl" value="${exchange.idPkm2.lvl}">
|
|
| 49 |
+ <h3>At least level ${(exchange.idPkm2.lvl)!}</h3>
|
|
| 50 |
+ </#if> |
|
| 51 |
+ <button name = "exchangeId" value = "${(exchange.id)!}">Choose</button>
|
|
| 52 |
+ </form> |
|
| 53 |
+ </#if> |
|
| 54 |
+ |
|
| 55 |
+ </div> |
|
| 56 |
+ <form action = "/exchange/${(exchange.id)!}/accepted" method = "POST">
|
|
| 57 |
+ <input type="hidden" name="dataId" value="${exchange.dataPkm2.dataId}">
|
|
| 58 |
+ <button>Accept</button> |
|
| 59 |
+ </form> |
|
| 60 |
+</div> |
|
| 61 |
+ |
|
| 62 |
+</body> |
|
| 63 |
+ |
|
| 64 |
+</html> |
| ... | ... |
@@ -0,0 +1,51 @@ |
| 1 |
+<#ftl encoding="utf-8"> |
|
| 2 |
+<!DOCTYPE html> |
|
| 3 |
+<html> |
|
| 4 |
+<head> |
|
| 5 |
+<link rel="stylesheet" type="text/css" href="/style.css" media="screen"> |
|
| 6 |
+ |
|
| 7 |
+<title></title> |
|
| 8 |
+</head> |
|
| 9 |
+<body xmlns="http://www.w3.org/1999/html"> |
|
| 10 |
+ |
|
| 11 |
+ |
|
| 12 |
+<div class = exchange> |
|
| 13 |
+ <div class = pokemon> |
|
| 14 |
+ <p>From you </p> |
|
| 15 |
+ <img src = ${(pokemon.sprite)!} alt = ${(pokemon.name)!}</img>
|
|
| 16 |
+ <h3>${(pokemon.name)!}</h3>
|
|
| 17 |
+ <p>${(pokemon.lvl)!}</p>
|
|
| 18 |
+ </div> |
|
| 19 |
+ <div> |
|
| 20 |
+ <form action = "/user/${user.login}/exchangeOut/new" method = "POST" >
|
|
| 21 |
+ <p>Pokemon</p> |
|
| 22 |
+ <div class = exchangeForm> |
|
| 23 |
+ <input type="text" name="pkmName" placeholder = "Enter the name of the pokemon you want"> |
|
| 24 |
+ <input type="checkbox" name="anyPkm" value = "true"> |
|
| 25 |
+ <p>Any</p> |
|
| 26 |
+ </div> |
|
| 27 |
+ |
|
| 28 |
+ <p>Pokemon level</p> |
|
| 29 |
+ <div class = exchangeForm> |
|
| 30 |
+ <input type="text" name="pkmLvl" placeholder = "Enter the minimum level of the pokemon you want"> |
|
| 31 |
+ |
|
| 32 |
+ <input type="checkbox" name="anyLvl" value = "true"> |
|
| 33 |
+ <p>Any</p> |
|
| 34 |
+ </div> |
|
| 35 |
+ |
|
| 36 |
+ |
|
| 37 |
+ <p>Shiny</p> |
|
| 38 |
+ <input type="checkbox" name="pkmShiny" value = "true"> |
|
| 39 |
+ |
|
| 40 |
+ </div> |
|
| 41 |
+ <div> |
|
| 42 |
+ <input type="hidden" name="dataId" value = "${(pokemon.dataId)!}">
|
|
| 43 |
+ <input type="hidden" name="userId" value = "${(user.login)!}">
|
|
| 44 |
+ <button>Post</button> |
|
| 45 |
+ </div> |
|
| 46 |
+ </form> |
|
| 47 |
+</div> |
|
| 48 |
+ |
|
| 49 |
+</body> |
|
| 50 |
+ |
|
| 51 |
+</html> |
| ... | ... |
@@ -0,0 +1,44 @@ |
| 1 |
+<#ftl encoding="utf-8"> |
|
| 2 |
+<!DOCTYPE html> |
|
| 3 |
+<html> |
|
| 4 |
+<head> |
|
| 5 |
+<link rel="stylesheet" type="text/css" href="/style.css" media="screen"> |
|
| 6 |
+ |
|
| 7 |
+<title></title> |
|
| 8 |
+</head> |
|
| 9 |
+<body xmlns="http://www.w3.org/1999/html"> |
|
| 10 |
+ |
|
| 11 |
+ |
|
| 12 |
+<div class = exchange> |
|
| 13 |
+ <div class = pokemon> |
|
| 14 |
+ <p>From ${(exchange.user1.pseudo)!} </p>
|
|
| 15 |
+ <img src = ${(exchange.pkm1.sprite)!} alt = ${(pokemon.name)!}</img>
|
|
| 16 |
+ <h3>${(exchange.pkm1.name)!}</h3>
|
|
| 17 |
+ <p>${(exchange.pkm1.lvl)!}</p>
|
|
| 18 |
+ </div> |
|
| 19 |
+ <div> |
|
| 20 |
+ <#if exchange.dataPkm2?has_content> |
|
| 21 |
+ <img src = ${(exchange.dataPkm2.sprite)!} alt = ${(exchange.dataPkm2.name)!}</img>
|
|
| 22 |
+ <h3>${(exchange.dataPkm2.name)!}</h3>
|
|
| 23 |
+ <p>${(exchange.dataPkm2.lvl)!}</p>
|
|
| 24 |
+ <#else> |
|
| 25 |
+ <form action = "/user/${exchange.user1.login}/pokemon/${exchange.pkm1.dataId}/exchange/choosePkm" method = "GET" >
|
|
| 26 |
+ <img src = "/pokemonSprite/0.png" alt = "Any pokemon"</img> <br> |
|
| 27 |
+ <h3>Any pokemon</h3> |
|
| 28 |
+ <h3>Any level</h3> |
|
| 29 |
+ |
|
| 30 |
+ <button>Choose</button> |
|
| 31 |
+ </form> |
|
| 32 |
+ </#if> |
|
| 33 |
+ </div> |
|
| 34 |
+ <div> |
|
| 35 |
+ <form action = "/user/${exchange.user1.login}/pokemon/${exchange.pkm1.dataId}/exchange/valided/${(exchange.dataPkm2.dataId)!}" method = "POST">
|
|
| 36 |
+ |
|
| 37 |
+ <button>Post</button> |
|
| 38 |
+ </form> |
|
| 39 |
+ </div> |
|
| 40 |
+</div> |
|
| 41 |
+ |
|
| 42 |
+</body> |
|
| 43 |
+ |
|
| 44 |
+</html> |
| ... | ... |
@@ -0,0 +1,78 @@ |
| 1 |
+<!DOCTYPE html> |
|
| 2 |
+<html lang = "fr"> |
|
| 3 |
+<head> |
|
| 4 |
+ <meta charset="utf-8"> |
|
| 5 |
+ <meta name="viewport" content="width=device-width, initial-scale=1"> |
|
| 6 |
+ <link rel="stylesheet" type="text/css" href="style.css" media="screen"> |
|
| 7 |
+ |
|
| 8 |
+ |
|
| 9 |
+ <title></title> |
|
| 10 |
+ |
|
| 11 |
+ |
|
| 12 |
+ |
|
| 13 |
+</head> |
|
| 14 |
+ |
|
| 15 |
+<body> |
|
| 16 |
+ |
|
| 17 |
+ <div class="container"> |
|
| 18 |
+ <div class = logsign> |
|
| 19 |
+ <form action="/signup" method="post" id="signup" class = form> |
|
| 20 |
+ <h1>Signup</h1> |
|
| 21 |
+ <div class="field"> |
|
| 22 |
+ <label for="lastname">Pseudo :</label> |
|
| 23 |
+ <input type="text" id="pseudo" name="pseudo" placeholder="Enter you pseudo" > |
|
| 24 |
+ <small></small> |
|
| 25 |
+ </div> |
|
| 26 |
+ |
|
| 27 |
+ <div class="field"> |
|
| 28 |
+ <label for="userpwd">Password :</label> |
|
| 29 |
+ <input type="password" id="userpwd" name="userpwd" placeholder="Entrez votre mot de passe ici" > |
|
| 30 |
+ <small></small> |
|
| 31 |
+ </div> |
|
| 32 |
+ |
|
| 33 |
+ <div class="field"> |
|
| 34 |
+ <label for="usermail">Email:</label> |
|
| 35 |
+ <input type="text" id="usermail" name="usermail" placeholder="Enter your email address" > |
|
| 36 |
+ <small></small> |
|
| 37 |
+ </div> |
|
| 38 |
+ <div class="field"> |
|
| 39 |
+ <button type="submit" class="full">Signin</button> |
|
| 40 |
+ </div> |
|
| 41 |
+ <div id="zoneSignup"> |
|
| 42 |
+ <span class="Style1"></span> |
|
| 43 |
+ </div> |
|
| 44 |
+ </form> |
|
| 45 |
+ |
|
| 46 |
+ |
|
| 47 |
+ <form action="/login" method="post" id="login" class = form> |
|
| 48 |
+ <h1>Login</h1> |
|
| 49 |
+ |
|
| 50 |
+ <div class="field"> |
|
| 51 |
+ <label for="usermail">Email:</label> |
|
| 52 |
+ <input type="text" id="usermail" name="usermail" placeholder="Enter your email address" > |
|
| 53 |
+ <small></small> |
|
| 54 |
+ </div> |
|
| 55 |
+ |
|
| 56 |
+ <div class="field"> |
|
| 57 |
+ <label for="userpwd">Password :</label> |
|
| 58 |
+ <input type="password" id="userpwd" name="userpwd" placeholder="Entrez votre mot de passe ici" > |
|
| 59 |
+ <small></small> |
|
| 60 |
+ </div> |
|
| 61 |
+ |
|
| 62 |
+ |
|
| 63 |
+ <div class="field"> |
|
| 64 |
+ <button type="submit" class="full">Login</button> |
|
| 65 |
+ </div> |
|
| 66 |
+ <div id="zone"> |
|
| 67 |
+ <span class="Style1"></span> |
|
| 68 |
+ </div> |
|
| 69 |
+ </form> |
|
| 70 |
+ </div> |
|
| 71 |
+ |
|
| 72 |
+ |
|
| 73 |
+ </div> |
|
| 74 |
+ |
|
| 75 |
+ |
|
| 76 |
+ |
|
| 77 |
+</body> |
|
| 78 |
+</html> |
|
| 0 | 79 |
\ No newline at end of file |
| ... | ... |
@@ -0,0 +1,26 @@ |
| 1 |
+<#ftl encoding="utf-8"> |
|
| 2 |
+<!DOCTYPE html> |
|
| 3 |
+<html> |
|
| 4 |
+<head> |
|
| 5 |
+<link rel="stylesheet" type="text/css" href="/style.css" media="screen"> |
|
| 6 |
+ |
|
| 7 |
+<title>New pokemon</title> |
|
| 8 |
+</head> |
|
| 9 |
+ |
|
| 10 |
+<body xmlns="http://www.w3.org/1999/html"> |
|
| 11 |
+ |
|
| 12 |
+ |
|
| 13 |
+ |
|
| 14 |
+ |
|
| 15 |
+<div class = pkListItem> |
|
| 16 |
+ <img src = ${(pokemon.sprite)!} alt = ${(pokemon.name)!}</img> <br>
|
|
| 17 |
+ <h3>${(pokemon.name)!}</h3>
|
|
| 18 |
+ <form action = "/userRedirect" method = "GET"> |
|
| 19 |
+ <button>Ok</button> |
|
| 20 |
+ </form> |
|
| 21 |
+ |
|
| 22 |
+</div> |
|
| 23 |
+ |
|
| 24 |
+ |
|
| 25 |
+</body> |
|
| 26 |
+</html> |
| ... | ... |
@@ -0,0 +1,27 @@ |
| 1 |
+<#ftl encoding="utf-8"> |
|
| 2 |
+<!DOCTYPE html> |
|
| 3 |
+<html> |
|
| 4 |
+<head> |
|
| 5 |
+<link rel="stylesheet" type="text/css" href="/style.css" media="screen"> |
|
| 6 |
+ |
|
| 7 |
+<title></title> |
|
| 8 |
+</head> |
|
| 9 |
+<body xmlns="http://www.w3.org/1999/html"> |
|
| 10 |
+ |
|
| 11 |
+<ul class = pkList> |
|
| 12 |
+ <#list pokemons as pokemon> |
|
| 13 |
+ <li class = pkListItem> |
|
| 14 |
+ <img src = ${(pokemon.sprite)!} alt = ${(pokemon.name)!}</img> <br>
|
|
| 15 |
+ <h3>${(pokemon.name)!}</h3>
|
|
| 16 |
+ <p>${(pokemon.lvl)!}</p>
|
|
| 17 |
+ <form action = "/exchange/${(exchange)!}/offer" method = "POST">
|
|
| 18 |
+ <input type="hidden" name="exchangeId" value="${(exchange)!}">
|
|
| 19 |
+ <button name = "dataId" value = "${(pokemon.dataId)!}">Select</button>
|
|
| 20 |
+ </form> |
|
| 21 |
+ </li> |
|
| 22 |
+ </#list> |
|
| 23 |
+</ul> |
|
| 24 |
+ |
|
| 25 |
+</body> |
|
| 26 |
+ |
|
| 27 |
+</html> |
| ... | ... |
@@ -0,0 +1,26 @@ |
| 1 |
+<#ftl encoding="utf-8"> |
|
| 2 |
+<!DOCTYPE html> |
|
| 3 |
+<html> |
|
| 4 |
+<head> |
|
| 5 |
+<link rel="stylesheet" type="text/css" href="/style.css" media="screen"> |
|
| 6 |
+ |
|
| 7 |
+<title></title> |
|
| 8 |
+</head> |
|
| 9 |
+<body xmlns="http://www.w3.org/1999/html"> |
|
| 10 |
+ |
|
| 11 |
+<ul class = pkList> |
|
| 12 |
+ <#list pokemons as pokemon> |
|
| 13 |
+ <li class = pkListItem> |
|
| 14 |
+ <img src = ${(pokemon.sprite)!} alt = ${(pokemon.name)!}</img> <br>
|
|
| 15 |
+ <h3>${(pokemon.name)!}</h3>
|
|
| 16 |
+ <p>${(pokemon.lvl)!}</p>
|
|
| 17 |
+ <form action = "/user/${(user1)!}/pokemon/${(pkm1)!}/exchange/selected/${(pokemon.dataId)!}" method = "POST">
|
|
| 18 |
+ <button>Select</button> |
|
| 19 |
+ </form> |
|
| 20 |
+ </li> |
|
| 21 |
+ </#list> |
|
| 22 |
+</ul> |
|
| 23 |
+ |
|
| 24 |
+</body> |
|
| 25 |
+ |
|
| 26 |
+</html> |
| ... | ... |
@@ -0,0 +1,65 @@ |
| 1 |
+<#ftl encoding="utf-8"> |
|
| 2 |
+<!DOCTYPE html> |
|
| 3 |
+<html> |
|
| 4 |
+<head> |
|
| 5 |
+<link rel="stylesheet" type="text/css" href="/style.css" media="screen"> |
|
| 6 |
+ |
|
| 7 |
+<title>${user.pseudo}</title>
|
|
| 8 |
+</head> |
|
| 9 |
+ |
|
| 10 |
+<body xmlns="http://www.w3.org/1999/html"> |
|
| 11 |
+ |
|
| 12 |
+<ul class = pkList> |
|
| 13 |
+ <#list pokemons as pokemon> |
|
| 14 |
+ <li class = pkListItem> |
|
| 15 |
+ <img src = ${(pokemon.sprite)!} alt = ${(pokemon.name)!}</img> <br>
|
|
| 16 |
+ <h3>${(pokemon.name)!}</h3>
|
|
| 17 |
+ <p>${(pokemon.lvl)!}</p>
|
|
| 18 |
+ <form action = "/lvlup" method = "POST"> |
|
| 19 |
+ <input type="hidden" name="userid" value="${(user.login)!}">
|
|
| 20 |
+ <button class="btn-own" name = "dataid" value = "${(pokemon.dataId)!}">Lvl up</button>
|
|
| 21 |
+ </form> |
|
| 22 |
+ <form action = "/user/${(user.login)}/pokemon/${(pokemon.dataId)!}/exchange" method = "GET">
|
|
| 23 |
+ <button>Exchange</button> |
|
| 24 |
+ </form> |
|
| 25 |
+ </li> |
|
| 26 |
+ </#list> |
|
| 27 |
+</ul> |
|
| 28 |
+ |
|
| 29 |
+<div class = profil> |
|
| 30 |
+ <div class = left> |
|
| 31 |
+ <h2>My profile</h2> |
|
| 32 |
+ <p> |
|
| 33 |
+ ${(user.login)!} - ${(user.pseudo)!}<br>
|
|
| 34 |
+ </p> |
|
| 35 |
+ |
|
| 36 |
+ <h3>Number of pokemon : ${(userinfo.pkm)!}</h3>
|
|
| 37 |
+ |
|
| 38 |
+ <h3>Number of distinct pokemon : ${(userinfo.distinctPkm)!}</h3>
|
|
| 39 |
+ |
|
| 40 |
+ <h3>Number of shiny pokemon : ${(userinfo.shiny)!}</h3>
|
|
| 41 |
+ </div> |
|
| 42 |
+ |
|
| 43 |
+ <nav> |
|
| 44 |
+ <ul> |
|
| 45 |
+ <li> |
|
| 46 |
+ <a href = "/user/${(user.login)!}/exchangeIn">My incoming exchanges</a>
|
|
| 47 |
+ </li> |
|
| 48 |
+ <li> |
|
| 49 |
+ <a href = "/user/${(user.login)!}/exchangeOut">My outcoming exchanges</a>
|
|
| 50 |
+ </li> |
|
| 51 |
+ <li> |
|
| 52 |
+ <h4>User search</h4> |
|
| 53 |
+ <form id="searchForm" action = "/userSearch" method = "GET"> |
|
| 54 |
+ <input type="text" name="search" placeholder="Enter the id or pseudo"> |
|
| 55 |
+ <button type="submit" form="searchForm">Search</button> |
|
| 56 |
+ </form> |
|
| 57 |
+ </li> |
|
| 58 |
+ </ul> |
|
| 59 |
+ </nav> |
|
| 60 |
+</div> |
|
| 61 |
+ |
|
| 62 |
+</body> |
|
| 63 |
+</html> |
|
| 64 |
+ |
|
| 65 |
+ |
| ... | ... |
@@ -0,0 +1,51 @@ |
| 1 |
+<#ftl encoding="utf-8"> |
|
| 2 |
+<!DOCTYPE html> |
|
| 3 |
+<html> |
|
| 4 |
+<head> |
|
| 5 |
+<link rel="stylesheet" type="text/css" href="/style.css" media="screen"> |
|
| 6 |
+ |
|
| 7 |
+<title>${user.pseudo}</title>
|
|
| 8 |
+</head> |
|
| 9 |
+ |
|
| 10 |
+<body xmlns="http://www.w3.org/1999/html"> |
|
| 11 |
+ |
|
| 12 |
+<ul class = pkList> |
|
| 13 |
+ <#list pokemons as pokemon> |
|
| 14 |
+ <li class = pkListItem> |
|
| 15 |
+ <img src = ${(pokemon.sprite)!} alt = ${(pokemon.name)!}</img> <br>
|
|
| 16 |
+ <h3>${(pokemon.name)!}</h3>
|
|
| 17 |
+ <p>${(pokemon.lvl)!}</p>
|
|
| 18 |
+ <form action = "/lvlup" method = "POST"> |
|
| 19 |
+ <input type="hidden" name="userid" value="${(user.login)!}">
|
|
| 20 |
+ <button class="btn-own" name = "dataid" value = "${(pokemon.dataId)!}">Lvl up</button>
|
|
| 21 |
+ </form> |
|
| 22 |
+ <form action = "/user/${(user.login)!}/pokemon/${(pokemon.dataId)!}/exchange" method = "GET">
|
|
| 23 |
+ <button>Exchange</button> |
|
| 24 |
+ </form> |
|
| 25 |
+ </li> |
|
| 26 |
+ </#list> |
|
| 27 |
+</ul> |
|
| 28 |
+ |
|
| 29 |
+<div class = profil> |
|
| 30 |
+ <div class = left> |
|
| 31 |
+ <h2>${(user.pseudo)!}'s profile</h2>
|
|
| 32 |
+ <p> |
|
| 33 |
+ ${(user.login)!} - ${(user.pseudo)!}
|
|
| 34 |
+ </p> |
|
| 35 |
+ |
|
| 36 |
+ <h3>Number of pokemon : ${(userinfo.pkm)!}</h3>
|
|
| 37 |
+ |
|
| 38 |
+ <h3>Number of distinct pokemon : ${(userinfo.distinctPkm)!}</h3>
|
|
| 39 |
+ |
|
| 40 |
+ <h3>Number of shiny pokemon : ${(userinfo.shiny)!}</h3>
|
|
| 41 |
+ </div> |
|
| 42 |
+ |
|
| 43 |
+ <nav> |
|
| 44 |
+ <a href = "/user/${(user.login)!}/exchangeOut">Available exchange</a>
|
|
| 45 |
+ </nav> |
|
| 46 |
+</div> |
|
| 47 |
+ |
|
| 48 |
+</body> |
|
| 49 |
+</html> |
|
| 50 |
+ |
|
| 51 |
+ |
| ... | ... |
@@ -0,0 +1,18 @@ |
| 1 |
+<#ftl encoding="utf-8"> |
|
| 2 |
+ |
|
| 3 |
+<body xmlns="http://www.w3.org/1999/html"> |
|
| 4 |
+ |
|
| 5 |
+<ul> |
|
| 6 |
+ <#list users as user> |
|
| 7 |
+ <li> |
|
| 8 |
+ <h3>${(user.login)!} - ${(user.pseudo)!} </h3>
|
|
| 9 |
+ <form action = "/user/${user.login}" method = "GET">
|
|
| 10 |
+ <button>Go</button> |
|
| 11 |
+ </form> |
|
| 12 |
+ </li> |
|
| 13 |
+ </#list> |
|
| 14 |
+</ul> |
|
| 15 |
+ |
|
| 16 |
+</body> |
|
| 17 |
+ |
|
| 18 |
+</html> |
| ... | ... |
@@ -0,0 +1,13 @@ |
| 1 |
+<#ftl encoding="utf-8"> |
|
| 2 |
+ |
|
| 3 |
+<body xmlns="http://www.w3.org/1999/html"> |
|
| 4 |
+ |
|
| 5 |
+<ul> |
|
| 6 |
+ <#list users as user> |
|
| 7 |
+ <li>${(user.login)!} - ${(user.pseudo)!} ${(user.email)!} ${(user.hashpswd)!} ${(user.lastCoDate?string("dd/MM/yyyy"))!}</li>
|
|
| 8 |
+ </#list> |
|
| 9 |
+</ul> |
|
| 10 |
+ |
|
| 11 |
+</body> |
|
| 12 |
+ |
|
| 13 |
+</html> |
| ... | ... |
@@ -0,0 +1,172 @@ |
| 1 |
+#!/usr/bin/env sh |
|
| 2 |
+ |
|
| 3 |
+############################################################################## |
|
| 4 |
+## |
|
| 5 |
+## Gradle start up script for UN*X |
|
| 6 |
+## |
|
| 7 |
+############################################################################## |
|
| 8 |
+ |
|
| 9 |
+# Attempt to set APP_HOME |
|
| 10 |
+# Resolve links: $0 may be a link |
|
| 11 |
+PRG="$0" |
|
| 12 |
+# Need this for relative symlinks. |
|
| 13 |
+while [ -h "$PRG" ] ; do |
|
| 14 |
+ ls=`ls -ld "$PRG"` |
|
| 15 |
+ link=`expr "$ls" : '.*-> \(.*\)$'` |
|
| 16 |
+ if expr "$link" : '/.*' > /dev/null; then |
|
| 17 |
+ PRG="$link" |
|
| 18 |
+ else |
|
| 19 |
+ PRG=`dirname "$PRG"`"/$link" |
|
| 20 |
+ fi |
|
| 21 |
+done |
|
| 22 |
+SAVED="`pwd`" |
|
| 23 |
+cd "`dirname \"$PRG\"`/" >/dev/null |
|
| 24 |
+APP_HOME="`pwd -P`" |
|
| 25 |
+cd "$SAVED" >/dev/null |
|
| 26 |
+ |
|
| 27 |
+APP_NAME="Gradle" |
|
| 28 |
+APP_BASE_NAME=`basename "$0"` |
|
| 29 |
+ |
|
| 30 |
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. |
|
| 31 |
+DEFAULT_JVM_OPTS="" |
|
| 32 |
+ |
|
| 33 |
+# Use the maximum available, or set MAX_FD != -1 to use that value. |
|
| 34 |
+MAX_FD="maximum" |
|
| 35 |
+ |
|
| 36 |
+warn () {
|
|
| 37 |
+ echo "$*" |
|
| 38 |
+} |
|
| 39 |
+ |
|
| 40 |
+die () {
|
|
| 41 |
+ echo |
|
| 42 |
+ echo "$*" |
|
| 43 |
+ echo |
|
| 44 |
+ exit 1 |
|
| 45 |
+} |
|
| 46 |
+ |
|
| 47 |
+# OS specific support (must be 'true' or 'false'). |
|
| 48 |
+cygwin=false |
|
| 49 |
+msys=false |
|
| 50 |
+darwin=false |
|
| 51 |
+nonstop=false |
|
| 52 |
+case "`uname`" in |
|
| 53 |
+ CYGWIN* ) |
|
| 54 |
+ cygwin=true |
|
| 55 |
+ ;; |
|
| 56 |
+ Darwin* ) |
|
| 57 |
+ darwin=true |
|
| 58 |
+ ;; |
|
| 59 |
+ MINGW* ) |
|
| 60 |
+ msys=true |
|
| 61 |
+ ;; |
|
| 62 |
+ NONSTOP* ) |
|
| 63 |
+ nonstop=true |
|
| 64 |
+ ;; |
|
| 65 |
+esac |
|
| 66 |
+ |
|
| 67 |
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar |
|
| 68 |
+ |
|
| 69 |
+# Determine the Java command to use to start the JVM. |
|
| 70 |
+if [ -n "$JAVA_HOME" ] ; then |
|
| 71 |
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then |
|
| 72 |
+ # IBM's JDK on AIX uses strange locations for the executables |
|
| 73 |
+ JAVACMD="$JAVA_HOME/jre/sh/java" |
|
| 74 |
+ else |
|
| 75 |
+ JAVACMD="$JAVA_HOME/bin/java" |
|
| 76 |
+ fi |
|
| 77 |
+ if [ ! -x "$JAVACMD" ] ; then |
|
| 78 |
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME |
|
| 79 |
+ |
|
| 80 |
+Please set the JAVA_HOME variable in your environment to match the |
|
| 81 |
+location of your Java installation." |
|
| 82 |
+ fi |
|
| 83 |
+else |
|
| 84 |
+ JAVACMD="java" |
|
| 85 |
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. |
|
| 86 |
+ |
|
| 87 |
+Please set the JAVA_HOME variable in your environment to match the |
|
| 88 |
+location of your Java installation." |
|
| 89 |
+fi |
|
| 90 |
+ |
|
| 91 |
+# Increase the maximum file descriptors if we can. |
|
| 92 |
+if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then |
|
| 93 |
+ MAX_FD_LIMIT=`ulimit -H -n` |
|
| 94 |
+ if [ $? -eq 0 ] ; then |
|
| 95 |
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then |
|
| 96 |
+ MAX_FD="$MAX_FD_LIMIT" |
|
| 97 |
+ fi |
|
| 98 |
+ ulimit -n $MAX_FD |
|
| 99 |
+ if [ $? -ne 0 ] ; then |
|
| 100 |
+ warn "Could not set maximum file descriptor limit: $MAX_FD" |
|
| 101 |
+ fi |
|
| 102 |
+ else |
|
| 103 |
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" |
|
| 104 |
+ fi |
|
| 105 |
+fi |
|
| 106 |
+ |
|
| 107 |
+# For Darwin, add options to specify how the application appears in the dock |
|
| 108 |
+if $darwin; then |
|
| 109 |
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" |
|
| 110 |
+fi |
|
| 111 |
+ |
|
| 112 |
+# For Cygwin, switch paths to Windows format before running java |
|
| 113 |
+if $cygwin ; then |
|
| 114 |
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"` |
|
| 115 |
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` |
|
| 116 |
+ JAVACMD=`cygpath --unix "$JAVACMD"` |
|
| 117 |
+ |
|
| 118 |
+ # We build the pattern for arguments to be converted via cygpath |
|
| 119 |
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` |
|
| 120 |
+ SEP="" |
|
| 121 |
+ for dir in $ROOTDIRSRAW ; do |
|
| 122 |
+ ROOTDIRS="$ROOTDIRS$SEP$dir" |
|
| 123 |
+ SEP="|" |
|
| 124 |
+ done |
|
| 125 |
+ OURCYGPATTERN="(^($ROOTDIRS))" |
|
| 126 |
+ # Add a user-defined pattern to the cygpath arguments |
|
| 127 |
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then |
|
| 128 |
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" |
|
| 129 |
+ fi |
|
| 130 |
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh |
|
| 131 |
+ i=0 |
|
| 132 |
+ for arg in "$@" ; do |
|
| 133 |
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` |
|
| 134 |
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option |
|
| 135 |
+ |
|
| 136 |
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition |
|
| 137 |
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` |
|
| 138 |
+ else |
|
| 139 |
+ eval `echo args$i`="\"$arg\"" |
|
| 140 |
+ fi |
|
| 141 |
+ i=$((i+1)) |
|
| 142 |
+ done |
|
| 143 |
+ case $i in |
|
| 144 |
+ (0) set -- ;; |
|
| 145 |
+ (1) set -- "$args0" ;; |
|
| 146 |
+ (2) set -- "$args0" "$args1" ;; |
|
| 147 |
+ (3) set -- "$args0" "$args1" "$args2" ;; |
|
| 148 |
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;; |
|
| 149 |
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; |
|
| 150 |
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; |
|
| 151 |
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; |
|
| 152 |
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; |
|
| 153 |
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; |
|
| 154 |
+ esac |
|
| 155 |
+fi |
|
| 156 |
+ |
|
| 157 |
+# Escape application args |
|
| 158 |
+save () {
|
|
| 159 |
+ for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done |
|
| 160 |
+ echo " " |
|
| 161 |
+} |
|
| 162 |
+APP_ARGS=$(save "$@") |
|
| 163 |
+ |
|
| 164 |
+# Collect all arguments for the java command, following the shell quoting and substitution rules |
|
| 165 |
+eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" |
|
| 166 |
+ |
|
| 167 |
+# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong |
|
| 168 |
+if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then |
|
| 169 |
+ cd "$(dirname "$0")" |
|
| 170 |
+fi |
|
| 171 |
+ |
|
| 172 |
+exec "$JAVACMD" "$@" |
| ... | ... |
@@ -0,0 +1,84 @@ |
| 1 |
+@if "%DEBUG%" == "" @echo off |
|
| 2 |
+@rem ########################################################################## |
|
| 3 |
+@rem |
|
| 4 |
+@rem Gradle startup script for Windows |
|
| 5 |
+@rem |
|
| 6 |
+@rem ########################################################################## |
|
| 7 |
+ |
|
| 8 |
+@rem Set local scope for the variables with windows NT shell |
|
| 9 |
+if "%OS%"=="Windows_NT" setlocal |
|
| 10 |
+ |
|
| 11 |
+set DIRNAME=%~dp0 |
|
| 12 |
+if "%DIRNAME%" == "" set DIRNAME=. |
|
| 13 |
+set APP_BASE_NAME=%~n0 |
|
| 14 |
+set APP_HOME=%DIRNAME% |
|
| 15 |
+ |
|
| 16 |
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. |
|
| 17 |
+set DEFAULT_JVM_OPTS= |
|
| 18 |
+ |
|
| 19 |
+@rem Find java.exe |
|
| 20 |
+if defined JAVA_HOME goto findJavaFromJavaHome |
|
| 21 |
+ |
|
| 22 |
+set JAVA_EXE=java.exe |
|
| 23 |
+%JAVA_EXE% -version >NUL 2>&1 |
|
| 24 |
+if "%ERRORLEVEL%" == "0" goto init |
|
| 25 |
+ |
|
| 26 |
+echo. |
|
| 27 |
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. |
|
| 28 |
+echo. |
|
| 29 |
+echo Please set the JAVA_HOME variable in your environment to match the |
|
| 30 |
+echo location of your Java installation. |
|
| 31 |
+ |
|
| 32 |
+goto fail |
|
| 33 |
+ |
|
| 34 |
+:findJavaFromJavaHome |
|
| 35 |
+set JAVA_HOME=%JAVA_HOME:"=% |
|
| 36 |
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe |
|
| 37 |
+ |
|
| 38 |
+if exist "%JAVA_EXE%" goto init |
|
| 39 |
+ |
|
| 40 |
+echo. |
|
| 41 |
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% |
|
| 42 |
+echo. |
|
| 43 |
+echo Please set the JAVA_HOME variable in your environment to match the |
|
| 44 |
+echo location of your Java installation. |
|
| 45 |
+ |
|
| 46 |
+goto fail |
|
| 47 |
+ |
|
| 48 |
+:init |
|
| 49 |
+@rem Get command-line arguments, handling Windows variants |
|
| 50 |
+ |
|
| 51 |
+if not "%OS%" == "Windows_NT" goto win9xME_args |
|
| 52 |
+ |
|
| 53 |
+:win9xME_args |
|
| 54 |
+@rem Slurp the command line arguments. |
|
| 55 |
+set CMD_LINE_ARGS= |
|
| 56 |
+set _SKIP=2 |
|
| 57 |
+ |
|
| 58 |
+:win9xME_args_slurp |
|
| 59 |
+if "x%~1" == "x" goto execute |
|
| 60 |
+ |
|
| 61 |
+set CMD_LINE_ARGS=%* |
|
| 62 |
+ |
|
| 63 |
+:execute |
|
| 64 |
+@rem Setup the command line |
|
| 65 |
+ |
|
| 66 |
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar |
|
| 67 |
+ |
|
| 68 |
+@rem Execute Gradle |
|
| 69 |
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% |
|
| 70 |
+ |
|
| 71 |
+:end |
|
| 72 |
+@rem End local scope for the variables with windows NT shell |
|
| 73 |
+if "%ERRORLEVEL%"=="0" goto mainEnd |
|
| 74 |
+ |
|
| 75 |
+:fail |
|
| 76 |
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of |
|
| 77 |
+rem the _cmd.exe /c_ return code! |
|
| 78 |
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 |
|
| 79 |
+exit /b 1 |
|
| 80 |
+ |
|
| 81 |
+:mainEnd |
|
| 82 |
+if "%OS%"=="Windows_NT" endlocal |
|
| 83 |
+ |
|
| 84 |
+:omega |
| ... | ... |
@@ -0,0 +1,544 @@ |
| 1 |
+package com.uca; |
|
| 2 |
+ |
|
| 3 |
+import com.uca.dao._Initializer; |
|
| 4 |
+import com.uca.core.UserCore; |
|
| 5 |
+import com.uca.core.PokemonCore; |
|
| 6 |
+import com.uca.core.ExchangeCore; |
|
| 7 |
+import com.uca.gui.*; |
|
| 8 |
+ |
|
| 9 |
+ |
|
| 10 |
+ |
|
| 11 |
+import static spark.Spark.*; |
|
| 12 |
+import spark.Request; |
|
| 13 |
+import spark.Response; |
|
| 14 |
+import spark.Session; |
|
| 15 |
+ |
|
| 16 |
+public class StartServer {
|
|
| 17 |
+ |
|
| 18 |
+ private enum Login{
|
|
| 19 |
+ ERROR(0), |
|
| 20 |
+ SUCCESS(1), |
|
| 21 |
+ FIRSTCO(2), |
|
| 22 |
+ INCORRECT(3); |
|
| 23 |
+ |
|
| 24 |
+ private int value; |
|
| 25 |
+ |
|
| 26 |
+ Login(int value) |
|
| 27 |
+ {
|
|
| 28 |
+ this.value = value; |
|
| 29 |
+ } |
|
| 30 |
+ |
|
| 31 |
+ public int getValue() |
|
| 32 |
+ {
|
|
| 33 |
+ return value; |
|
| 34 |
+ } |
|
| 35 |
+ } |
|
| 36 |
+ |
|
| 37 |
+ private enum InitiateExchange{
|
|
| 38 |
+ ERROR(0), |
|
| 39 |
+ SUCCESS(1), |
|
| 40 |
+ INCORRECTPKM(2), |
|
| 41 |
+ INCORRECTLVL(3); |
|
| 42 |
+ |
|
| 43 |
+ private int value; |
|
| 44 |
+ |
|
| 45 |
+ InitiateExchange(int value) |
|
| 46 |
+ {
|
|
| 47 |
+ this.value = value; |
|
| 48 |
+ } |
|
| 49 |
+ |
|
| 50 |
+ public int getValue() |
|
| 51 |
+ {
|
|
| 52 |
+ return value; |
|
| 53 |
+ } |
|
| 54 |
+ } |
|
| 55 |
+ |
|
| 56 |
+ private enum Base{
|
|
| 57 |
+ ERROR(0), |
|
| 58 |
+ SUCCESS(1), |
|
| 59 |
+ FAILURE(2); |
|
| 60 |
+ |
|
| 61 |
+ private int value; |
|
| 62 |
+ |
|
| 63 |
+ Base(int value) |
|
| 64 |
+ {
|
|
| 65 |
+ this.value = value; |
|
| 66 |
+ } |
|
| 67 |
+ |
|
| 68 |
+ public int getValue() |
|
| 69 |
+ {
|
|
| 70 |
+ return value; |
|
| 71 |
+ } |
|
| 72 |
+ } |
|
| 73 |
+ |
|
| 74 |
+ public static void main(String[] args) {
|
|
| 75 |
+ //Configure Spark |
|
| 76 |
+ staticFiles.location("/static/");
|
|
| 77 |
+ port(8081); |
|
| 78 |
+ |
|
| 79 |
+ |
|
| 80 |
+ |
|
| 81 |
+ _Initializer.Init(); |
|
| 82 |
+ |
|
| 83 |
+ |
|
| 84 |
+ //profile utilisateur |
|
| 85 |
+ get("/user/:id", (req, res) -> {
|
|
| 86 |
+ int result = UserCore.userExist(Integer.parseInt(req.params(":id")));
|
|
| 87 |
+ Base loginStatus = Base.values()[result]; |
|
| 88 |
+ switch(loginStatus) |
|
| 89 |
+ {
|
|
| 90 |
+ case ERROR: |
|
| 91 |
+ halt(500, "Server error, please try again later"); |
|
| 92 |
+ break; |
|
| 93 |
+ case SUCCESS: |
|
| 94 |
+ if(req.session().attribute("user_id") != null && req.session().attribute("user_id").equals(Integer.parseInt(req.params(":id"))))
|
|
| 95 |
+ return UserGUI.getMyProfileById(Integer.parseInt(req.params(":id")));
|
|
| 96 |
+ else |
|
| 97 |
+ return UserGUI.getUserById(Integer.parseInt(req.params(":id")));
|
|
| 98 |
+ case FAILURE: |
|
| 99 |
+ halt(404, "This user dosen't exist"); |
|
| 100 |
+ break; |
|
| 101 |
+ } |
|
| 102 |
+ return null; |
|
| 103 |
+ }); |
|
| 104 |
+ |
|
| 105 |
+ //Racine |
|
| 106 |
+ get("/", (req,res) ->{
|
|
| 107 |
+ if(req.session().attribute("user_id") != null)
|
|
| 108 |
+ {
|
|
| 109 |
+ int userId = req.session().attribute("user_id");
|
|
| 110 |
+ res.redirect("/user/"+ String.valueOf(userId));
|
|
| 111 |
+ } |
|
| 112 |
+ else |
|
| 113 |
+ {
|
|
| 114 |
+ String str = new UtilGUI().frontPage(); |
|
| 115 |
+ if(str == null) |
|
| 116 |
+ {
|
|
| 117 |
+ res.status(404); |
|
| 118 |
+ res.body("html not found");
|
|
| 119 |
+ return null; |
|
| 120 |
+ } |
|
| 121 |
+ res.type("text/html");
|
|
| 122 |
+ res.status(200); |
|
| 123 |
+ return str; |
|
| 124 |
+ } |
|
| 125 |
+ return null; |
|
| 126 |
+ }); |
|
| 127 |
+ |
|
| 128 |
+ //Redirige vers le profil de l'utilisateur connecté (peut etre appelé depuis un form) |
|
| 129 |
+ get("/userRedirect", (req,res) ->{
|
|
| 130 |
+ if(req.session().attribute("user_id") == null)
|
|
| 131 |
+ {
|
|
| 132 |
+ halt(401, "You must login to do that"); |
|
| 133 |
+ } |
|
| 134 |
+ int userId = req.session().attribute("user_id");
|
|
| 135 |
+ res.redirect("/user/"+ String.valueOf(userId));
|
|
| 136 |
+ return null; |
|
| 137 |
+ }); |
|
| 138 |
+ |
|
| 139 |
+ //Pour première connexion journalière, donne un nouveau pokemon a un utilisateur |
|
| 140 |
+ get("/user/:id/newPkm", (req, resp) ->{
|
|
| 141 |
+ if(req.session().attribute("user_id") == null)
|
|
| 142 |
+ {
|
|
| 143 |
+ halt(401, "You must login to do that"); |
|
| 144 |
+ } |
|
| 145 |
+ int userId = req.session().attribute("user_id");
|
|
| 146 |
+ int id = Integer.parseInt(req.params(":id"));
|
|
| 147 |
+ if(req.session().attribute("user_id") != null && userId != id)
|
|
| 148 |
+ {
|
|
| 149 |
+ halt(401, "You are not welcome here"); |
|
| 150 |
+ } |
|
| 151 |
+ //On utilise un cookie, c'est pas très propre |
|
| 152 |
+ if(req.session().attribute("firstco") != null && Boolean.parseBoolean(req.session().attribute("firstco")))
|
|
| 153 |
+ {
|
|
| 154 |
+ req.session().attribute("firstco","false");
|
|
| 155 |
+ int result = UserCore.userExist(Integer.parseInt(req.params(":id")));
|
|
| 156 |
+ Base loginStatus = Base.values()[result]; |
|
| 157 |
+ switch(loginStatus) |
|
| 158 |
+ {
|
|
| 159 |
+ case ERROR: |
|
| 160 |
+ halt(500, "Server error, please try again later"); |
|
| 161 |
+ break; |
|
| 162 |
+ case SUCCESS: |
|
| 163 |
+ return PokemonGUI.getNewPokemon(req.session().attribute("user_id"));
|
|
| 164 |
+ case FAILURE: |
|
| 165 |
+ halt(404, "This user dosen't exist"); |
|
| 166 |
+ break; |
|
| 167 |
+ } |
|
| 168 |
+ } |
|
| 169 |
+ else |
|
| 170 |
+ {
|
|
| 171 |
+ halt(401, "You are not welcome here"); |
|
| 172 |
+ } |
|
| 173 |
+ return null; |
|
| 174 |
+ }); |
|
| 175 |
+ |
|
| 176 |
+ //Renvoie les utilisateur ayant un pseudo ou login avec search |
|
| 177 |
+ get("/userSearch", (req,res) -> {
|
|
| 178 |
+ if(req.session().attribute("user_id") == null)
|
|
| 179 |
+ {
|
|
| 180 |
+ halt(401, "You must login to do that"); |
|
| 181 |
+ } |
|
| 182 |
+ if(req.queryParams("search") == null)
|
|
| 183 |
+ {
|
|
| 184 |
+ halt(422, "You took a wrong turn"); |
|
| 185 |
+ } |
|
| 186 |
+ if(req.queryParams("search").isEmpty())
|
|
| 187 |
+ {
|
|
| 188 |
+ halt(422, "Please enter a user id or pseudo"); |
|
| 189 |
+ } |
|
| 190 |
+ return UserGUI.searchUser(req.queryParams("search"));
|
|
| 191 |
+ }); |
|
| 192 |
+ |
|
| 193 |
+ //Selectionne un pokemon lors de la réponse a un échange indéfini |
|
| 194 |
+ get("/exchange/:id/selectPokemon" , (req,resp) -> {
|
|
| 195 |
+ if(req.session().attribute("user_id") == null)
|
|
| 196 |
+ {
|
|
| 197 |
+ halt(401, "You must login to do that"); |
|
| 198 |
+ } |
|
| 199 |
+ if(req.queryParams("pkmId") == null || req.queryParams("pkmLvl") == null || req.queryParams("pkmShiny") == null)
|
|
| 200 |
+ {
|
|
| 201 |
+ halt(412, "We couln't process"); |
|
| 202 |
+ } |
|
| 203 |
+ //On ne vérifie pas si l'utilisateur a l'autorisation, donc un utilisateur peut échanger avec lui meme |
|
| 204 |
+ int result = ExchangeCore.exchangeExist(Integer.parseInt(req.params(":id")));
|
|
| 205 |
+ Base loginStatus = Base.values()[result]; |
|
| 206 |
+ int userId = req.session().attribute("user_id");
|
|
| 207 |
+ switch(loginStatus) |
|
| 208 |
+ {
|
|
| 209 |
+ case ERROR: |
|
| 210 |
+ halt(500, "Server error, please try again later"); |
|
| 211 |
+ break; |
|
| 212 |
+ case SUCCESS: |
|
| 213 |
+ return PokemonGUI.getPokemonForExchange(Integer.parseInt(req.params("id")),userId, Integer.parseInt(req.queryParams("pkmId")), Integer.parseInt(req.queryParams("pkmLvl")), Boolean.parseBoolean(req.queryParams("pkmShiny")));
|
|
| 214 |
+ case FAILURE: |
|
| 215 |
+ halt(404, "This page dosen't exist"); |
|
| 216 |
+ break; |
|
| 217 |
+ } |
|
| 218 |
+ return null; |
|
| 219 |
+ }); |
|
| 220 |
+ |
|
| 221 |
+ //Permet de choisir un pokemon a échangé pour un échange défini |
|
| 222 |
+ get("/user/:userid/pokemon/:pkmid/exchange/choosePkm", (req,resp) -> {
|
|
| 223 |
+ if(req.session().attribute("user_id") == null)
|
|
| 224 |
+ {
|
|
| 225 |
+ halt(401, "You must login to do that"); |
|
| 226 |
+ } |
|
| 227 |
+ int userId = req.session().attribute("user_id");
|
|
| 228 |
+ int id = Integer.parseInt(req.params(":userid"));
|
|
| 229 |
+ if(req.session().attribute("user_id") != null && userId != id)
|
|
| 230 |
+ {
|
|
| 231 |
+ halt(401, "You are not welcome here"); |
|
| 232 |
+ } |
|
| 233 |
+ int result = UserCore.userExist(Integer.parseInt(req.params(":userid")));
|
|
| 234 |
+ Base loginStatus = Base.values()[result]; |
|
| 235 |
+ switch(loginStatus) |
|
| 236 |
+ {
|
|
| 237 |
+ case ERROR: |
|
| 238 |
+ halt(500, "Server error, please try again later"); |
|
| 239 |
+ break; |
|
| 240 |
+ case SUCCESS: |
|
| 241 |
+ {
|
|
| 242 |
+ if(PokemonCore.isPokemonOwnedByUser(id, Integer.parseInt(req.params(":pkmid"))))
|
|
| 243 |
+ return PokemonGUI.getPokemonForNewExchangeOffer( id,userId, Integer.parseInt(req.params(":pkmid")));
|
|
| 244 |
+ else |
|
| 245 |
+ halt(404, "This page dosen't exist"); |
|
| 246 |
+ } |
|
| 247 |
+ case FAILURE: |
|
| 248 |
+ halt(404, "This page dosen't exist"); |
|
| 249 |
+ break; |
|
| 250 |
+ } |
|
| 251 |
+ return null; |
|
| 252 |
+ }); |
|
| 253 |
+ |
|
| 254 |
+ //Creer un échange défini |
|
| 255 |
+ get("/user/:userid/pokemon/:pkmid/exchange", (req,resp) -> {
|
|
| 256 |
+ if(req.session().attribute("user_id") == null)
|
|
| 257 |
+ {
|
|
| 258 |
+ halt(401, "You must login to do that"); |
|
| 259 |
+ } |
|
| 260 |
+ int userId = req.session().attribute("user_id");
|
|
| 261 |
+ int id = Integer.parseInt(req.params(":userid"));
|
|
| 262 |
+ if(userId == id) |
|
| 263 |
+ return ExchangeGUI.myNewExchange(userId , Integer.parseInt(req.params("pkmid")));
|
|
| 264 |
+ else |
|
| 265 |
+ return ExchangeGUI.newExchange(id, Integer.parseInt(req.params("pkmid")), userId, 0);
|
|
| 266 |
+ }); |
|
| 267 |
+ |
|
| 268 |
+ //Affiche l'offre d'échange après le choix d'un pokemon lors d'un échange indéfini |
|
| 269 |
+ post("/user/:userid/pokemon/:pkmid/exchange/selected/:pkmid2", (req,resp) -> {
|
|
| 270 |
+ if(req.session().attribute("user_id") == null)
|
|
| 271 |
+ {
|
|
| 272 |
+ halt(401, "You must login to do that"); |
|
| 273 |
+ } |
|
| 274 |
+ int userId = req.session().attribute("user_id");
|
|
| 275 |
+ |
|
| 276 |
+ return ExchangeGUI.newExchange(Integer.parseInt(req.params("userid")), Integer.parseInt(req.params("pkmid")), userId, Integer.parseInt(req.params("pkmid2")));
|
|
| 277 |
+ }); |
|
| 278 |
+ |
|
| 279 |
+ //Valide un échnage indéfini |
|
| 280 |
+ post("/user/:userid/pokemon/:pkmid/exchange/valided/:pkmid2", (req,resp) -> {
|
|
| 281 |
+ if(req.session().attribute("user_id") == null)
|
|
| 282 |
+ {
|
|
| 283 |
+ halt(401, "You must login to do that"); |
|
| 284 |
+ } |
|
| 285 |
+ int userId = req.session().attribute("user_id");
|
|
| 286 |
+ |
|
| 287 |
+ |
|
| 288 |
+ int result = ExchangeCore.createNewExchange(userId, Integer.parseInt(req.params(":pkmid2")), Integer.parseInt(req.params(":userid")), Integer.parseInt(req.params(":pkmid")));
|
|
| 289 |
+ |
|
| 290 |
+ InitiateExchange loginStatus = InitiateExchange.values()[result]; |
|
| 291 |
+ switch(loginStatus) |
|
| 292 |
+ {
|
|
| 293 |
+ case ERROR: |
|
| 294 |
+ halt(500, "Server error, please try again later"); |
|
| 295 |
+ break; |
|
| 296 |
+ case SUCCESS: |
|
| 297 |
+ userId = req.session().attribute("user_id");
|
|
| 298 |
+ //On devrait renvoiyer un 200 mais il est overwriten par le redirect |
|
| 299 |
+ resp.redirect("/user/"+ String.valueOf(userId));
|
|
| 300 |
+ break; |
|
| 301 |
+ case INCORRECTPKM: |
|
| 302 |
+ halt(422, "This pokemon doesn't exist"); |
|
| 303 |
+ break; |
|
| 304 |
+ case INCORRECTLVL: |
|
| 305 |
+ halt(422, "Non valid level"); |
|
| 306 |
+ break; |
|
| 307 |
+ } |
|
| 308 |
+ |
|
| 309 |
+ return null; |
|
| 310 |
+ }); |
|
| 311 |
+ |
|
| 312 |
+ //Permet de creer un nouvel échange indéfini |
|
| 313 |
+ post("/user/:id/exchangeOut/new", (req,resp) -> {
|
|
| 314 |
+ if(req.session().attribute("user_id") == null)
|
|
| 315 |
+ {
|
|
| 316 |
+ halt(401, "You must login to do that"); |
|
| 317 |
+ } |
|
| 318 |
+ if(req.queryParams("dataId") == null)
|
|
| 319 |
+ {
|
|
| 320 |
+ halt(422, "Please select a pokemon to exchange"); |
|
| 321 |
+ } |
|
| 322 |
+ int userId = req.session().attribute("user_id");
|
|
| 323 |
+ int id = Integer.parseInt(req.params(":id"));
|
|
| 324 |
+ if(req.session().attribute("user_id") != null && userId != id)
|
|
| 325 |
+ {
|
|
| 326 |
+ halt(401, "You are not welcome here"); |
|
| 327 |
+ } |
|
| 328 |
+ if((req.queryParams("anyPkm") == null && req.queryParams("pkmName").isEmpty()) || (req.queryParams("anyLvl") == null && req.queryParams("pkmLvl").isEmpty()))
|
|
| 329 |
+ {
|
|
| 330 |
+ halt(422, "Please enter information about the pokemon you want"); |
|
| 331 |
+ } |
|
| 332 |
+ String pkmName = ""; |
|
| 333 |
+ if(!req.queryParams("pkmName").isEmpty())
|
|
| 334 |
+ pkmName = req.queryParams("pkmName");
|
|
| 335 |
+ |
|
| 336 |
+ int pkmLvl = 0; |
|
| 337 |
+ if(!req.queryParams("pkmLvl").isEmpty())
|
|
| 338 |
+ pkmLvl = Integer.parseInt(req.queryParams("pkmLvl"));
|
|
| 339 |
+ |
|
| 340 |
+ Boolean pkmShiny = req.queryParams("pkmShiny") == null;
|
|
| 341 |
+ |
|
| 342 |
+ |
|
| 343 |
+ |
|
| 344 |
+ int result = ExchangeCore.createNewExchange(id, Integer.parseInt(req.queryParams("dataId")), pkmName, pkmLvl, pkmShiny);
|
|
| 345 |
+ InitiateExchange loginStatus = InitiateExchange.values()[result]; |
|
| 346 |
+ switch(loginStatus) |
|
| 347 |
+ {
|
|
| 348 |
+ case ERROR: |
|
| 349 |
+ halt(500, "Server error, please try again later"); |
|
| 350 |
+ break; |
|
| 351 |
+ case SUCCESS: |
|
| 352 |
+ userId = req.session().attribute("user_id");
|
|
| 353 |
+ resp.redirect("/user/"+ String.valueOf(userId));
|
|
| 354 |
+ break; |
|
| 355 |
+ case INCORRECTPKM: |
|
| 356 |
+ halt(422, "This pokemon doesn't exist"); |
|
| 357 |
+ break; |
|
| 358 |
+ case INCORRECTLVL: |
|
| 359 |
+ halt(422, "Non valid level"); |
|
| 360 |
+ break; |
|
| 361 |
+ } |
|
| 362 |
+ |
|
| 363 |
+ return null; |
|
| 364 |
+ }); |
|
| 365 |
+ |
|
| 366 |
+ //Affiche l'échange cible |
|
| 367 |
+ get("/exchange/:id" , (req,resp) -> {
|
|
| 368 |
+ return ExchangeGUI.getExchangeById(Integer.parseInt(req.params(":id")));
|
|
| 369 |
+ }); |
|
| 370 |
+ |
|
| 371 |
+ //Affiche les échange sortant d'un utilisateur |
|
| 372 |
+ get("/user/:id/exchangeOut" , (req,res) -> {
|
|
| 373 |
+ if(req.session().attribute("user_id") == null)
|
|
| 374 |
+ {
|
|
| 375 |
+ halt(401, "You must login to do that"); |
|
| 376 |
+ } |
|
| 377 |
+ int userId = req.session().attribute("user_id");
|
|
| 378 |
+ int id = Integer.parseInt(req.params(":id"));
|
|
| 379 |
+ return ExchangeGUI.exchangeOut(id, userId == id); |
|
| 380 |
+ }); |
|
| 381 |
+ |
|
| 382 |
+ //Affiche les échange entrant d'un utilisateur |
|
| 383 |
+ get("/user/:id/exchangeIn" , (req,res) -> {
|
|
| 384 |
+ if(req.session().attribute("user_id") == null)
|
|
| 385 |
+ {
|
|
| 386 |
+ halt(401, "You must login to do that"); |
|
| 387 |
+ } |
|
| 388 |
+ int userId = req.session().attribute("user_id");
|
|
| 389 |
+ int id = Integer.parseInt(req.params(":id"));
|
|
| 390 |
+ if(req.session().attribute("user_id") != null && userId != id)
|
|
| 391 |
+ {
|
|
| 392 |
+ halt(401, "You are not welcome here"); |
|
| 393 |
+ } |
|
| 394 |
+ return ExchangeGUI.exchangeIn(id); |
|
| 395 |
+ }); |
|
| 396 |
+ |
|
| 397 |
+ //Affiche l'offre d'échange avant de la validé |
|
| 398 |
+ post("/exchange/:id/offer", (req,resp) -> {
|
|
| 399 |
+ if(req.session().attribute("user_id") == null)
|
|
| 400 |
+ {
|
|
| 401 |
+ halt(401, "You must login to do that"); |
|
| 402 |
+ } |
|
| 403 |
+ return ExchangeGUI.getExchangeOffer(Integer.parseInt(req.params(":id")),Integer.parseInt(req.queryParams("dataId")));
|
|
| 404 |
+ }); |
|
| 405 |
+ |
|
| 406 |
+ //Accepte un échange |
|
| 407 |
+ post("/exchange/:id/accepted", (req,res)->{
|
|
| 408 |
+ if(req.queryParams("dataId") == null)
|
|
| 409 |
+ {
|
|
| 410 |
+ Boolean success = ExchangeCore.doExchange(Integer.parseInt(req.params(":id")));
|
|
| 411 |
+ if(success) |
|
| 412 |
+ {
|
|
| 413 |
+ res.redirect("/userRedirect");
|
|
| 414 |
+ } |
|
| 415 |
+ else |
|
| 416 |
+ halt(500, "The exchange failed"); |
|
| 417 |
+ } |
|
| 418 |
+ else |
|
| 419 |
+ {
|
|
| 420 |
+ int userId = req.session().attribute("user_id");
|
|
| 421 |
+ Boolean success = ExchangeCore.doExchange(Integer.parseInt(req.params(":id")), Integer.parseInt(req.queryParams("dataId")), userId );
|
|
| 422 |
+ |
|
| 423 |
+ if(success) |
|
| 424 |
+ {
|
|
| 425 |
+ res.redirect("/userRedirect");
|
|
| 426 |
+ } |
|
| 427 |
+ else |
|
| 428 |
+ halt(500, "The exchange failed"); |
|
| 429 |
+ } |
|
| 430 |
+ return null; |
|
| 431 |
+ }); |
|
| 432 |
+ |
|
| 433 |
+ //Refuse un échange |
|
| 434 |
+ post("/exchange/:id/refused" , (req,res) ->{
|
|
| 435 |
+ if(req.session().attribute("user_id") == null)
|
|
| 436 |
+ {
|
|
| 437 |
+ halt(401, "You must login to do that"); |
|
| 438 |
+ } |
|
| 439 |
+ Boolean success = ExchangeCore.refuseExchange(Integer.parseInt(req.params(":id")));
|
|
| 440 |
+ if(success) |
|
| 441 |
+ {
|
|
| 442 |
+ res.redirect("/userRedirect");
|
|
| 443 |
+ } |
|
| 444 |
+ else |
|
| 445 |
+ halt(500, "An error occured"); |
|
| 446 |
+ return null; |
|
| 447 |
+ }); |
|
| 448 |
+ |
|
| 449 |
+ //Annule un échange |
|
| 450 |
+ post("/exchange/:id/canceled" , (req,res) ->{
|
|
| 451 |
+ if(req.session().attribute("user_id") == null)
|
|
| 452 |
+ {
|
|
| 453 |
+ halt(401, "You must login to do that"); |
|
| 454 |
+ } |
|
| 455 |
+ Boolean success = ExchangeCore.refuseExchange(Integer.parseInt(req.params(":id")));
|
|
| 456 |
+ if(success) |
|
| 457 |
+ {
|
|
| 458 |
+ res.redirect("/userRedirect");
|
|
| 459 |
+ } |
|
| 460 |
+ else |
|
| 461 |
+ halt(500, "An error occured"); |
|
| 462 |
+ return null; |
|
| 463 |
+ }); |
|
| 464 |
+ |
|
| 465 |
+ //Inscription |
|
| 466 |
+ post("/signup", (req,resp) ->{
|
|
| 467 |
+ if(req.queryParams("pseudo").isEmpty() && req.queryParams("userpwd").isEmpty() && req.queryParams("usermail").isEmpty())
|
|
| 468 |
+ {
|
|
| 469 |
+ halt(422, "Please enter information"); |
|
| 470 |
+ } |
|
| 471 |
+ if(UserCore.userEmailExist(req.queryParams("usermail")))
|
|
| 472 |
+ {
|
|
| 473 |
+ halt(422, "This mail is already registered"); |
|
| 474 |
+ } |
|
| 475 |
+ else |
|
| 476 |
+ {
|
|
| 477 |
+ if(UserCore.createUser(req.queryParams("pseudo"), req.queryParams("userpwd"), req.queryParams("usermail")) == null)
|
|
| 478 |
+ halt(500,"An error occured"); |
|
| 479 |
+ else |
|
| 480 |
+ {
|
|
| 481 |
+ resp.status(201); |
|
| 482 |
+ resp.redirect("/");
|
|
| 483 |
+ } |
|
| 484 |
+ } |
|
| 485 |
+ return null; |
|
| 486 |
+ }); |
|
| 487 |
+ |
|
| 488 |
+ //Connexion |
|
| 489 |
+ post("/login", (req,resp) ->{
|
|
| 490 |
+ int result = UserCore.login(req.queryParams("userpwd"),req.queryParams("usermail"));
|
|
| 491 |
+ Login loginStatus = Login.values()[result]; |
|
| 492 |
+ int userId; |
|
| 493 |
+ switch(loginStatus) |
|
| 494 |
+ {
|
|
| 495 |
+ case ERROR: |
|
| 496 |
+ halt(500, "Server error, please try again later"); |
|
| 497 |
+ break; |
|
| 498 |
+ case SUCCESS: |
|
| 499 |
+ userId = UserCore.getUserIdByMail(req.queryParams("usermail"));
|
|
| 500 |
+ req.session().attribute("user_id", userId);
|
|
| 501 |
+ resp.redirect("/user/"+ String.valueOf(userId));
|
|
| 502 |
+ break; |
|
| 503 |
+ case FIRSTCO: |
|
| 504 |
+ userId = UserCore.getUserIdByMail(req.queryParams("usermail"));
|
|
| 505 |
+ req.session().attribute("user_id", userId);
|
|
| 506 |
+ req.session().attribute("firstco", "true");
|
|
| 507 |
+ resp.redirect("/user/"+ String.valueOf(userId)+"/newPkm");
|
|
| 508 |
+ case INCORRECT: |
|
| 509 |
+ halt(422, "Incorrects informations"); |
|
| 510 |
+ break; |
|
| 511 |
+ } |
|
| 512 |
+ return null; |
|
| 513 |
+ }); |
|
| 514 |
+ |
|
| 515 |
+ //Fait monter un pokemon de niveau |
|
| 516 |
+ post("/lvlup", (req,resp) ->{
|
|
| 517 |
+ if(req.session().attribute("user_id") == null)
|
|
| 518 |
+ {
|
|
| 519 |
+ halt(401, "You must login to do that"); |
|
| 520 |
+ } |
|
| 521 |
+ int id = Integer.parseInt(req.queryParams("userid"));
|
|
| 522 |
+ if(UserCore.lvlup(id)) |
|
| 523 |
+ {
|
|
| 524 |
+ int result = PokemonCore.lvlUpPokemonById(id); |
|
| 525 |
+ Base loginStatus = Base.values()[result]; |
|
| 526 |
+ switch(loginStatus) |
|
| 527 |
+ {
|
|
| 528 |
+ case ERROR: |
|
| 529 |
+ halt(500, "Server error, please try again later"); |
|
| 530 |
+ break; |
|
| 531 |
+ case SUCCESS: |
|
| 532 |
+ resp.redirect("/user/"+ String.valueOf(id));
|
|
| 533 |
+ break; |
|
| 534 |
+ case FAILURE: |
|
| 535 |
+ halt(202, "Already max level"); |
|
| 536 |
+ break; |
|
| 537 |
+ } |
|
| 538 |
+ } |
|
| 539 |
+ //resp.redirect("/user/"+ String.valueOf(req.session().attribute("user_id")));
|
|
| 540 |
+ halt(202,"You don't have any lvl up left"); |
|
| 541 |
+ return null; |
|
| 542 |
+ }); |
|
| 543 |
+ } |
|
| 544 |
+} |
|
| 0 | 545 |
\ No newline at end of file |
| ... | ... |
@@ -0,0 +1,170 @@ |
| 1 |
+package com.uca.core; |
|
| 2 |
+ |
|
| 3 |
+import com.uca.dao.ExchangeDAO; |
|
| 4 |
+import com.uca.entity.ExchangeEntity; |
|
| 5 |
+import com.uca.entity.PokemonEntity; |
|
| 6 |
+import com.uca.entity.UserEntity; |
|
| 7 |
+ |
|
| 8 |
+import java.io.IOException; |
|
| 9 |
+ |
|
| 10 |
+import java.util.ArrayList; |
|
| 11 |
+ |
|
| 12 |
+public class ExchangeCore {
|
|
| 13 |
+ |
|
| 14 |
+ //Renvoie tout les échange |
|
| 15 |
+ public static ArrayList<ExchangeEntity> getAllExchange() throws IOException {
|
|
| 16 |
+ return new ExchangeDAO().getAllExchange(); |
|
| 17 |
+ } |
|
| 18 |
+ |
|
| 19 |
+ //Renvoie l'échange cible |
|
| 20 |
+ public static ExchangeEntity getExchangeById(int exchangeId) throws IOException |
|
| 21 |
+ {
|
|
| 22 |
+ return new ExchangeDAO().getExchangeById(exchangeId); |
|
| 23 |
+ } |
|
| 24 |
+ |
|
| 25 |
+ //Renvoie une offre d'échange avec le pokemon selectionné dans le cas d'un échange indéfini |
|
| 26 |
+ public static ExchangeEntity getNewOffer(int id, int dataId) throws IOException |
|
| 27 |
+ {
|
|
| 28 |
+ ExchangeEntity entity = new ExchangeDAO().getExchangeById(id); |
|
| 29 |
+ |
|
| 30 |
+ if(entity != null) |
|
| 31 |
+ {
|
|
| 32 |
+ entity.setDataPkm2(PokemonCore.getPokemonByDataId(dataId)); |
|
| 33 |
+ } |
|
| 34 |
+ return entity; |
|
| 35 |
+ } |
|
| 36 |
+ |
|
| 37 |
+ //Effectue un échange |
|
| 38 |
+ public static Boolean doExchange(ExchangeEntity exchange) throws IOException |
|
| 39 |
+ {
|
|
| 40 |
+ return new ExchangeDAO().doExchange(exchange); |
|
| 41 |
+ } |
|
| 42 |
+ |
|
| 43 |
+ //Effectue un échange |
|
| 44 |
+ public static Boolean doExchange(int exchange) throws IOException |
|
| 45 |
+ {
|
|
| 46 |
+ return new ExchangeDAO().doExchange(exchange); |
|
| 47 |
+ } |
|
| 48 |
+ |
|
| 49 |
+ //Effectue un échange |
|
| 50 |
+ public static Boolean doExchange(int exchange, int dataId) throws IOException |
|
| 51 |
+ {
|
|
| 52 |
+ ExchangeEntity entity = getExchangeById(exchange); |
|
| 53 |
+ entity.setDataPkm2(PokemonCore.getPokemonByDataId(dataId)); |
|
| 54 |
+ return doExchange(entity); |
|
| 55 |
+ } |
|
| 56 |
+ |
|
| 57 |
+ //Effectue un échange |
|
| 58 |
+ public static Boolean doExchange(int exchange, int dataId, int idUser2) throws IOException |
|
| 59 |
+ {
|
|
| 60 |
+ ExchangeEntity entity = getExchangeById(exchange); |
|
| 61 |
+ entity.setDataPkm2(PokemonCore.getPokemonByDataId(dataId)); |
|
| 62 |
+ entity.setUser2(UserCore.getUserById(idUser2)); |
|
| 63 |
+ return doExchange(entity); |
|
| 64 |
+ } |
|
| 65 |
+ |
|
| 66 |
+ //Creer une offre d'change (n'update pas la BDD) |
|
| 67 |
+ public static ExchangeEntity newExchangeOffer(int iduser1, int dataId, int iduser2, int idpkm2) throws IOException |
|
| 68 |
+ {
|
|
| 69 |
+ PokemonEntity pkm1 = PokemonCore.getPokemonByDataId(dataId); |
|
| 70 |
+ ExchangeEntity exchange = new ExchangeEntity(); |
|
| 71 |
+ UserEntity user1 = UserCore.getUserById(iduser1); |
|
| 72 |
+ UserEntity user2 = UserCore.getUserById(iduser2); |
|
| 73 |
+ if(user2 == null || user1 == null) |
|
| 74 |
+ return null; |
|
| 75 |
+ exchange.setUser1(user1); |
|
| 76 |
+ exchange.setPkm1(pkm1); |
|
| 77 |
+ if(idpkm2 == 0) |
|
| 78 |
+ exchange.setDataPkm2(null); |
|
| 79 |
+ else |
|
| 80 |
+ exchange.setDataPkm2(PokemonCore.getPokemonByDataId(idpkm2)); |
|
| 81 |
+ exchange.setIdPkm2(null); |
|
| 82 |
+ exchange.setUser2(user2); |
|
| 83 |
+ return exchange; |
|
| 84 |
+ } |
|
| 85 |
+ |
|
| 86 |
+ //Renvoie tout les échange entrant d'un utilisateur |
|
| 87 |
+ public static ArrayList<ExchangeEntity> getAllExchangeIn(int userId) throws IOException |
|
| 88 |
+ {
|
|
| 89 |
+ return new ExchangeDAO().getAllExchangeIn(userId); |
|
| 90 |
+ } |
|
| 91 |
+ |
|
| 92 |
+ //Renvoie tout les échange sortant d'un utilisateur |
|
| 93 |
+ public static ArrayList<ExchangeEntity> getAllExchangeOut(int userId, boolean actualUser) throws IOException |
|
| 94 |
+ {
|
|
| 95 |
+ if(actualUser) |
|
| 96 |
+ return new ExchangeDAO().getAllMyExchangeOut(userId); |
|
| 97 |
+ else |
|
| 98 |
+ return new ExchangeDAO().getAllExchangeOut(userId); |
|
| 99 |
+ } |
|
| 100 |
+ |
|
| 101 |
+ //Creer un nouvel echange |
|
| 102 |
+ public static int createNewExchange(int userId, int dataId, String pkmName, int pkmLvl, Boolean shiny) throws IOException |
|
| 103 |
+ {
|
|
| 104 |
+ if(!PokemonCore.pokemonExist(pkmName)) |
|
| 105 |
+ return 2; |
|
| 106 |
+ if(pkmLvl < 0 || pkmLvl >100) |
|
| 107 |
+ return 3; |
|
| 108 |
+ PokemonEntity pkm2 = new PokemonEntity(pkmName.isEmpty() ? 0 : PokemonCore.getPokemonIdByName(pkmName), pkmLvl , shiny); |
|
| 109 |
+ PokemonEntity pkm1 = PokemonCore.getPokemonByDataId(dataId); |
|
| 110 |
+ ExchangeEntity exchange = new ExchangeEntity(); |
|
| 111 |
+ UserEntity user1 = UserCore.getUserById(userId); |
|
| 112 |
+ if(pkm2 == null || user1 == null) |
|
| 113 |
+ return 0; |
|
| 114 |
+ exchange.setUser1(user1); |
|
| 115 |
+ exchange.setPkm1(pkm1); |
|
| 116 |
+ exchange.setDataPkm2(null); |
|
| 117 |
+ exchange.setIdPkm2(pkm2); |
|
| 118 |
+ exchange.setUser2(null); |
|
| 119 |
+ exchange = new ExchangeDAO().create(exchange); |
|
| 120 |
+ |
|
| 121 |
+ return exchange == null ? 0 : 1; |
|
| 122 |
+ } |
|
| 123 |
+ |
|
| 124 |
+ //Creer un nouvel echange |
|
| 125 |
+ public static int createNewExchange(int userId, int dataId, int iduser2, int idpkm2) throws IOException |
|
| 126 |
+ {
|
|
| 127 |
+ PokemonEntity pkm2 = PokemonCore.getPokemonByDataId(idpkm2); |
|
| 128 |
+ PokemonEntity pkm1 = PokemonCore.getPokemonByDataId(dataId); |
|
| 129 |
+ ExchangeEntity exchange = new ExchangeEntity(); |
|
| 130 |
+ UserEntity user1 = UserCore.getUserById(userId); |
|
| 131 |
+ UserEntity user2 = UserCore.getUserById(iduser2); |
|
| 132 |
+ if(pkm2 == null || user1 == null || pkm2 == null || user2 == null) |
|
| 133 |
+ return 0; |
|
| 134 |
+ exchange.setUser1(user1); |
|
| 135 |
+ exchange.setPkm1(pkm1); |
|
| 136 |
+ exchange.setDataPkm2(pkm2); |
|
| 137 |
+ exchange.setIdPkm2(null); |
|
| 138 |
+ exchange.setUser2(user2); |
|
| 139 |
+ |
|
| 140 |
+ exchange = new ExchangeDAO().create(exchange); |
|
| 141 |
+ return exchange == null ? 0 : 1; |
|
| 142 |
+ } |
|
| 143 |
+ |
|
| 144 |
+ //Refuse un échange |
|
| 145 |
+ public static Boolean refuseExchange(int id) throws IOException |
|
| 146 |
+ {
|
|
| 147 |
+ ExchangeEntity exchange = getExchangeById(id); |
|
| 148 |
+ if(exchange == null) |
|
| 149 |
+ return false; |
|
| 150 |
+ new ExchangeDAO().delete(exchange); |
|
| 151 |
+ return true; |
|
| 152 |
+ |
|
| 153 |
+ } |
|
| 154 |
+ |
|
| 155 |
+ //Vérifie si un échange existe |
|
| 156 |
+ public static int exchangeExist(int id) throws IOException |
|
| 157 |
+ {
|
|
| 158 |
+ Boolean bool = new ExchangeDAO().exchangeExist(id); |
|
| 159 |
+ //Existe |
|
| 160 |
+ if(bool) |
|
| 161 |
+ return 1; |
|
| 162 |
+ //N'éxiste pas |
|
| 163 |
+ if(!bool) |
|
| 164 |
+ return 2; |
|
| 165 |
+ else |
|
| 166 |
+ return 0; |
|
| 167 |
+ //Erreur |
|
| 168 |
+ } |
|
| 169 |
+ |
|
| 170 |
+} |
| ... | ... |
@@ -0,0 +1,91 @@ |
| 1 |
+package com.uca.core; |
|
| 2 |
+ |
|
| 3 |
+import com.uca.dao.PokemonDAO; |
|
| 4 |
+import com.uca.entity.PokemonEntity; |
|
| 5 |
+ |
|
| 6 |
+import java.io.IOException; |
|
| 7 |
+ |
|
| 8 |
+import java.util.ArrayList; |
|
| 9 |
+ |
|
| 10 |
+public class PokemonCore {
|
|
| 11 |
+ |
|
| 12 |
+ //Renvoie le pokemon avec l'id ciblé (pokeapi) |
|
| 13 |
+ public static PokemonEntity getPokemonById(int id) throws IOException {
|
|
| 14 |
+ return new PokemonDAO().getPokemonById(id); |
|
| 15 |
+ } |
|
| 16 |
+ |
|
| 17 |
+ //Renvoie l'id du pokemon avec le nom donné (pokeapi) |
|
| 18 |
+ public static int getPokemonIdByName(String name) throws IOException |
|
| 19 |
+ {
|
|
| 20 |
+ return new PokemonDAO().getPokemonIdByName(name); |
|
| 21 |
+ } |
|
| 22 |
+ |
|
| 23 |
+ //Réciroque de la prédcédente (pokeapi) |
|
| 24 |
+ public static String getPokemonNameById(int id) throws IOException {
|
|
| 25 |
+ return new PokemonDAO().getPokemonNameById(id); |
|
| 26 |
+ } |
|
| 27 |
+ |
|
| 28 |
+ //Renvoie tout les pokemon d'un utilisateur |
|
| 29 |
+ public static ArrayList<PokemonEntity> getPokemonByUser(int id) throws IOException{
|
|
| 30 |
+ return new PokemonDAO().getPokemonByUser(id); |
|
| 31 |
+ } |
|
| 32 |
+ |
|
| 33 |
+ //Permet de tirer au hasard un pokemon |
|
| 34 |
+ public static PokemonEntity getNewPokemon(int userId) throws IOException{
|
|
| 35 |
+ return new PokemonDAO().getNewPokemon(userId); |
|
| 36 |
+ } |
|
| 37 |
+ |
|
| 38 |
+ //Ajoute un niveau au pokemon cible |
|
| 39 |
+ public static int lvlUpPokemonById(int id) |
|
| 40 |
+ {
|
|
| 41 |
+ return new PokemonDAO().lvlUpPokemonById(id); |
|
| 42 |
+ |
|
| 43 |
+ } |
|
| 44 |
+ |
|
| 45 |
+ //Renvoie une instance simplifié d'un pokemon |
|
| 46 |
+ public static PokemonEntity getSimpleInstance(int id, int lvl, Boolean shiny) throws IOException |
|
| 47 |
+ {
|
|
| 48 |
+ PokemonEntity pkm = new PokemonEntity(id, id == 0 ? "" : getPokemonNameById(id), lvl ,shiny); |
|
| 49 |
+ if(pkm.getSprite() == null) |
|
| 50 |
+ PokemonDAO.setPokemonSprite(pkm); |
|
| 51 |
+ return pkm; |
|
| 52 |
+ } |
|
| 53 |
+ |
|
| 54 |
+ //Renvoie l'id de l'utilisateur ayant le pokemon cible |
|
| 55 |
+ public static int getOwnerId(int pkmId) throws IOException |
|
| 56 |
+ {
|
|
| 57 |
+ return new PokemonDAO().getOwnerId(pkmId); |
|
| 58 |
+ } |
|
| 59 |
+ |
|
| 60 |
+ //Renvoie un pokemon de la table own |
|
| 61 |
+ public static PokemonEntity getPokemonByDataId(int id) throws IOException |
|
| 62 |
+ {
|
|
| 63 |
+ return new PokemonDAO().getPokemonByDataId(id); |
|
| 64 |
+ } |
|
| 65 |
+ |
|
| 66 |
+ //Permet de selectionner un pokemon pour un echange |
|
| 67 |
+ public static ArrayList<PokemonEntity> getPokemonForExchange(int ownerId, int id, int lvl, Boolean shiny) throws IOException |
|
| 68 |
+ {
|
|
| 69 |
+ PokemonEntity pkm = new PokemonEntity(id, lvl, shiny); |
|
| 70 |
+ return new PokemonDAO().getPokemonForExchange(ownerId, pkm); |
|
| 71 |
+ } |
|
| 72 |
+ |
|
| 73 |
+ //Vérifie si un pokemon existe dans notre BDD |
|
| 74 |
+ public static Boolean pokemonExist(String name) throws IOException |
|
| 75 |
+ {
|
|
| 76 |
+ return new PokemonDAO().pokemonExist(name); |
|
| 77 |
+ } |
|
| 78 |
+ |
|
| 79 |
+ //Vérifie si un pokemon existe dans notre BDD |
|
| 80 |
+ public static Boolean pokemonExist(int id) throws IOException |
|
| 81 |
+ {
|
|
| 82 |
+ return new PokemonDAO().pokemonExist(id); |
|
| 83 |
+ } |
|
| 84 |
+ |
|
| 85 |
+ //Vérifie si un pokemon appartient a un utilisateur |
|
| 86 |
+ public static Boolean isPokemonOwnedByUser(int userId, int pkmId) throws IOException |
|
| 87 |
+ {
|
|
| 88 |
+ return new PokemonDAO().isPokemonOwnedByUser(userId,pkmId); |
|
| 89 |
+ } |
|
| 90 |
+ |
|
| 91 |
+} |
| ... | ... |
@@ -0,0 +1,80 @@ |
| 1 |
+package com.uca.core; |
|
| 2 |
+ |
|
| 3 |
+import com.uca.dao.UserDAO; |
|
| 4 |
+import com.uca.entity.UserEntity; |
|
| 5 |
+import com.uca.entity.UserInfosEntity; |
|
| 6 |
+ |
|
| 7 |
+ |
|
| 8 |
+import java.util.ArrayList; |
|
| 9 |
+ |
|
| 10 |
+public class UserCore {
|
|
| 11 |
+ |
|
| 12 |
+ //Renvoie tout les utilsateur |
|
| 13 |
+ public static ArrayList<UserEntity> getAllUsers() {
|
|
| 14 |
+ return new UserDAO().getAllUsers(); |
|
| 15 |
+ } |
|
| 16 |
+ |
|
| 17 |
+ //Renvoie l'utilisateur ciblé |
|
| 18 |
+ public static UserEntity getUserById(int id) {
|
|
| 19 |
+ return new UserDAO().getUserById(id); |
|
| 20 |
+ } |
|
| 21 |
+ |
|
| 22 |
+ //Vérifie si un mail est enregistré |
|
| 23 |
+ public static Boolean userEmailExist(String mail){
|
|
| 24 |
+ return new UserDAO().userEmailExist(mail); |
|
| 25 |
+ } |
|
| 26 |
+ |
|
| 27 |
+ //Crée un nouvel utilisateur |
|
| 28 |
+ public static UserEntity createUser(String pseudo, String pswd, String email) |
|
| 29 |
+ {
|
|
| 30 |
+ UserEntity user = new UserEntity(pseudo, pswd, email); |
|
| 31 |
+ return new UserDAO().create(user); |
|
| 32 |
+ } |
|
| 33 |
+ |
|
| 34 |
+ //Récupère les infos d'un utilisateur (pour le profil) |
|
| 35 |
+ public static UserInfosEntity getUserInfo(int id) |
|
| 36 |
+ {
|
|
| 37 |
+ return new UserDAO().getUserInfo(id); |
|
| 38 |
+ } |
|
| 39 |
+ |
|
| 40 |
+ //Recupère l'id d'un utilisateur avec le mail donné |
|
| 41 |
+ public static int getUserIdByMail(String mail) |
|
| 42 |
+ {
|
|
| 43 |
+ return new UserDAO().getUserIdByMail(mail); |
|
| 44 |
+ } |
|
| 45 |
+ |
|
| 46 |
+ //Test si les infos de login sont bonnes |
|
| 47 |
+ public static int login(String pswd, String mail) |
|
| 48 |
+ {
|
|
| 49 |
+ return new UserDAO().login(pswd, mail); |
|
| 50 |
+ } |
|
| 51 |
+ |
|
| 52 |
+ //Test les lvlup d'un joueur |
|
| 53 |
+ public static Boolean lvlup(int id) |
|
| 54 |
+ {
|
|
| 55 |
+ return new UserDAO().lvlup(id); |
|
| 56 |
+ } |
|
| 57 |
+ |
|
| 58 |
+ //Met a jour les lvlup des joueur a 5 |
|
| 59 |
+ public static void updateLvlUp() |
|
| 60 |
+ {
|
|
| 61 |
+ new UserDAO().updateLvlUp(); |
|
| 62 |
+ } |
|
| 63 |
+ |
|
| 64 |
+ //Renvoie tout les utilisateur ayant le login ou le pseaudo valant search |
|
| 65 |
+ public static ArrayList<UserEntity> userSearch(String search) |
|
| 66 |
+ {
|
|
| 67 |
+ return new UserDAO().userSearch(search); |
|
| 68 |
+ } |
|
| 69 |
+ |
|
| 70 |
+ //Vérifie si un utilisateur existe |
|
| 71 |
+ public static int userExist(int id) |
|
| 72 |
+ {
|
|
| 73 |
+ Boolean bool = new UserDAO().userExist(id); |
|
| 74 |
+ if(bool) |
|
| 75 |
+ return 1; |
|
| 76 |
+ if(!bool) |
|
| 77 |
+ return 2; |
|
| 78 |
+ return 0; |
|
| 79 |
+ } |
|
| 80 |
+} |
| ... | ... |
@@ -0,0 +1,255 @@ |
| 1 |
+package com.uca.dao; |
|
| 2 |
+ |
|
| 3 |
+import com.uca.entity.ExchangeEntity; |
|
| 4 |
+import com.uca.core.PokemonCore; |
|
| 5 |
+import com.uca.core.UserCore; |
|
| 6 |
+import com.uca.entity.PokemonEntity; |
|
| 7 |
+import org.mindrot.jbcrypt.BCrypt; |
|
| 8 |
+ |
|
| 9 |
+import java.sql.*; |
|
| 10 |
+import java.util.ArrayList; |
|
| 11 |
+import java.util.Date; |
|
| 12 |
+import java.util.Calendar; |
|
| 13 |
+import java.io.IOException; |
|
| 14 |
+ |
|
| 15 |
+public class ExchangeDAO extends _Generic<ExchangeEntity> {
|
|
| 16 |
+ //Renvoie tout les échange (plus utilisé) |
|
| 17 |
+ public ArrayList<ExchangeEntity> getAllExchange() throws IOException |
|
| 18 |
+ {
|
|
| 19 |
+ ArrayList<ExchangeEntity> entities = new ArrayList<>(); |
|
| 20 |
+ try {
|
|
| 21 |
+ PreparedStatement preparedStatement = this.connect.prepareStatement("SELECT * FROM exchange ORDER BY id ASC;");
|
|
| 22 |
+ ResultSet resultSet = preparedStatement.executeQuery(); |
|
| 23 |
+ while (resultSet.next()) {
|
|
| 24 |
+ ExchangeEntity entity = new ExchangeEntity(); |
|
| 25 |
+ entity.setId(resultSet.getInt("id"));
|
|
| 26 |
+ entity.setPkm1(PokemonCore.getPokemonByDataId(resultSet.getInt("idpkm1")));
|
|
| 27 |
+ entity.setDataPkm2(resultSet.getInt("IDDATA_PKM2") != 0 ? PokemonCore.getPokemonByDataId(resultSet.getInt("IDDATA_PKM2")) : null);
|
|
| 28 |
+ entity.setUser1(UserCore.getUserById(resultSet.getInt("iduser1")));
|
|
| 29 |
+ entity.setUser2(resultSet.getInt("iduser2") != 0 ? UserCore.getUserById(resultSet.getInt("iduser2")) : null);
|
|
| 30 |
+ |
|
| 31 |
+ if(entity.getDataPkm2() ==null) |
|
| 32 |
+ entity.setIdPkm2(PokemonCore.getSimpleInstance(resultSet.getInt("idpkm2"), resultSet.getInt("lvl") ,resultSet.getBoolean("shiny")));
|
|
| 33 |
+ |
|
| 34 |
+ |
|
| 35 |
+ entities.add(entity); |
|
| 36 |
+ } |
|
| 37 |
+ } catch (SQLException e) {
|
|
| 38 |
+ e.printStackTrace(); |
|
| 39 |
+ } |
|
| 40 |
+ |
|
| 41 |
+ return entities; |
|
| 42 |
+ } |
|
| 43 |
+ |
|
| 44 |
+ //Vérifie si un echange existe |
|
| 45 |
+ public Boolean exchangeExist(int id) throws IOException |
|
| 46 |
+ {
|
|
| 47 |
+ Boolean exist = null; |
|
| 48 |
+ try {
|
|
| 49 |
+ |
|
| 50 |
+ PreparedStatement preparedStatement = this.connect.prepareStatement("SELECT * FROM exchange WHERE id = ? ;");
|
|
| 51 |
+ preparedStatement.setInt(1, id); |
|
| 52 |
+ ResultSet resultSet = preparedStatement.executeQuery(); |
|
| 53 |
+ exist = resultSet.next(); |
|
| 54 |
+ } catch (SQLException e) {
|
|
| 55 |
+ e.printStackTrace(); |
|
| 56 |
+ } |
|
| 57 |
+ return exist; |
|
| 58 |
+ } |
|
| 59 |
+ |
|
| 60 |
+ //Valide et effectu un échange |
|
| 61 |
+ public Boolean doExchange(ExchangeEntity exchange) throws IOException |
|
| 62 |
+ {
|
|
| 63 |
+ try |
|
| 64 |
+ {
|
|
| 65 |
+ PreparedStatement preparedStatement = this.connect.prepareStatement("UPDATE own SET idowner = (?), getting_Date = (?) WHERE id = (?);");
|
|
| 66 |
+ java.util.Date date = new java.util.Date(); |
|
| 67 |
+ preparedStatement.setInt(1, exchange.getUser1().getLogin()); |
|
| 68 |
+ preparedStatement.setDate(2, new java.sql.Date(date.getTime())); |
|
| 69 |
+ preparedStatement.setInt(3, exchange.getDataPkm2().getDataId()); |
|
| 70 |
+ preparedStatement.executeUpdate(); |
|
| 71 |
+ |
|
| 72 |
+ preparedStatement = this.connect.prepareStatement("UPDATE own SET idowner = (?), getting_Date = (?) WHERE id = (?);");
|
|
| 73 |
+ preparedStatement.setInt(1, exchange.getUser2().getLogin()); |
|
| 74 |
+ preparedStatement.setDate(2, new java.sql.Date(date.getTime())); |
|
| 75 |
+ preparedStatement.setInt(3, exchange.getPkm1().getDataId()); |
|
| 76 |
+ preparedStatement.executeUpdate(); |
|
| 77 |
+ |
|
| 78 |
+ //Supprime tout les échange contenant un des pokemon échangé (ils ne sont plus valide) |
|
| 79 |
+ preparedStatement = this.connect.prepareStatement("DELETE FROM exchange WHERE idpkm1 = (?) or IDDATA_PKM2 = (?);");
|
|
| 80 |
+ preparedStatement.setInt(1, exchange.getPkm1().getDataId()); |
|
| 81 |
+ preparedStatement.setInt(2, exchange.getDataPkm2().getDataId()); |
|
| 82 |
+ preparedStatement.executeUpdate(); |
|
| 83 |
+ |
|
| 84 |
+ |
|
| 85 |
+ return true; |
|
| 86 |
+ } |
|
| 87 |
+ catch (SQLException e) |
|
| 88 |
+ {
|
|
| 89 |
+ e.printStackTrace(); |
|
| 90 |
+ } |
|
| 91 |
+ return false; |
|
| 92 |
+ } |
|
| 93 |
+ |
|
| 94 |
+ //Valide et effectu un échange |
|
| 95 |
+ public Boolean doExchange(int exchange) throws IOException |
|
| 96 |
+ {
|
|
| 97 |
+ ExchangeEntity entity = getExchangeById(exchange); |
|
| 98 |
+ return doExchange(entity); |
|
| 99 |
+ |
|
| 100 |
+ } |
|
| 101 |
+ |
|
| 102 |
+ //Récupere un échange par un id |
|
| 103 |
+ public ExchangeEntity getExchangeById(int id) throws IOException |
|
| 104 |
+ {
|
|
| 105 |
+ ExchangeEntity entity = null; |
|
| 106 |
+ try {
|
|
| 107 |
+ PreparedStatement preparedStatement = this.connect.prepareStatement("SELECT * FROM exchange WHERE id = (?);");
|
|
| 108 |
+ preparedStatement.setInt(1, id); |
|
| 109 |
+ ResultSet resultSet = preparedStatement.executeQuery(); |
|
| 110 |
+ if(resultSet.next()) {
|
|
| 111 |
+ entity = new ExchangeEntity(); |
|
| 112 |
+ entity.setId(resultSet.getInt("id"));
|
|
| 113 |
+ entity.setPkm1(PokemonCore.getPokemonByDataId(resultSet.getInt("idpkm1")));
|
|
| 114 |
+ entity.setDataPkm2(resultSet.getInt("IDDATA_PKM2") != 0 ? PokemonCore.getPokemonByDataId(resultSet.getInt("IDDATA_PKM2")) : null);
|
|
| 115 |
+ entity.setUser1(UserCore.getUserById(resultSet.getInt("iduser1")));
|
|
| 116 |
+ entity.setUser2(resultSet.getInt("iduser2") != 0 ? UserCore.getUserById(resultSet.getInt("iduser2")) : null);
|
|
| 117 |
+ |
|
| 118 |
+ if(entity.getDataPkm2() ==null) |
|
| 119 |
+ entity.setIdPkm2(PokemonCore.getSimpleInstance(resultSet.getInt("idpkm2"), resultSet.getInt("lvl") ,resultSet.getBoolean("shiny")));
|
|
| 120 |
+ |
|
| 121 |
+ } |
|
| 122 |
+ } catch (SQLException e) {
|
|
| 123 |
+ e.printStackTrace(); |
|
| 124 |
+ } |
|
| 125 |
+ |
|
| 126 |
+ return entity; |
|
| 127 |
+ } |
|
| 128 |
+ |
|
| 129 |
+ //Récupère tous les échange entrant d'un utilisateur |
|
| 130 |
+ public ArrayList<ExchangeEntity> getAllExchangeIn(int userId) throws IOException |
|
| 131 |
+ {
|
|
| 132 |
+ ArrayList<ExchangeEntity> entities = new ArrayList<>(); |
|
| 133 |
+ try {
|
|
| 134 |
+ PreparedStatement preparedStatement = this.connect.prepareStatement("SELECT * FROM exchange where iduser2 = (?) ORDER BY id ASC;");
|
|
| 135 |
+ preparedStatement.setInt(1,userId); |
|
| 136 |
+ ResultSet resultSet = preparedStatement.executeQuery(); |
|
| 137 |
+ while (resultSet.next()) {
|
|
| 138 |
+ ExchangeEntity entity = new ExchangeEntity(); |
|
| 139 |
+ entity.setId(resultSet.getInt("id"));
|
|
| 140 |
+ entity.setPkm1(PokemonCore.getPokemonByDataId(resultSet.getInt("idpkm1")));
|
|
| 141 |
+ entity.setDataPkm2(resultSet.getInt("IDDATA_PKM2") != 0 ? PokemonCore.getPokemonByDataId(resultSet.getInt("IDDATA_PKM2")) : null);
|
|
| 142 |
+ entity.setUser1(UserCore.getUserById(resultSet.getInt("iduser1")));
|
|
| 143 |
+ entity.setUser2(resultSet.getInt("iduser2") != 0 ? UserCore.getUserById(resultSet.getInt("iduser2")) : null);
|
|
| 144 |
+ |
|
| 145 |
+ if(entity.getDataPkm2() ==null) |
|
| 146 |
+ entity.setIdPkm2(PokemonCore.getSimpleInstance(resultSet.getInt("idpkm2"), resultSet.getInt("lvl") ,resultSet.getBoolean("shiny")));
|
|
| 147 |
+ |
|
| 148 |
+ |
|
| 149 |
+ entities.add(entity); |
|
| 150 |
+ } |
|
| 151 |
+ } catch (SQLException e) {
|
|
| 152 |
+ e.printStackTrace(); |
|
| 153 |
+ } |
|
| 154 |
+ |
|
| 155 |
+ return entities; |
|
| 156 |
+ } |
|
| 157 |
+ |
|
| 158 |
+ //Récupère tous les échange sortants d'un utilisateur |
|
| 159 |
+ public ArrayList<ExchangeEntity> getAllExchangeOut(int userId) throws IOException |
|
| 160 |
+ {
|
|
| 161 |
+ ArrayList<ExchangeEntity> entities = new ArrayList<>(); |
|
| 162 |
+ try {
|
|
| 163 |
+ PreparedStatement preparedStatement = this.connect.prepareStatement("SELECT * FROM exchange WHERE iduser1 = (?) ORDER BY id ASC;");
|
|
| 164 |
+ preparedStatement.setInt(1,userId); |
|
| 165 |
+ ResultSet resultSet = preparedStatement.executeQuery(); |
|
| 166 |
+ while (resultSet.next()) {
|
|
| 167 |
+ if(resultSet.getInt("IDDATA_PKM2") == 0)
|
|
| 168 |
+ {
|
|
| 169 |
+ ExchangeEntity entity = new ExchangeEntity(); |
|
| 170 |
+ entity.setId(resultSet.getInt("id"));
|
|
| 171 |
+ entity.setPkm1(PokemonCore.getPokemonByDataId(resultSet.getInt("idpkm1")));
|
|
| 172 |
+ entity.setUser1(UserCore.getUserById(resultSet.getInt("iduser1")));
|
|
| 173 |
+ entity.setUser2(resultSet.getInt("iduser2") != 0 ? UserCore.getUserById(resultSet.getInt("iduser2")) : null);
|
|
| 174 |
+ |
|
| 175 |
+ if(entity.getDataPkm2() ==null) |
|
| 176 |
+ entity.setIdPkm2(PokemonCore.getSimpleInstance(resultSet.getInt("idpkm2"), resultSet.getInt("lvl") ,resultSet.getBoolean("shiny")));
|
|
| 177 |
+ |
|
| 178 |
+ |
|
| 179 |
+ entities.add(entity); |
|
| 180 |
+ |
|
| 181 |
+ } |
|
| 182 |
+ } |
|
| 183 |
+ } catch (SQLException e) {
|
|
| 184 |
+ e.printStackTrace(); |
|
| 185 |
+ } |
|
| 186 |
+ |
|
| 187 |
+ |
|
| 188 |
+ return entities; |
|
| 189 |
+ } |
|
| 190 |
+ |
|
| 191 |
+ //Récupère tout les échange sortant de l'utilisateur connecté |
|
| 192 |
+ public ArrayList<ExchangeEntity> getAllMyExchangeOut(int userId) throws IOException |
|
| 193 |
+ {
|
|
| 194 |
+ ArrayList<ExchangeEntity> entities = new ArrayList<>(); |
|
| 195 |
+ try {
|
|
| 196 |
+ PreparedStatement preparedStatement = this.connect.prepareStatement("SELECT * FROM exchange where iduser1 = (?) ORDER BY id ASC;");
|
|
| 197 |
+ preparedStatement.setInt(1,userId); |
|
| 198 |
+ ResultSet resultSet = preparedStatement.executeQuery(); |
|
| 199 |
+ while (resultSet.next()) {
|
|
| 200 |
+ ExchangeEntity entity = new ExchangeEntity(); |
|
| 201 |
+ entity.setId(resultSet.getInt("id"));
|
|
| 202 |
+ entity.setPkm1(PokemonCore.getPokemonByDataId(resultSet.getInt("idpkm1")));
|
|
| 203 |
+ entity.setDataPkm2(resultSet.getInt("IDDATA_PKM2") != 0 ? PokemonCore.getPokemonByDataId(resultSet.getInt("IDDATA_PKM2")) : null);
|
|
| 204 |
+ entity.setUser1(UserCore.getUserById(resultSet.getInt("iduser1")));
|
|
| 205 |
+ entity.setUser2(resultSet.getInt("iduser2") != 0 ? UserCore.getUserById(resultSet.getInt("iduser2")) : null);
|
|
| 206 |
+ |
|
| 207 |
+ if(entity.getDataPkm2() ==null) |
|
| 208 |
+ entity.setIdPkm2(PokemonCore.getSimpleInstance(resultSet.getInt("idpkm2"), resultSet.getInt("lvl") ,resultSet.getBoolean("shiny")));
|
|
| 209 |
+ |
|
| 210 |
+ |
|
| 211 |
+ entities.add(entity); |
|
| 212 |
+ } |
|
| 213 |
+ } catch (SQLException e) {
|
|
| 214 |
+ e.printStackTrace(); |
|
| 215 |
+ } |
|
| 216 |
+ |
|
| 217 |
+ return entities; |
|
| 218 |
+ } |
|
| 219 |
+ |
|
| 220 |
+ |
|
| 221 |
+ @Override |
|
| 222 |
+ public ExchangeEntity create(ExchangeEntity exchange) |
|
| 223 |
+ {
|
|
| 224 |
+ try {
|
|
| 225 |
+ PreparedStatement preparedStatement = this.connect.prepareStatement("INSERT INTO exchange(iduser1, idpkm1, idpkm2, lvl, shiny, IDDATA_PKM2, iduser2) VALUES(?,?,?,?,?, ?,?);");
|
|
| 226 |
+ preparedStatement.setInt(1, exchange.getUser1().getLogin()); |
|
| 227 |
+ preparedStatement.setInt(2, exchange.getPkm1().getDataId()); |
|
| 228 |
+ preparedStatement.setInt(3, exchange.getIdPkm2() == null ? 0 : exchange.getIdPkm2().getDataId()); |
|
| 229 |
+ preparedStatement.setInt(4, exchange.getIdPkm2() == null ? 0 : exchange.getIdPkm2().getLvl()); |
|
| 230 |
+ preparedStatement.setBoolean(5, exchange.getIdPkm2() == null ? false : exchange.getIdPkm2().getShiny()); |
|
| 231 |
+ preparedStatement.setInt(6, exchange.getDataPkm2() == null ? 0 : exchange.getDataPkm2().getDataId()); |
|
| 232 |
+ preparedStatement.setInt(7, exchange.getUser2() == null ? 0 : exchange.getUser2().getLogin()); |
|
| 233 |
+ preparedStatement.executeUpdate(); |
|
| 234 |
+ return exchange; |
|
| 235 |
+ } catch (SQLException e) {
|
|
| 236 |
+ e.printStackTrace(); |
|
| 237 |
+ } |
|
| 238 |
+ return null; |
|
| 239 |
+ } |
|
| 240 |
+ |
|
| 241 |
+ @Override |
|
| 242 |
+ public void delete(ExchangeEntity exchange) |
|
| 243 |
+ {
|
|
| 244 |
+ try |
|
| 245 |
+ {
|
|
| 246 |
+ PreparedStatement preparedStatement = this.connect.prepareStatement("DELETE FROM exchange WHERE id = (?);");
|
|
| 247 |
+ preparedStatement.setInt(1, exchange.getId()); |
|
| 248 |
+ preparedStatement.executeUpdate(); |
|
| 249 |
+ } |
|
| 250 |
+ catch (SQLException e) |
|
| 251 |
+ {
|
|
| 252 |
+ e.printStackTrace(); |
|
| 253 |
+ } |
|
| 254 |
+ } |
|
| 255 |
+} |
|
| 0 | 256 |
\ No newline at end of file |
| ... | ... |
@@ -0,0 +1,353 @@ |
| 1 |
+package com.uca.dao; |
|
| 2 |
+ |
|
| 3 |
+import com.uca.entity.PokemonEntity; |
|
| 4 |
+import com.uca.util.JsonReader; |
|
| 5 |
+ |
|
| 6 |
+ |
|
| 7 |
+import java.sql.*; |
|
| 8 |
+import java.util.Date; |
|
| 9 |
+import java.util.ArrayList; |
|
| 10 |
+import java.util.Random; |
|
| 11 |
+import java.io.IOException; |
|
| 12 |
+ |
|
| 13 |
+import org.json.JSONException; |
|
| 14 |
+import org.json.JSONObject; |
|
| 15 |
+import org.json.JSONArray; |
|
| 16 |
+ |
|
| 17 |
+ |
|
| 18 |
+ |
|
| 19 |
+public class PokemonDAO extends _Generic<PokemonEntity>{
|
|
| 20 |
+ |
|
| 21 |
+ //Récupère les info d'un pokemon sur le pokeapi avec un id |
|
| 22 |
+ public PokemonEntity getPokemonById(int id) throws JSONException, IOException |
|
| 23 |
+ {
|
|
| 24 |
+ PokemonEntity entity = new PokemonEntity(); |
|
| 25 |
+ JsonReader jsonRd = new JsonReader(); |
|
| 26 |
+ JSONObject json = jsonRd.readJsonFromUrl("https://pokeapi.co/api/v2/pokemon/" + String.valueOf(id));
|
|
| 27 |
+ entity.setId(id); |
|
| 28 |
+ entity.setName(json.getString("name"));
|
|
| 29 |
+ entity.setDescription(getPokemonDescriptionById(id)); |
|
| 30 |
+ |
|
| 31 |
+ JSONArray type = json.getJSONArray("types");
|
|
| 32 |
+ for(int i = 0 ; i < type.length() ; i++) |
|
| 33 |
+ {
|
|
| 34 |
+ entity.setType(i, type.getJSONObject(i).getJSONObject("type").getString("name"));
|
|
| 35 |
+ } |
|
| 36 |
+ return entity; |
|
| 37 |
+ } |
|
| 38 |
+ |
|
| 39 |
+ //Verfifie si un pokemon exist sur le pokeapi |
|
| 40 |
+ public Boolean pokemonExist(String name) throws IOException, JSONException |
|
| 41 |
+ {
|
|
| 42 |
+ Boolean exist = null; |
|
| 43 |
+ JsonReader jsonRd = new JsonReader(); |
|
| 44 |
+ JSONObject json = jsonRd.readJsonFromUrl("https://pokeapi.co/api/v2/pokemon/" + name);
|
|
| 45 |
+ if(json == null) |
|
| 46 |
+ exist = false; |
|
| 47 |
+ else |
|
| 48 |
+ exist = true; |
|
| 49 |
+ return exist; |
|
| 50 |
+ } |
|
| 51 |
+ |
|
| 52 |
+ //Verfifie si un pokemon exist sur le pokeapi |
|
| 53 |
+ public Boolean pokemonExist(int id) throws IOException, JSONException |
|
| 54 |
+ {
|
|
| 55 |
+ Boolean exist = null; |
|
| 56 |
+ JsonReader jsonRd = new JsonReader(); |
|
| 57 |
+ JSONObject json = jsonRd.readJsonFromUrl("https://pokeapi.co/api/v2/pokemon/" + String.valueOf(id));
|
|
| 58 |
+ if(json == null) |
|
| 59 |
+ exist = false; |
|
| 60 |
+ else |
|
| 61 |
+ exist = true; |
|
| 62 |
+ return exist; |
|
| 63 |
+ } |
|
| 64 |
+ |
|
| 65 |
+ |
|
| 66 |
+ //Récupere le genre possible d'un pokemon sur le pokeapi puis tire au hasard et le renvoie |
|
| 67 |
+ public String getPokemonGenderById(int id) throws JSONException, IOException |
|
| 68 |
+ {
|
|
| 69 |
+ String gender = "unknown"; |
|
| 70 |
+ JsonReader jsonRd = new JsonReader(); |
|
| 71 |
+ JSONObject json = jsonRd.readJsonFromUrl("https://pokeapi.co/api/v2/pokemon-species/" + String.valueOf(id));
|
|
| 72 |
+ int genderRatio = json.getInt("gender_rate");
|
|
| 73 |
+ switch(genderRatio) |
|
| 74 |
+ {
|
|
| 75 |
+ case -1: |
|
| 76 |
+ return "genderless"; |
|
| 77 |
+ case 0: |
|
| 78 |
+ return "male"; |
|
| 79 |
+ case 1: |
|
| 80 |
+ return Math.random() < 0.125 ? "female" : "male"; |
|
| 81 |
+ case 2: |
|
| 82 |
+ return Math.random() < 0.25 ? "female" : "male"; |
|
| 83 |
+ case 6: |
|
| 84 |
+ return Math.random() < 0.75 ? "female" : "male"; |
|
| 85 |
+ case 7: |
|
| 86 |
+ return Math.random() < 0.875 ? "female" : "male"; |
|
| 87 |
+ case 8: |
|
| 88 |
+ return "female"; |
|
| 89 |
+ default: |
|
| 90 |
+ return Math.random() < 0.5 ? "female" : "male"; |
|
| 91 |
+ } |
|
| 92 |
+ } |
|
| 93 |
+ |
|
| 94 |
+ //Récupère l'id d'un pokemon avec son nom |
|
| 95 |
+ public int getPokemonIdByName(String name) throws IOException |
|
| 96 |
+ {
|
|
| 97 |
+ JsonReader jsonRd = new JsonReader(); |
|
| 98 |
+ JSONObject json = jsonRd.readJsonFromUrl("https://pokeapi.co/api/v2/pokemon/" + name);
|
|
| 99 |
+ return json.getInt("id");
|
|
| 100 |
+ } |
|
| 101 |
+ |
|
| 102 |
+ public ArrayList<PokemonEntity> getPokemonForExchange(int ownerId, PokemonEntity pkm) throws IOException |
|
| 103 |
+ {
|
|
| 104 |
+ ArrayList<PokemonEntity> entities = new ArrayList<PokemonEntity>(); |
|
| 105 |
+ try |
|
| 106 |
+ {
|
|
| 107 |
+ PokemonEntity entity; |
|
| 108 |
+ PreparedStatement preparedStatement; |
|
| 109 |
+ if(pkm.getId() != 0) |
|
| 110 |
+ {
|
|
| 111 |
+ preparedStatement = this.connect.prepareStatement("SELECT * FROM own WHERE idOwner = (?) AND idpkm = (?) AND lvl >= (?);");
|
|
| 112 |
+ preparedStatement.setInt(1, ownerId); |
|
| 113 |
+ preparedStatement.setInt(2, pkm.getId()); |
|
| 114 |
+ preparedStatement.setInt(3, pkm.getLvl()); |
|
| 115 |
+ } |
|
| 116 |
+ else |
|
| 117 |
+ {
|
|
| 118 |
+ preparedStatement = this.connect.prepareStatement("SELECT * FROM own WHERE idOwner = (?) AND lvl >= (?);");
|
|
| 119 |
+ preparedStatement.setInt(1, ownerId); |
|
| 120 |
+ preparedStatement.setInt(2, pkm.getLvl()); |
|
| 121 |
+ } |
|
| 122 |
+ ResultSet resultSet = preparedStatement.executeQuery(); |
|
| 123 |
+ while (resultSet.next()) |
|
| 124 |
+ {
|
|
| 125 |
+ if((pkm.getShiny() && resultSet.getBoolean("shiny")) || !pkm.getShiny())
|
|
| 126 |
+ {
|
|
| 127 |
+ entity = getPokemonById(resultSet.getInt("idpkm"));
|
|
| 128 |
+ entity.setDescription(getPokemonDescriptionById(resultSet.getInt("idpkm")));
|
|
| 129 |
+ entity.setShiny(resultSet.getBoolean("shiny"));
|
|
| 130 |
+ entity.setGender(resultSet.getString("gender"));
|
|
| 131 |
+ entity.setLvl(resultSet.getInt("lvl"));
|
|
| 132 |
+ entity.setGettingDate(resultSet.getDate("getting_date"));
|
|
| 133 |
+ entity.setBaseOwner(resultSet.getInt("baseowner"));
|
|
| 134 |
+ entity.setDataId(resultSet.getInt("id"));
|
|
| 135 |
+ setPokemonSprite(entity); |
|
| 136 |
+ entities.add(entity); |
|
| 137 |
+ } |
|
| 138 |
+ } |
|
| 139 |
+ } catch (SQLException e) {
|
|
| 140 |
+ e.printStackTrace(); |
|
| 141 |
+ } |
|
| 142 |
+ |
|
| 143 |
+ |
|
| 144 |
+ return entities; |
|
| 145 |
+ } |
|
| 146 |
+ |
|
| 147 |
+ //Récupère le nom d'un pokemon avec un id |
|
| 148 |
+ public String getPokemonNameById(int id) throws JSONException, IOException |
|
| 149 |
+ {
|
|
| 150 |
+ JsonReader jsonRd = new JsonReader(); |
|
| 151 |
+ |
|
| 152 |
+ JSONObject json = jsonRd.readJsonFromUrl("https://pokeapi.co/api/v2/pokemon/" + String.valueOf(id));
|
|
| 153 |
+ return json.getString("name");
|
|
| 154 |
+ } |
|
| 155 |
+ |
|
| 156 |
+ //Tire aléatoirement un pokemon |
|
| 157 |
+ public PokemonEntity getNewPokemon(int userId) throws IOException |
|
| 158 |
+ {
|
|
| 159 |
+ Random rand = new Random(); |
|
| 160 |
+ int pokeId = rand.nextInt((1008 - 1) + 1) + 1; |
|
| 161 |
+ PokemonEntity pkm = getPokemonById(pokeId); |
|
| 162 |
+ pkm.setGender(getPokemonGenderById(pokeId)); |
|
| 163 |
+ pkm.setLvl(rand.nextInt((100 - 1) + 1) + 1); |
|
| 164 |
+ pkm.setShiny(Math.random() < 0.01); |
|
| 165 |
+ setPokemonSprite(pkm); |
|
| 166 |
+ try {
|
|
| 167 |
+ PreparedStatement preparedStatement = this.connect.prepareStatement("INSERT INTO own(idowner, idpkm, gender, shiny, lvl, baseowner, getting_date) VALUES(?, ? , ?, ?, ?, ?, ?);");
|
|
| 168 |
+ java.util.Date date = new java.util.Date(); |
|
| 169 |
+ |
|
| 170 |
+ preparedStatement.setInt(1, userId); |
|
| 171 |
+ preparedStatement.setInt(2, pokeId); |
|
| 172 |
+ preparedStatement.setString(3, pkm.getGender()); |
|
| 173 |
+ preparedStatement.setBoolean(4, pkm.getShiny()); |
|
| 174 |
+ preparedStatement.setInt(5, pkm.getLvl()); |
|
| 175 |
+ preparedStatement.setInt(6, userId); |
|
| 176 |
+ preparedStatement.setDate(7, new java.sql.Date(date.getTime())); |
|
| 177 |
+ preparedStatement.executeUpdate(); |
|
| 178 |
+ } catch (SQLException e) {
|
|
| 179 |
+ e.printStackTrace(); |
|
| 180 |
+ } |
|
| 181 |
+ return pkm; |
|
| 182 |
+ } |
|
| 183 |
+ |
|
| 184 |
+ //Vérifie si un pokemon appartien bien a un utilisateur |
|
| 185 |
+ public Boolean isPokemonOwnedByUser(int userId, int pkmId) throws IOException |
|
| 186 |
+ {
|
|
| 187 |
+ Boolean exist = null; |
|
| 188 |
+ try {
|
|
| 189 |
+ |
|
| 190 |
+ PreparedStatement preparedStatement = this.connect.prepareStatement("SELECT * FROM own WHERE idOwner = ? AND id = ? ;");
|
|
| 191 |
+ preparedStatement.setInt(1, userId); |
|
| 192 |
+ preparedStatement.setInt(2, pkmId); |
|
| 193 |
+ ResultSet resultSet = preparedStatement.executeQuery(); |
|
| 194 |
+ exist = resultSet.next(); |
|
| 195 |
+ } catch (SQLException e) {
|
|
| 196 |
+ e.printStackTrace(); |
|
| 197 |
+ } |
|
| 198 |
+ return exist; |
|
| 199 |
+ } |
|
| 200 |
+ |
|
| 201 |
+ //Récupère la description d'un pokemon sur le pokeapi |
|
| 202 |
+ public String getPokemonDescriptionById(int id) throws JSONException, IOException |
|
| 203 |
+ {
|
|
| 204 |
+ JsonReader jsonRd = new JsonReader(); |
|
| 205 |
+ JSONObject json = jsonRd.readJsonFromUrl("https://pokeapi.co/api/v2/pokemon-species/" + String.valueOf(id));
|
|
| 206 |
+ String str = json.getJSONArray("flavor_text_entries").getJSONObject(0).getString("flavor_text");
|
|
| 207 |
+ return str; |
|
| 208 |
+ } |
|
| 209 |
+ |
|
| 210 |
+ //Recupere un pokemon dans notre BDD |
|
| 211 |
+ public PokemonEntity getPokemonByDataId(int id) throws IOException |
|
| 212 |
+ {
|
|
| 213 |
+ PokemonEntity pkm = null; |
|
| 214 |
+ try {
|
|
| 215 |
+ PreparedStatement preparedStatement = this.connect.prepareStatement("SELECT * from own WHERE id = (?);");
|
|
| 216 |
+ preparedStatement.setInt(1, id); |
|
| 217 |
+ ResultSet resultSet = preparedStatement.executeQuery(); |
|
| 218 |
+ if(resultSet.next()) |
|
| 219 |
+ {
|
|
| 220 |
+ pkm = getPokemonById(resultSet.getInt("idpkm"));
|
|
| 221 |
+ pkm.setGender(resultSet.getString("gender"));
|
|
| 222 |
+ pkm.setLvl(resultSet.getInt("lvl"));
|
|
| 223 |
+ pkm.setShiny(resultSet.getBoolean("shiny"));
|
|
| 224 |
+ pkm.setBaseOwner(resultSet.getInt("baseowner"));
|
|
| 225 |
+ pkm.setDataId(id); |
|
| 226 |
+ setPokemonSprite(pkm); |
|
| 227 |
+ } |
|
| 228 |
+ } catch (SQLException e) {
|
|
| 229 |
+ e.printStackTrace(); |
|
| 230 |
+ } |
|
| 231 |
+ return pkm; |
|
| 232 |
+ } |
|
| 233 |
+ |
|
| 234 |
+ //Récupère l'id de l'utilisateur ayant le pokemon donné |
|
| 235 |
+ public int getOwnerId(int pkmId) throws IOException |
|
| 236 |
+ {
|
|
| 237 |
+ try {
|
|
| 238 |
+ PreparedStatement preparedStatement = this.connect.prepareStatement("SELECT idOwner from own WHERE id = (?);");
|
|
| 239 |
+ preparedStatement.setInt(1, pkmId); |
|
| 240 |
+ ResultSet resultSet = preparedStatement.executeQuery(); |
|
| 241 |
+ if(resultSet.next()) |
|
| 242 |
+ {
|
|
| 243 |
+ return resultSet.getInt("idOwner");
|
|
| 244 |
+ } |
|
| 245 |
+ } catch (SQLException e) {
|
|
| 246 |
+ e.printStackTrace(); |
|
| 247 |
+ } |
|
| 248 |
+ return 0; |
|
| 249 |
+ } |
|
| 250 |
+ |
|
| 251 |
+ //Ajoute un niveau au pokemon ciblé |
|
| 252 |
+ public int lvlUpPokemonById(int id) |
|
| 253 |
+ {
|
|
| 254 |
+ try {
|
|
| 255 |
+ PreparedStatement preparedStatement = this.connect.prepareStatement("SELECT lvl from own WHERE id = (?);");
|
|
| 256 |
+ preparedStatement.setInt(1, id); |
|
| 257 |
+ ResultSet resultSet = preparedStatement.executeQuery(); |
|
| 258 |
+ if(resultSet.next()) |
|
| 259 |
+ {
|
|
| 260 |
+ if(resultSet.getInt("lvl") < 100)
|
|
| 261 |
+ {
|
|
| 262 |
+ preparedStatement = this.connect.prepareStatement("UPDATE own SET lvl = lvl + 1 WHERE id = (?);");
|
|
| 263 |
+ preparedStatement.setInt(1, id); |
|
| 264 |
+ preparedStatement.executeUpdate(); |
|
| 265 |
+ return 1; |
|
| 266 |
+ } |
|
| 267 |
+ else |
|
| 268 |
+ {
|
|
| 269 |
+ return 2; |
|
| 270 |
+ } |
|
| 271 |
+ } |
|
| 272 |
+ } catch (SQLException e) {
|
|
| 273 |
+ e.printStackTrace(); |
|
| 274 |
+ } |
|
| 275 |
+ |
|
| 276 |
+ return 0; |
|
| 277 |
+ } |
|
| 278 |
+ |
|
| 279 |
+ //A l'aide d'info du pokeapi, met a jour le chemin du sprite d'un pokemon |
|
| 280 |
+ public static void setPokemonSprite(PokemonEntity pkm) throws JSONException, IOException |
|
| 281 |
+ {
|
|
| 282 |
+ JsonReader jsonRd = new JsonReader(); |
|
| 283 |
+ JSONObject json = jsonRd.readJsonFromUrl("https://pokeapi.co/api/v2/pokemon/" + String.valueOf(pkm.getId()));
|
|
| 284 |
+ if(pkm.getShiny()) |
|
| 285 |
+ {
|
|
| 286 |
+ if(pkm.getGender() == "female" && json.getJSONObject("sprites").has("front_shiny_female") && !json.getJSONObject("sprites").isNull("front_shiny_female"))
|
|
| 287 |
+ {
|
|
| 288 |
+ pkm.setSprite("/pokemonSprite/shiny/female/"+String.valueOf(pkm.getId())+".png");
|
|
| 289 |
+ } |
|
| 290 |
+ else |
|
| 291 |
+ {
|
|
| 292 |
+ pkm.setSprite("/pokemonSprite/shiny/"+String.valueOf(pkm.getId())+".png");
|
|
| 293 |
+ } |
|
| 294 |
+ } |
|
| 295 |
+ else |
|
| 296 |
+ {
|
|
| 297 |
+ if(pkm.getGender() == "female" && json.getJSONObject("sprites").has("front_female") && !json.getJSONObject("sprites").isNull("front_female"))
|
|
| 298 |
+ {
|
|
| 299 |
+ pkm.setSprite("/pokemonSprite/female/"+String.valueOf(pkm.getId())+".png");
|
|
| 300 |
+ } |
|
| 301 |
+ else |
|
| 302 |
+ {
|
|
| 303 |
+ pkm.setSprite("/pokemonSprite/"+String.valueOf(pkm.getId())+".png");
|
|
| 304 |
+ } |
|
| 305 |
+ } |
|
| 306 |
+ } |
|
| 307 |
+ |
|
| 308 |
+ //Renvoie tout les pokemon d'un utilisateur |
|
| 309 |
+ public ArrayList<PokemonEntity> getPokemonByUser(int id) throws JSONException, IOException |
|
| 310 |
+ {
|
|
| 311 |
+ ArrayList<PokemonEntity> entities = new ArrayList<PokemonEntity>(); |
|
| 312 |
+ try |
|
| 313 |
+ {
|
|
| 314 |
+ PokemonEntity entity; |
|
| 315 |
+ PreparedStatement preparedStatement = this.connect.prepareStatement("SELECT * FROM own WHERE idOwner = (?);");
|
|
| 316 |
+ preparedStatement.setString(1, String.valueOf(id)); |
|
| 317 |
+ ResultSet resultSet = preparedStatement.executeQuery(); |
|
| 318 |
+ while (resultSet.next()) |
|
| 319 |
+ {
|
|
| 320 |
+ entity = getPokemonById(resultSet.getInt("idpkm"));
|
|
| 321 |
+ entity.setDescription(getPokemonDescriptionById(resultSet.getInt("idpkm")));
|
|
| 322 |
+ entity.setShiny(resultSet.getBoolean("shiny"));
|
|
| 323 |
+ entity.setGender(resultSet.getString("gender"));
|
|
| 324 |
+ entity.setLvl(resultSet.getInt("lvl"));
|
|
| 325 |
+ entity.setGettingDate(resultSet.getDate("getting_date"));
|
|
| 326 |
+ entity.setBaseOwner(resultSet.getInt("baseowner"));
|
|
| 327 |
+ entity.setDataId(resultSet.getInt("id"));
|
|
| 328 |
+ setPokemonSprite(entity); |
|
| 329 |
+ entities.add(entity); |
|
| 330 |
+ } |
|
| 331 |
+ } catch (SQLException e) {
|
|
| 332 |
+ e.printStackTrace(); |
|
| 333 |
+ } |
|
| 334 |
+ return entities; |
|
| 335 |
+ } |
|
| 336 |
+ |
|
| 337 |
+ |
|
| 338 |
+ |
|
| 339 |
+ //Crée un pokemon, non implémenté |
|
| 340 |
+ @Override |
|
| 341 |
+ public PokemonEntity create(PokemonEntity pkm) |
|
| 342 |
+ {
|
|
| 343 |
+ //TODO ! |
|
| 344 |
+ return null; |
|
| 345 |
+ } |
|
| 346 |
+ |
|
| 347 |
+ //Supprime un pokemon, non implémenté |
|
| 348 |
+ @Override |
|
| 349 |
+ public void delete(PokemonEntity pkm) |
|
| 350 |
+ {
|
|
| 351 |
+ //TODO ! |
|
| 352 |
+ } |
|
| 353 |
+} |
| ... | ... |
@@ -0,0 +1,334 @@ |
| 1 |
+package com.uca.dao; |
|
| 2 |
+ |
|
| 3 |
+import com.uca.entity.UserEntity; |
|
| 4 |
+import com.uca.entity.UserInfosEntity; |
|
| 5 |
+import org.mindrot.jbcrypt.BCrypt; |
|
| 6 |
+ |
|
| 7 |
+import java.sql.*; |
|
| 8 |
+import java.util.ArrayList; |
|
| 9 |
+import java.util.Date; |
|
| 10 |
+import java.util.Calendar; |
|
| 11 |
+ |
|
| 12 |
+ |
|
| 13 |
+public class UserDAO extends _Generic<UserEntity> {
|
|
| 14 |
+ |
|
| 15 |
+ //Renvoie tous les utilisateur (non utilisé) |
|
| 16 |
+ public ArrayList<UserEntity> getAllUsers() {
|
|
| 17 |
+ ArrayList<UserEntity> entities = new ArrayList<>(); |
|
| 18 |
+ try {
|
|
| 19 |
+ PreparedStatement preparedStatement = this.connect.prepareStatement("SELECT * FROM users ORDER BY login ASC;");
|
|
| 20 |
+ ResultSet resultSet = preparedStatement.executeQuery(); |
|
| 21 |
+ while (resultSet.next()) {
|
|
| 22 |
+ UserEntity entity = new UserEntity(); |
|
| 23 |
+ entity.setLogin(resultSet.getInt("login"));
|
|
| 24 |
+ entity.setPseudo(resultSet.getString("pseudo"));
|
|
| 25 |
+ entity.setEmail(resultSet.getString("email"));
|
|
| 26 |
+ entity.setHashpswd(resultSet.getString("hashpswd"));
|
|
| 27 |
+ java.sql.Date sqlDate = resultSet.getDate("last_date_co");
|
|
| 28 |
+ if(sqlDate != null) |
|
| 29 |
+ {
|
|
| 30 |
+ java.util.Date utilDate = new java.util.Date(sqlDate.getTime()); |
|
| 31 |
+ entity.setLastCoDate(utilDate); |
|
| 32 |
+ } |
|
| 33 |
+ |
|
| 34 |
+ entities.add(entity); |
|
| 35 |
+ } |
|
| 36 |
+ } catch (SQLException e) {
|
|
| 37 |
+ e.printStackTrace(); |
|
| 38 |
+ } |
|
| 39 |
+ |
|
| 40 |
+ return entities; |
|
| 41 |
+ } |
|
| 42 |
+ |
|
| 43 |
+ //Renvoie un untilisateur avec le login donné |
|
| 44 |
+ public UserEntity getUserById(int id) |
|
| 45 |
+ {
|
|
| 46 |
+ UserEntity entity = new UserEntity(); |
|
| 47 |
+ try {
|
|
| 48 |
+ PreparedStatement preparedStatement = this.connect.prepareStatement("SELECT * FROM users WHERE login = (?);");
|
|
| 49 |
+ preparedStatement.setString(1, String.valueOf(id)); |
|
| 50 |
+ ResultSet resultSet = preparedStatement.executeQuery(); |
|
| 51 |
+ while (resultSet.next()) {
|
|
| 52 |
+ entity.setLogin(resultSet.getInt("login"));
|
|
| 53 |
+ entity.setPseudo(resultSet.getString("pseudo"));
|
|
| 54 |
+ entity.setEmail(resultSet.getString("email"));
|
|
| 55 |
+ entity.setHashpswd(resultSet.getString("hashpswd"));
|
|
| 56 |
+ java.sql.Date sqlDate = resultSet.getDate("last_date_co");
|
|
| 57 |
+ if(sqlDate != null) |
|
| 58 |
+ {
|
|
| 59 |
+ java.util.Date utilDate = new java.util.Date(sqlDate.getTime()); |
|
| 60 |
+ entity.setLastCoDate(utilDate); |
|
| 61 |
+ } |
|
| 62 |
+ |
|
| 63 |
+ } |
|
| 64 |
+ } catch (SQLException e) {
|
|
| 65 |
+ e.printStackTrace(); |
|
| 66 |
+ } |
|
| 67 |
+ return entity; |
|
| 68 |
+ } |
|
| 69 |
+ |
|
| 70 |
+ //Renvoie un l'utilisateur avec le mail donné |
|
| 71 |
+ public Integer getUserIdByMail(String mail) |
|
| 72 |
+ {
|
|
| 73 |
+ if(!userEmailExist(mail)) |
|
| 74 |
+ {
|
|
| 75 |
+ return null; |
|
| 76 |
+ } |
|
| 77 |
+ try {
|
|
| 78 |
+ PreparedStatement preparedStatement = this.connect.prepareStatement("SELECT login FROM users WHERE email = (?);");
|
|
| 79 |
+ preparedStatement.setString(1, mail); |
|
| 80 |
+ ResultSet resultSet = preparedStatement.executeQuery(); |
|
| 81 |
+ if(resultSet.next()) |
|
| 82 |
+ {
|
|
| 83 |
+ return resultSet.getInt("login");
|
|
| 84 |
+ } |
|
| 85 |
+ } catch (SQLException e) {
|
|
| 86 |
+ e.printStackTrace(); |
|
| 87 |
+ } |
|
| 88 |
+ return null; |
|
| 89 |
+ } |
|
| 90 |
+ |
|
| 91 |
+ //Vérifie si le mot de passe associé au mail est valide |
|
| 92 |
+ private Boolean pswdCheck(String pswd, String mail) |
|
| 93 |
+ {
|
|
| 94 |
+ int id = getUserIdByMail(mail); |
|
| 95 |
+ Boolean exist = null; |
|
| 96 |
+ try {
|
|
| 97 |
+ //Récupere le salt et le hash |
|
| 98 |
+ PreparedStatement preparedStatement = this.connect.prepareStatement("SELECT salt,hashpswd FROM users WHERE login = (?) ;");
|
|
| 99 |
+ preparedStatement.setInt(1, id); |
|
| 100 |
+ ResultSet resultSet = preparedStatement.executeQuery(); |
|
| 101 |
+ if(resultSet.next()) |
|
| 102 |
+ {
|
|
| 103 |
+ //Utilise le salt pour hasher le mdp donné et compare au mdp de la BDD |
|
| 104 |
+ String hashedPassword = BCrypt.hashpw(pswd, resultSet.getString("salt"));
|
|
| 105 |
+ exist = hashedPassword.equals(resultSet.getString("hashpswd"));
|
|
| 106 |
+ } |
|
| 107 |
+ } catch (SQLException e) {
|
|
| 108 |
+ e.printStackTrace(); |
|
| 109 |
+ } |
|
| 110 |
+ return exist; |
|
| 111 |
+ } |
|
| 112 |
+ |
|
| 113 |
+ //Détecte si c'est la première connexion journaliere du l'utilisateur |
|
| 114 |
+ private Boolean firstCo(int id) |
|
| 115 |
+ {
|
|
| 116 |
+ Boolean result = null; |
|
| 117 |
+ try {
|
|
| 118 |
+ PreparedStatement preparedStatement = this.connect.prepareStatement("SELECT * FROM users WHERE login = (?);");
|
|
| 119 |
+ preparedStatement.setString(1, String.valueOf(id)); |
|
| 120 |
+ ResultSet resultSet = preparedStatement.executeQuery(); |
|
| 121 |
+ if(resultSet.next()) |
|
| 122 |
+ {
|
|
| 123 |
+ java.sql.Date sqlDate = resultSet.getDate("last_date_co");
|
|
| 124 |
+ java.util.Date lastCoDate = sqlDate == null ? new java.util.Date(0) : new java.util.Date(sqlDate.getTime()); |
|
| 125 |
+ |
|
| 126 |
+ Calendar lastCoCal = Calendar.getInstance(); |
|
| 127 |
+ lastCoCal.setTime(lastCoDate); |
|
| 128 |
+ |
|
| 129 |
+ Calendar actualDateCal = Calendar.getInstance(); |
|
| 130 |
+ |
|
| 131 |
+ if (lastCoCal.get(Calendar.DAY_OF_YEAR) != actualDateCal.get(Calendar.DAY_OF_YEAR)) {
|
|
| 132 |
+ result = true; |
|
| 133 |
+ } else {
|
|
| 134 |
+ result = false; |
|
| 135 |
+ } |
|
| 136 |
+ preparedStatement = this.connect.prepareStatement("UPDATE USERS SET LAST_DATE_CO = (?) WHERE LOGIN = (?);");
|
|
| 137 |
+ java.util.Date date = new java.util.Date(); |
|
| 138 |
+ |
|
| 139 |
+ preparedStatement.setDate(1, new java.sql.Date(date.getTime())); |
|
| 140 |
+ preparedStatement.setInt(2, id); |
|
| 141 |
+ |
|
| 142 |
+ preparedStatement.executeUpdate(); |
|
| 143 |
+ } |
|
| 144 |
+ } catch (SQLException e) {
|
|
| 145 |
+ e.printStackTrace(); |
|
| 146 |
+ } |
|
| 147 |
+ return result; |
|
| 148 |
+ } |
|
| 149 |
+ |
|
| 150 |
+ //Vérifie si le mail est déja enregistré dans la BDD |
|
| 151 |
+ public Boolean userEmailExist(String mail) |
|
| 152 |
+ {
|
|
| 153 |
+ |
|
| 154 |
+ Boolean exist = null; |
|
| 155 |
+ try {
|
|
| 156 |
+ |
|
| 157 |
+ PreparedStatement preparedStatement = this.connect.prepareStatement("SELECT * FROM users WHERE email = ? ;");
|
|
| 158 |
+ preparedStatement.setString(1, mail); |
|
| 159 |
+ ResultSet resultSet = preparedStatement.executeQuery(); |
|
| 160 |
+ exist = resultSet.next(); |
|
| 161 |
+ } catch (SQLException e) {
|
|
| 162 |
+ e.printStackTrace(); |
|
| 163 |
+ } |
|
| 164 |
+ return exist; |
|
| 165 |
+ } |
|
| 166 |
+ |
|
| 167 |
+ //Calcule et renvoie des infos pour le profil de l'utilisateur |
|
| 168 |
+ public UserInfosEntity getUserInfo(int id) |
|
| 169 |
+ {
|
|
| 170 |
+ UserInfosEntity userInfo = new UserInfosEntity(); |
|
| 171 |
+ try {
|
|
| 172 |
+ PreparedStatement preparedStatement = this.connect.prepareStatement("SELECT count(*) as count FROM own WHERE idowner = ? ;");
|
|
| 173 |
+ preparedStatement.setInt(1, id); |
|
| 174 |
+ ResultSet resultSet = preparedStatement.executeQuery(); |
|
| 175 |
+ if(resultSet.next()) |
|
| 176 |
+ userInfo.setPkm(resultSet.getInt("count"));
|
|
| 177 |
+ preparedStatement = this.connect.prepareStatement("SELECT count(distinct idpkm) as count FROM own WHERE idowner = ? ;");
|
|
| 178 |
+ preparedStatement.setInt(1, id); |
|
| 179 |
+ resultSet = preparedStatement.executeQuery(); |
|
| 180 |
+ if(resultSet.next()) |
|
| 181 |
+ userInfo.setDistinctPkm(resultSet.getInt("count"));
|
|
| 182 |
+ preparedStatement = this.connect.prepareStatement("SELECT count(*) as count FROM own WHERE idowner = ? AND shiny = true;");
|
|
| 183 |
+ preparedStatement.setInt(1, id); |
|
| 184 |
+ resultSet = preparedStatement.executeQuery(); |
|
| 185 |
+ if(resultSet.next()) |
|
| 186 |
+ userInfo.setShiny(resultSet.getInt("count"));
|
|
| 187 |
+ } catch (SQLException e) {
|
|
| 188 |
+ e.printStackTrace(); |
|
| 189 |
+ } |
|
| 190 |
+ return userInfo; |
|
| 191 |
+ } |
|
| 192 |
+ |
|
| 193 |
+ //Vérifie |
|
| 194 |
+ public int login(String pswd, String email) |
|
| 195 |
+ {
|
|
| 196 |
+ if(!userEmailExist(email)) |
|
| 197 |
+ {
|
|
| 198 |
+ return 3; |
|
| 199 |
+ } |
|
| 200 |
+ int result = 0; |
|
| 201 |
+ Boolean bool = pswdCheck(pswd, email); |
|
| 202 |
+ if(bool) |
|
| 203 |
+ result = 1; |
|
| 204 |
+ else if(!bool) |
|
| 205 |
+ result = 3; |
|
| 206 |
+ else |
|
| 207 |
+ result = 0; |
|
| 208 |
+ if(result == 1) |
|
| 209 |
+ {
|
|
| 210 |
+ if(firstCo(getUserIdByMail(email))) |
|
| 211 |
+ {
|
|
| 212 |
+ return 2; |
|
| 213 |
+ } |
|
| 214 |
+ else |
|
| 215 |
+ return 1; |
|
| 216 |
+ |
|
| 217 |
+ } |
|
| 218 |
+ return result; |
|
| 219 |
+ } |
|
| 220 |
+ |
|
| 221 |
+ //Vérifie s'il reste des lvlup a l'utilisateur |
|
| 222 |
+ public Boolean lvlup(int id) |
|
| 223 |
+ {
|
|
| 224 |
+ Boolean possible = null; |
|
| 225 |
+ try {
|
|
| 226 |
+ PreparedStatement preparedStatement = this.connect.prepareStatement("SELECT lvlup FROM users WHERE login = (?) ;");
|
|
| 227 |
+ preparedStatement.setInt(1, id); |
|
| 228 |
+ ResultSet resultSet = preparedStatement.executeQuery(); |
|
| 229 |
+ if(resultSet.next()) |
|
| 230 |
+ {
|
|
| 231 |
+ possible = resultSet.getInt("lvlup") > 0 ? true : false;
|
|
| 232 |
+ if(possible) |
|
| 233 |
+ {
|
|
| 234 |
+ preparedStatement = this.connect.prepareStatement("UPDATE USERS SET lvlup = (?) WHERE LOGIN = (?);");
|
|
| 235 |
+ |
|
| 236 |
+ preparedStatement.setInt(1, resultSet.getInt("lvlup") - 1);
|
|
| 237 |
+ preparedStatement.setInt(2, id); |
|
| 238 |
+ |
|
| 239 |
+ preparedStatement.executeUpdate(); |
|
| 240 |
+ } |
|
| 241 |
+ } |
|
| 242 |
+ } catch (SQLException e) {
|
|
| 243 |
+ e.printStackTrace(); |
|
| 244 |
+ } |
|
| 245 |
+ return possible; |
|
| 246 |
+ } |
|
| 247 |
+ |
|
| 248 |
+ //Renvoie tous les utlisateur ayant pour login ou psedo la String donné |
|
| 249 |
+ public ArrayList<UserEntity> userSearch(String search) |
|
| 250 |
+ {
|
|
| 251 |
+ ArrayList<UserEntity> entities = new ArrayList<>(); |
|
| 252 |
+ try {
|
|
| 253 |
+ PreparedStatement preparedStatement = this.connect.prepareStatement("SELECT * FROM users WHERE pseudo = (?) OR login = (?) ORDER BY login ASC;");
|
|
| 254 |
+ preparedStatement.setString(1,search); |
|
| 255 |
+ preparedStatement.setInt(2,Integer.parseInt(search)); |
|
| 256 |
+ ResultSet resultSet = preparedStatement.executeQuery(); |
|
| 257 |
+ while (resultSet.next()) {
|
|
| 258 |
+ UserEntity entity = new UserEntity(); |
|
| 259 |
+ entity.setLogin(resultSet.getInt("login"));
|
|
| 260 |
+ entity.setPseudo(resultSet.getString("pseudo"));
|
|
| 261 |
+ entity.setEmail(resultSet.getString("email"));
|
|
| 262 |
+ entity.setHashpswd(resultSet.getString("hashpswd"));
|
|
| 263 |
+ java.sql.Date sqlDate = resultSet.getDate("last_date_co");
|
|
| 264 |
+ if(sqlDate != null) |
|
| 265 |
+ {
|
|
| 266 |
+ java.util.Date utilDate = new java.util.Date(sqlDate.getTime()); |
|
| 267 |
+ entity.setLastCoDate(utilDate); |
|
| 268 |
+ } |
|
| 269 |
+ |
|
| 270 |
+ entities.add(entity); |
|
| 271 |
+ } |
|
| 272 |
+ } catch (SQLException e) {
|
|
| 273 |
+ e.printStackTrace(); |
|
| 274 |
+ } |
|
| 275 |
+ |
|
| 276 |
+ return entities; |
|
| 277 |
+ } |
|
| 278 |
+ |
|
| 279 |
+ //Vérifie si un utilisateur existe |
|
| 280 |
+ public Boolean userExist(int id) |
|
| 281 |
+ {
|
|
| 282 |
+ Boolean exist = null; |
|
| 283 |
+ try {
|
|
| 284 |
+ |
|
| 285 |
+ PreparedStatement preparedStatement = this.connect.prepareStatement("SELECT * FROM users WHERE login = ? ;");
|
|
| 286 |
+ preparedStatement.setInt(1, id); |
|
| 287 |
+ ResultSet resultSet = preparedStatement.executeQuery(); |
|
| 288 |
+ exist = resultSet.next(); |
|
| 289 |
+ } catch (SQLException e) {
|
|
| 290 |
+ e.printStackTrace(); |
|
| 291 |
+ } |
|
| 292 |
+ return exist; |
|
| 293 |
+ } |
|
| 294 |
+ |
|
| 295 |
+ //Met a jour les lvlup de tout les utilisateur a 5 |
|
| 296 |
+ public void updateLvlUp() |
|
| 297 |
+ {
|
|
| 298 |
+ try {
|
|
| 299 |
+ PreparedStatement preparedStatement = this.connect.prepareStatement("UPDATE USERS SET lvlup = 5;");
|
|
| 300 |
+ preparedStatement.executeUpdate(); |
|
| 301 |
+ |
|
| 302 |
+ } catch (SQLException e) {
|
|
| 303 |
+ e.printStackTrace(); |
|
| 304 |
+ } |
|
| 305 |
+ } |
|
| 306 |
+ |
|
| 307 |
+ //Crée un utilisateur |
|
| 308 |
+ @Override |
|
| 309 |
+ public UserEntity create(UserEntity user) {
|
|
| 310 |
+ try {
|
|
| 311 |
+ PreparedStatement preparedStatement = this.connect.prepareStatement("INSERT INTO users(pseudo, email, salt, hashpswd, last_date_co, lvlup) VALUES(?,?,?,?,?,?);");
|
|
| 312 |
+ preparedStatement.setString(1, user.getPseudo()); |
|
| 313 |
+ preparedStatement.setString(2, user.getEmail()); |
|
| 314 |
+ String salt = BCrypt.gensalt(); |
|
| 315 |
+ preparedStatement.setString(3, salt); |
|
| 316 |
+ String hashedPassword = BCrypt.hashpw(user.getHashpswd(), salt); |
|
| 317 |
+ user.setHashpswd(hashedPassword); |
|
| 318 |
+ preparedStatement.setString(4, hashedPassword); |
|
| 319 |
+ preparedStatement.setDate(5, null); |
|
| 320 |
+ preparedStatement.setInt(6, 5); |
|
| 321 |
+ preparedStatement.executeUpdate(); |
|
| 322 |
+ return user; |
|
| 323 |
+ } catch (SQLException e) {
|
|
| 324 |
+ e.printStackTrace(); |
|
| 325 |
+ } |
|
| 326 |
+ return null; |
|
| 327 |
+ } |
|
| 328 |
+ |
|
| 329 |
+ //Supprime un utilisateur, non implémenté |
|
| 330 |
+ @Override |
|
| 331 |
+ public void delete(UserEntity obj) {
|
|
| 332 |
+ //TODO ! |
|
| 333 |
+ } |
|
| 334 |
+} |
| ... | ... |
@@ -0,0 +1,29 @@ |
| 1 |
+package com.uca.dao; |
|
| 2 |
+ |
|
| 3 |
+import java.sql.Connection; |
|
| 4 |
+import java.sql.DriverManager; |
|
| 5 |
+import java.sql.SQLException; |
|
| 6 |
+ |
|
| 7 |
+public class _Connector {
|
|
| 8 |
+ |
|
| 9 |
+ private static String url = "jdbc:h2:./test"; |
|
| 10 |
+ |
|
| 11 |
+ private static String user = "sa"; |
|
| 12 |
+ |
|
| 13 |
+ private static String passwd = ""; |
|
| 14 |
+ |
|
| 15 |
+ private static Connection connect; |
|
| 16 |
+ |
|
| 17 |
+ public static Connection getInstance(){
|
|
| 18 |
+ if(connect == null){
|
|
| 19 |
+ try {
|
|
| 20 |
+ connect = DriverManager.getConnection(url, user, passwd); |
|
| 21 |
+ } catch (SQLException e) {
|
|
| 22 |
+ e.printStackTrace(); |
|
| 23 |
+ } |
|
| 24 |
+ } |
|
| 25 |
+ return connect; |
|
| 26 |
+ } |
|
| 27 |
+ |
|
| 28 |
+ |
|
| 29 |
+} |
| ... | ... |
@@ -0,0 +1,22 @@ |
| 1 |
+package com.uca.dao; |
|
| 2 |
+ |
|
| 3 |
+import java.sql.Connection; |
|
| 4 |
+ |
|
| 5 |
+public abstract class _Generic<T> {
|
|
| 6 |
+ |
|
| 7 |
+ public Connection connect = _Connector.getInstance(); |
|
| 8 |
+ |
|
| 9 |
+ /** |
|
| 10 |
+ * Permet de créer une entrée dans la base de données |
|
| 11 |
+ * par rapport à un objet |
|
| 12 |
+ * @param obj |
|
| 13 |
+ */ |
|
| 14 |
+ public abstract T create(T obj); |
|
| 15 |
+ |
|
| 16 |
+ /** |
|
| 17 |
+ * Permet la suppression d'une entrée de la base |
|
| 18 |
+ * @param obj |
|
| 19 |
+ */ |
|
| 20 |
+ public abstract void delete(T obj); |
|
| 21 |
+ |
|
| 22 |
+} |
| ... | ... |
@@ -0,0 +1,118 @@ |
| 1 |
+package com.uca.dao; |
|
| 2 |
+ |
|
| 3 |
+import java.sql.*; |
|
| 4 |
+import java.util.Date; |
|
| 5 |
+import com.uca.util.Scheduler; |
|
| 6 |
+ |
|
| 7 |
+import com.uca.core.UserCore; |
|
| 8 |
+ |
|
| 9 |
+public class _Initializer {
|
|
| 10 |
+ |
|
| 11 |
+ public static void Init(){
|
|
| 12 |
+ Connection connection = _Connector.getInstance(); |
|
| 13 |
+ |
|
| 14 |
+ try {
|
|
| 15 |
+ PreparedStatement statement; |
|
| 16 |
+ //Init articles table |
|
| 17 |
+ statement = connection.prepareStatement("CREATE TABLE IF NOT EXISTS users (login int primary key auto_increment, pseudo varchar(100), email varchar(100), salt varchar(50), hashpswd varchar(100), avatarURL varchar(100), last_date_co date, lvlup int); ");
|
|
| 18 |
+ statement.executeUpdate(); |
|
| 19 |
+ statement = connection.prepareStatement("CREATE TABLE IF NOT EXISTS OWN (ID INT PRIMARY KEY AUTO_INCREMENT, IDOWNER INT, IDPKM INT, GENDER VARCHAR(20), SHINY Boolean, LVL INT, BASEOWNER INT, GETTING_DATE DATE, CONSTRAINT FK_IDOWNER FOREIGN KEY (IDOWNER) REFERENCES USERS(LOGIN), CONSTRAINT FK_BASEOWNER FOREIGN KEY (BASEOWNER) REFERENCES USERS(LOGIN)); ");
|
|
| 20 |
+ statement.executeUpdate(); |
|
| 21 |
+ statement = connection.prepareStatement("CREATE TABLE IF NOT EXISTS exchange (ID INT PRIMARY KEY AUTO_INCREMENT, IDPKM1 INT, IDPKM2 INT, IDDATA_PKM2 INT, SHINY Boolean, LVL INT, iduser1 int, iduser2 int,CONSTRAINT FK_USER1 FOREIGN KEY (iduser1) REFERENCES users(login));");
|
|
| 22 |
+ statement.executeUpdate(); |
|
| 23 |
+ |
|
| 24 |
+ //Initialise BDD avec valeur test |
|
| 25 |
+ UserCore.createUser("foo", "pswd1","foomail");
|
|
| 26 |
+ |
|
| 27 |
+ UserCore.createUser("toto", "pswd1", "totomail");
|
|
| 28 |
+ |
|
| 29 |
+ UserCore.createUser("titi", "pswd1", "titimail");
|
|
| 30 |
+ |
|
| 31 |
+ statement = connection.prepareStatement("INSERT INTO own(idowner, idpkm, gender, shiny, lvl, baseowner, getting_date) VALUES(?, ? , ?, ?, ?, ?, ?);");
|
|
| 32 |
+ statement.setInt(1, 1); |
|
| 33 |
+ statement.setInt(2, 431); |
|
| 34 |
+ statement.setString(3, "female"); |
|
| 35 |
+ statement.setBoolean(4, true); |
|
| 36 |
+ statement.setInt(5, 23); |
|
| 37 |
+ statement.setInt(6, 1); |
|
| 38 |
+ statement.setDate(7, java.sql.Date.valueOf("2022-11-11"));
|
|
| 39 |
+ statement.executeUpdate(); |
|
| 40 |
+ |
|
| 41 |
+ statement = connection.prepareStatement("INSERT INTO own(idowner, idpkm, gender, shiny, lvl, baseowner, getting_date) VALUES(?, ? , ?, ?, ?, ?, ?);");
|
|
| 42 |
+ statement.setInt(1, 1); |
|
| 43 |
+ statement.setInt(2, 20); |
|
| 44 |
+ statement.setString(3, "male"); |
|
| 45 |
+ statement.setBoolean(4, false); |
|
| 46 |
+ statement.setInt(5, 10); |
|
| 47 |
+ statement.setInt(6, 1); |
|
| 48 |
+ statement.setDate(7, java.sql.Date.valueOf("2022-11-10"));
|
|
| 49 |
+ statement.executeUpdate(); |
|
| 50 |
+ |
|
| 51 |
+ statement = connection.prepareStatement("INSERT INTO own(idowner, idpkm, gender, shiny, lvl, baseowner, getting_date) VALUES(?, ? , ?, ?, ?, ?, ?);");
|
|
| 52 |
+ statement.setInt(1, 2); |
|
| 53 |
+ statement.setInt(2, 719); |
|
| 54 |
+ statement.setString(3, "genderless"); |
|
| 55 |
+ statement.setBoolean(4, false); |
|
| 56 |
+ statement.setInt(5, 13); |
|
| 57 |
+ statement.setInt(6, 2); |
|
| 58 |
+ statement.setDate(7, java.sql.Date.valueOf("2022-09-08"));
|
|
| 59 |
+ statement.executeUpdate(); |
|
| 60 |
+ |
|
| 61 |
+ statement = connection.prepareStatement("INSERT INTO own(idowner, idpkm, gender, shiny, lvl, baseowner, getting_date) VALUES(?, ? , ?, ?, ?, ?, ?);");
|
|
| 62 |
+ statement.setInt(1, 2); |
|
| 63 |
+ statement.setInt(2, 745); |
|
| 64 |
+ statement.setString(3, "female"); |
|
| 65 |
+ statement.setBoolean(4, false); |
|
| 66 |
+ statement.setInt(5, 32); |
|
| 67 |
+ statement.setInt(6, 3); |
|
| 68 |
+ statement.setDate(7, java.sql.Date.valueOf("2022-09-08"));
|
|
| 69 |
+ statement.executeUpdate(); |
|
| 70 |
+ |
|
| 71 |
+ statement = connection.prepareStatement("INSERT INTO own(idowner, idpkm, gender, shiny, lvl, baseowner, getting_date) VALUES(?, ? , ?, ?, ?, ?, ?);");
|
|
| 72 |
+ statement.setInt(1, 3); |
|
| 73 |
+ statement.setInt(2, 14); |
|
| 74 |
+ statement.setString(3, "male"); |
|
| 75 |
+ statement.setBoolean(4, false); |
|
| 76 |
+ statement.setInt(5, 85); |
|
| 77 |
+ statement.setInt(6, 2); |
|
| 78 |
+ statement.setDate(7, java.sql.Date.valueOf("2022-09-08"));
|
|
| 79 |
+ statement.executeUpdate(); |
|
| 80 |
+ |
|
| 81 |
+ statement = connection.prepareStatement("INSERT INTO own(idowner, idpkm, gender, shiny, lvl, baseowner, getting_date) VALUES(?, ? , ?, ?, ?, ?, ?);");
|
|
| 82 |
+ statement.setInt(1, 3); |
|
| 83 |
+ statement.setInt(2, 1); |
|
| 84 |
+ statement.setString(3, "male"); |
|
| 85 |
+ statement.setBoolean(4, true); |
|
| 86 |
+ statement.setInt(5, 28); |
|
| 87 |
+ statement.setInt(6, 3); |
|
| 88 |
+ statement.setDate(7, java.sql.Date.valueOf("2023-01-01"));
|
|
| 89 |
+ statement.executeUpdate(); |
|
| 90 |
+ |
|
| 91 |
+ statement = connection.prepareStatement("INSERT INTO exchange(idpkm1, iduser1) VALUES(?, ?);");
|
|
| 92 |
+ statement.setInt(1, 1); |
|
| 93 |
+ statement.setInt(2, 1); |
|
| 94 |
+ statement.executeUpdate(); |
|
| 95 |
+ |
|
| 96 |
+ statement = connection.prepareStatement("INSERT INTO exchange(idpkm1, iduser1, IDDATA_PKM2, iduser2) VALUES(?, ?, ? , ?);");
|
|
| 97 |
+ statement.setInt(1, 1); |
|
| 98 |
+ statement.setInt(2, 1); |
|
| 99 |
+ statement.setInt(3, 4); |
|
| 100 |
+ statement.setInt(4, 2); |
|
| 101 |
+ statement.executeUpdate(); |
|
| 102 |
+ |
|
| 103 |
+ statement = connection.prepareStatement("INSERT INTO exchange(idpkm1, iduser1, shiny) VALUES(?, ?,?);");
|
|
| 104 |
+ statement.setInt(1, 3); |
|
| 105 |
+ statement.setInt(2, 2); |
|
| 106 |
+ statement.setBoolean(3, true); |
|
| 107 |
+ statement.executeUpdate(); |
|
| 108 |
+ |
|
| 109 |
+ } catch (Exception e){
|
|
| 110 |
+ e.printStackTrace(); |
|
| 111 |
+ throw new RuntimeException("could not create database !");
|
|
| 112 |
+ } |
|
| 113 |
+ |
|
| 114 |
+ //Lance timer qui met a jour les 5 lvl up des joueurs toute les 24h |
|
| 115 |
+ Scheduler schedul = new Scheduler(); |
|
| 116 |
+ schedul.start(); |
|
| 117 |
+ } |
|
| 118 |
+} |
| ... | ... |
@@ -0,0 +1,86 @@ |
| 1 |
+package com.uca.entity; |
|
| 2 |
+ |
|
| 3 |
+public class ExchangeEntity {
|
|
| 4 |
+ private int id; |
|
| 5 |
+ private UserEntity user1; |
|
| 6 |
+ //Id dans la table own |
|
| 7 |
+ private PokemonEntity pkm1; |
|
| 8 |
+ private UserEntity user2; |
|
| 9 |
+ private PokemonEntity idPkm2; |
|
| 10 |
+ //Id dans la table own |
|
| 11 |
+ private PokemonEntity dataPkm2; |
|
| 12 |
+ |
|
| 13 |
+ |
|
| 14 |
+ public ExchangeEntity() {
|
|
| 15 |
+ // |
|
| 16 |
+ } |
|
| 17 |
+ |
|
| 18 |
+ public int getId() {
|
|
| 19 |
+ return this.id; |
|
| 20 |
+ } |
|
| 21 |
+ |
|
| 22 |
+ public void setId(int id) {
|
|
| 23 |
+ this.id = id; |
|
| 24 |
+ } |
|
| 25 |
+ |
|
| 26 |
+ public PokemonEntity getPkm1() {
|
|
| 27 |
+ return this.pkm1; |
|
| 28 |
+ } |
|
| 29 |
+ |
|
| 30 |
+ public void setPkm1(PokemonEntity pkm1) {
|
|
| 31 |
+ this.pkm1 = pkm1; |
|
| 32 |
+ } |
|
| 33 |
+ |
|
| 34 |
+ public PokemonEntity getDataPkm2() {
|
|
| 35 |
+ return this.dataPkm2; |
|
| 36 |
+ } |
|
| 37 |
+ |
|
| 38 |
+ public void setDataPkm2(PokemonEntity dataPkm2) {
|
|
| 39 |
+ this.dataPkm2 = dataPkm2; |
|
| 40 |
+ } |
|
| 41 |
+ |
|
| 42 |
+ public PokemonEntity getIdPkm2() {
|
|
| 43 |
+ return this.idPkm2; |
|
| 44 |
+ } |
|
| 45 |
+ |
|
| 46 |
+ public void setIdPkm2(PokemonEntity idPkm2) {
|
|
| 47 |
+ this.idPkm2 = idPkm2; |
|
| 48 |
+ } |
|
| 49 |
+ |
|
| 50 |
+ public UserEntity getUser1() |
|
| 51 |
+ {
|
|
| 52 |
+ return this.user1; |
|
| 53 |
+ } |
|
| 54 |
+ |
|
| 55 |
+ public void setUser1(UserEntity user) |
|
| 56 |
+ {
|
|
| 57 |
+ this.user1 = user; |
|
| 58 |
+ } |
|
| 59 |
+ |
|
| 60 |
+ public UserEntity getUser2() |
|
| 61 |
+ {
|
|
| 62 |
+ return this.user2; |
|
| 63 |
+ } |
|
| 64 |
+ |
|
| 65 |
+ public void setUser2(UserEntity user) |
|
| 66 |
+ {
|
|
| 67 |
+ this.user2 = user; |
|
| 68 |
+ } |
|
| 69 |
+ |
|
| 70 |
+ public String toString() |
|
| 71 |
+ {
|
|
| 72 |
+ |
|
| 73 |
+ return "Exchange : id = " + String.valueOf(this.id) + String.valueOf(this.pkm1) + " pkm2 = " + String.valueOf(this.idPkm2) + " dataidPkm2 = " + String.valueOf(this.dataPkm2); |
|
| 74 |
+ } |
|
| 75 |
+ |
|
| 76 |
+ public ExchangeEntity clone() |
|
| 77 |
+ {
|
|
| 78 |
+ ExchangeEntity clone = new ExchangeEntity(); |
|
| 79 |
+ clone.setId(this.id); |
|
| 80 |
+ clone.setPkm1(this.pkm1); |
|
| 81 |
+ clone.setDataPkm2(this.dataPkm2); |
|
| 82 |
+ clone.setIdPkm2(this.dataPkm2); |
|
| 83 |
+ |
|
| 84 |
+ return clone; |
|
| 85 |
+ } |
|
| 86 |
+} |
|
| 0 | 87 |
\ No newline at end of file |
| ... | ... |
@@ -0,0 +1,205 @@ |
| 1 |
+package com.uca.entity; |
|
| 2 |
+ |
|
| 3 |
+import java.util.Date; |
|
| 4 |
+import java.sql.Timestamp; |
|
| 5 |
+ |
|
| 6 |
+import java.io.File; |
|
| 7 |
+ |
|
| 8 |
+public class PokemonEntity {
|
|
| 9 |
+ private int id; |
|
| 10 |
+ private int lvl; |
|
| 11 |
+ private String name; |
|
| 12 |
+ //Non utilisé |
|
| 13 |
+ private String description; |
|
| 14 |
+ //Non utilisé |
|
| 15 |
+ private String[] types; |
|
| 16 |
+ private Date getting_date; |
|
| 17 |
+ private String gender; |
|
| 18 |
+ private Boolean shiny; |
|
| 19 |
+ private String sprite; |
|
| 20 |
+ private int base_owner; |
|
| 21 |
+ private int dataId; |
|
| 22 |
+ |
|
| 23 |
+ public PokemonEntity() |
|
| 24 |
+ {
|
|
| 25 |
+ this.sprite = null; |
|
| 26 |
+ this.types = new String[2]; |
|
| 27 |
+ this.types[0] = null; |
|
| 28 |
+ this.types[1] = null; |
|
| 29 |
+ } |
|
| 30 |
+ |
|
| 31 |
+ public PokemonEntity(int id, int lvl, Boolean shiny) |
|
| 32 |
+ {
|
|
| 33 |
+ this.id = id; |
|
| 34 |
+ this.lvl = lvl; |
|
| 35 |
+ this.shiny = shiny; |
|
| 36 |
+ } |
|
| 37 |
+ |
|
| 38 |
+ public PokemonEntity(int id, String name, int lvl, Boolean shiny) |
|
| 39 |
+ {
|
|
| 40 |
+ |
|
| 41 |
+ this.id = id; |
|
| 42 |
+ this.lvl = lvl; |
|
| 43 |
+ if(name != "") |
|
| 44 |
+ name = name.substring(0,1).toUpperCase() + name.substring(1); |
|
| 45 |
+ this.name = name; |
|
| 46 |
+ this.shiny = shiny; |
|
| 47 |
+ this.gender = ""; |
|
| 48 |
+ |
|
| 49 |
+ this.sprite = shiny ? "/pokemonSprite/shiny/"+String.valueOf(id)+".png" : "/pokemonSprite/"+String.valueOf(id)+".png"; |
|
| 50 |
+ |
|
| 51 |
+ this.types = new String[2]; |
|
| 52 |
+ this.types[0] = null; |
|
| 53 |
+ this.types[1] = null; |
|
| 54 |
+ } |
|
| 55 |
+ |
|
| 56 |
+ public int getId() |
|
| 57 |
+ {
|
|
| 58 |
+ return this.id; |
|
| 59 |
+ } |
|
| 60 |
+ |
|
| 61 |
+ public void setId(int id) |
|
| 62 |
+ {
|
|
| 63 |
+ if(id < 0) |
|
| 64 |
+ throw new IllegalArgumentException("Un index ne peut pas etre négatif");
|
|
| 65 |
+ this.id = id; |
|
| 66 |
+ } |
|
| 67 |
+ |
|
| 68 |
+ public int getDataId() |
|
| 69 |
+ {
|
|
| 70 |
+ return this.dataId; |
|
| 71 |
+ } |
|
| 72 |
+ |
|
| 73 |
+ public void setDataId(int data) |
|
| 74 |
+ {
|
|
| 75 |
+ this.dataId = data; |
|
| 76 |
+ } |
|
| 77 |
+ |
|
| 78 |
+ public int getLvl() |
|
| 79 |
+ {
|
|
| 80 |
+ return this.lvl; |
|
| 81 |
+ } |
|
| 82 |
+ |
|
| 83 |
+ public void setLvl(int lvl) |
|
| 84 |
+ {
|
|
| 85 |
+ this.lvl = lvl; |
|
| 86 |
+ } |
|
| 87 |
+ |
|
| 88 |
+ public String getName() |
|
| 89 |
+ {
|
|
| 90 |
+ String str = new String(this.name); |
|
| 91 |
+ return str; |
|
| 92 |
+ } |
|
| 93 |
+ |
|
| 94 |
+ public void setName(String name) |
|
| 95 |
+ {
|
|
| 96 |
+ name = name.substring(0,1).toUpperCase() + name.substring(1); |
|
| 97 |
+ this.name = name; |
|
| 98 |
+ } |
|
| 99 |
+ |
|
| 100 |
+ public String getDescription() |
|
| 101 |
+ {
|
|
| 102 |
+ String str = new String(this.description); |
|
| 103 |
+ return str; |
|
| 104 |
+ } |
|
| 105 |
+ |
|
| 106 |
+ public void setDescription(String description) |
|
| 107 |
+ {
|
|
| 108 |
+ this.description = description; |
|
| 109 |
+ } |
|
| 110 |
+ |
|
| 111 |
+ public String getType(int i) |
|
| 112 |
+ {
|
|
| 113 |
+ if(i < 0 || i > 2) |
|
| 114 |
+ throw new IndexOutOfBoundsException(); |
|
| 115 |
+ String str = new String(this.types[i]); |
|
| 116 |
+ return str; |
|
| 117 |
+ } |
|
| 118 |
+ |
|
| 119 |
+ public void setType(int i, String type) |
|
| 120 |
+ {
|
|
| 121 |
+ if(i < 0 || i > 2) |
|
| 122 |
+ throw new IndexOutOfBoundsException(); |
|
| 123 |
+ this.types[i] = type; |
|
| 124 |
+ } |
|
| 125 |
+ |
|
| 126 |
+ public Date getGettingDate() |
|
| 127 |
+ {
|
|
| 128 |
+ return this.getting_date; |
|
| 129 |
+ } |
|
| 130 |
+ |
|
| 131 |
+ public void setGettingDate(Date date) |
|
| 132 |
+ {
|
|
| 133 |
+ this.getting_date = date; |
|
| 134 |
+ } |
|
| 135 |
+ |
|
| 136 |
+ public String getGender() |
|
| 137 |
+ {
|
|
| 138 |
+ String str = new String(this.gender); |
|
| 139 |
+ return str; |
|
| 140 |
+ } |
|
| 141 |
+ |
|
| 142 |
+ public void setGender(String gender) |
|
| 143 |
+ {
|
|
| 144 |
+ this.gender = gender; |
|
| 145 |
+ } |
|
| 146 |
+ |
|
| 147 |
+ public Boolean getShiny() |
|
| 148 |
+ {
|
|
| 149 |
+ Boolean bool = new Boolean(this.shiny); |
|
| 150 |
+ return bool; |
|
| 151 |
+ } |
|
| 152 |
+ |
|
| 153 |
+ public void setShiny(Boolean shiny) |
|
| 154 |
+ {
|
|
| 155 |
+ this.shiny = shiny; |
|
| 156 |
+ } |
|
| 157 |
+ |
|
| 158 |
+ public String getSprite() |
|
| 159 |
+ {
|
|
| 160 |
+ String str = new String(this.sprite); |
|
| 161 |
+ return str; |
|
| 162 |
+ } |
|
| 163 |
+ |
|
| 164 |
+ public void setSprite(String sprite) |
|
| 165 |
+ {
|
|
| 166 |
+ this.sprite = sprite; |
|
| 167 |
+ } |
|
| 168 |
+ |
|
| 169 |
+ public int getBaseOwner() |
|
| 170 |
+ {
|
|
| 171 |
+ return this.base_owner; |
|
| 172 |
+ } |
|
| 173 |
+ |
|
| 174 |
+ public void setBaseOwner(int id) |
|
| 175 |
+ {
|
|
| 176 |
+ if(id < 0) |
|
| 177 |
+ throw new IllegalArgumentException("Un index ne peut pas etre négatif");
|
|
| 178 |
+ this.base_owner = id; |
|
| 179 |
+ } |
|
| 180 |
+ |
|
| 181 |
+ public String toString() |
|
| 182 |
+ {
|
|
| 183 |
+ return this.name + " id: " + String.valueOf(this.id) + " lvl: " + String.valueOf(this.lvl) + " shiny: " + String.valueOf(this.shiny) + " dataId: " + String.valueOf(this.dataId); |
|
| 184 |
+ } |
|
| 185 |
+ |
|
| 186 |
+ public PokemonEntity clone() |
|
| 187 |
+ {
|
|
| 188 |
+ PokemonEntity clone = new PokemonEntity(); |
|
| 189 |
+ clone.setId(this.id); |
|
| 190 |
+ clone.setName(this.getName()); |
|
| 191 |
+ clone.setLvl(this.lvl); |
|
| 192 |
+ clone.setDescription(this.getDescription()); |
|
| 193 |
+ clone.setBaseOwner(this.base_owner); |
|
| 194 |
+ clone.setSprite(this.getSprite()); |
|
| 195 |
+ clone.setShiny(this.getShiny()); |
|
| 196 |
+ clone.setGender(this.getGender()); |
|
| 197 |
+ clone.setGettingDate(this.getting_date); |
|
| 198 |
+ clone.setDataId(this.dataId); |
|
| 199 |
+ clone.setType(0, this.getType(0)); |
|
| 200 |
+ clone.setType(1, this.getType(1)); |
|
| 201 |
+ |
|
| 202 |
+ return clone; |
|
| 203 |
+ } |
|
| 204 |
+ |
|
| 205 |
+} |
|
| 0 | 206 |
\ No newline at end of file |
| ... | ... |
@@ -0,0 +1,66 @@ |
| 1 |
+package com.uca.entity; |
|
| 2 |
+ |
|
| 3 |
+import java.util.Date; |
|
| 4 |
+import java.sql.Timestamp; |
|
| 5 |
+ |
|
| 6 |
+public class UserEntity {
|
|
| 7 |
+ private int login; |
|
| 8 |
+ private String pseudo; |
|
| 9 |
+ private String email; |
|
| 10 |
+ private String hashpswd; |
|
| 11 |
+ private String avatarURL; |
|
| 12 |
+ private int points; |
|
| 13 |
+ private Date last_co_date; |
|
| 14 |
+ |
|
| 15 |
+ public UserEntity() {
|
|
| 16 |
+ //Ignored ! |
|
| 17 |
+ } |
|
| 18 |
+ |
|
| 19 |
+ public UserEntity(String pseudo, String pswd, String email) {
|
|
| 20 |
+ this.pseudo = pseudo; |
|
| 21 |
+ this.email = email; |
|
| 22 |
+ this.hashpswd = pswd; |
|
| 23 |
+ } |
|
| 24 |
+ |
|
| 25 |
+ public int getLogin() {
|
|
| 26 |
+ return this.login; |
|
| 27 |
+ } |
|
| 28 |
+ |
|
| 29 |
+ public void setLogin(int login) {
|
|
| 30 |
+ this.login = login; |
|
| 31 |
+ } |
|
| 32 |
+ |
|
| 33 |
+ public String getPseudo() {
|
|
| 34 |
+ return this.pseudo; |
|
| 35 |
+ } |
|
| 36 |
+ |
|
| 37 |
+ public void setPseudo(String pseudo) {
|
|
| 38 |
+ this.pseudo = pseudo; |
|
| 39 |
+ } |
|
| 40 |
+ |
|
| 41 |
+ public String getEmail() {
|
|
| 42 |
+ return this.email; |
|
| 43 |
+ } |
|
| 44 |
+ |
|
| 45 |
+ public void setEmail(String email) {
|
|
| 46 |
+ this.email = email; |
|
| 47 |
+ } |
|
| 48 |
+ |
|
| 49 |
+ public String getHashpswd() {
|
|
| 50 |
+ return this.hashpswd; |
|
| 51 |
+ } |
|
| 52 |
+ |
|
| 53 |
+ public void setHashpswd(String pswd) {
|
|
| 54 |
+ this.hashpswd = pswd; |
|
| 55 |
+ } |
|
| 56 |
+ |
|
| 57 |
+ public Date getLastCoDate() |
|
| 58 |
+ {
|
|
| 59 |
+ return this.last_co_date; |
|
| 60 |
+ } |
|
| 61 |
+ |
|
| 62 |
+ public void setLastCoDate(Date date) |
|
| 63 |
+ {
|
|
| 64 |
+ this.last_co_date = date; |
|
| 65 |
+ } |
|
| 66 |
+} |
| ... | ... |
@@ -0,0 +1,43 @@ |
| 1 |
+package com.uca.entity; |
|
| 2 |
+ |
|
| 3 |
+//Contient des infos propres a un utlisateur |
|
| 4 |
+public class UserInfosEntity extends UserEntity{
|
|
| 5 |
+ private int distinctPkm; |
|
| 6 |
+ private int pkm; |
|
| 7 |
+ private int shiny; |
|
| 8 |
+ |
|
| 9 |
+ public UserInfosEntity() {
|
|
| 10 |
+ //Ignored ! |
|
| 11 |
+ } |
|
| 12 |
+ |
|
| 13 |
+ public int getDistinctPkm() |
|
| 14 |
+ {
|
|
| 15 |
+ return this.distinctPkm; |
|
| 16 |
+ } |
|
| 17 |
+ |
|
| 18 |
+ public void setDistinctPkm(int distinctPkm) |
|
| 19 |
+ {
|
|
| 20 |
+ this.distinctPkm = distinctPkm; |
|
| 21 |
+ } |
|
| 22 |
+ |
|
| 23 |
+ public int getPkm() |
|
| 24 |
+ {
|
|
| 25 |
+ return this.pkm; |
|
| 26 |
+ } |
|
| 27 |
+ |
|
| 28 |
+ public void setPkm(int pkm) |
|
| 29 |
+ {
|
|
| 30 |
+ this.pkm = pkm; |
|
| 31 |
+ } |
|
| 32 |
+ |
|
| 33 |
+ public int getShiny() |
|
| 34 |
+ {
|
|
| 35 |
+ return this.shiny; |
|
| 36 |
+ } |
|
| 37 |
+ |
|
| 38 |
+ public void setShiny(int shiny) |
|
| 39 |
+ {
|
|
| 40 |
+ this.shiny = shiny; |
|
| 41 |
+ } |
|
| 42 |
+ |
|
| 43 |
+} |
|
| 0 | 44 |
\ No newline at end of file |
| ... | ... |
@@ -0,0 +1,144 @@ |
| 1 |
+package com.uca.gui; |
|
| 2 |
+ |
|
| 3 |
+import com.uca.core.ExchangeCore; |
|
| 4 |
+import com.uca.core.PokemonCore; |
|
| 5 |
+import com.uca.core.UserCore; |
|
| 6 |
+import freemarker.template.Configuration; |
|
| 7 |
+import freemarker.template.Template; |
|
| 8 |
+import freemarker.template.TemplateException; |
|
| 9 |
+ |
|
| 10 |
+import java.io.IOException; |
|
| 11 |
+import java.io.StringWriter; |
|
| 12 |
+import java.io.Writer; |
|
| 13 |
+import java.util.HashMap; |
|
| 14 |
+import java.util.Map; |
|
| 15 |
+ |
|
| 16 |
+public class ExchangeGUI {
|
|
| 17 |
+ //Plus utilisé |
|
| 18 |
+ public static String getAllExchange() throws IOException, TemplateException {
|
|
| 19 |
+ Configuration configuration = _FreeMarkerInitializer.getContext(); |
|
| 20 |
+ |
|
| 21 |
+ Map<String, Object> input = new HashMap<>(); |
|
| 22 |
+ |
|
| 23 |
+ input.put("exchanges", ExchangeCore.getAllExchange());
|
|
| 24 |
+ |
|
| 25 |
+ |
|
| 26 |
+ Writer output = new StringWriter(); |
|
| 27 |
+ Template template = configuration.getTemplate("exchanges/allExchange.ftl");
|
|
| 28 |
+ template.setOutputEncoding("UTF-8");
|
|
| 29 |
+ template.process(input, output); |
|
| 30 |
+ |
|
| 31 |
+ return output.toString(); |
|
| 32 |
+ } |
|
| 33 |
+ |
|
| 34 |
+ //Renvoie un échange |
|
| 35 |
+ public static String getExchangeById(int id) throws IOException, TemplateException {
|
|
| 36 |
+ Configuration configuration = _FreeMarkerInitializer.getContext(); |
|
| 37 |
+ |
|
| 38 |
+ Map<String, Object> input = new HashMap<>(); |
|
| 39 |
+ |
|
| 40 |
+ input.put("exchange", ExchangeCore.getExchangeById(id));
|
|
| 41 |
+ |
|
| 42 |
+ |
|
| 43 |
+ Writer output = new StringWriter(); |
|
| 44 |
+ Template template = configuration.getTemplate("exchanges/exchange.ftl");
|
|
| 45 |
+ template.setOutputEncoding("UTF-8");
|
|
| 46 |
+ template.process(input, output); |
|
| 47 |
+ |
|
| 48 |
+ return output.toString(); |
|
| 49 |
+ } |
|
| 50 |
+ |
|
| 51 |
+ //Renvoie une offre d'échange (choix d'un pokemon dans échange non défini) |
|
| 52 |
+ public static String getExchangeOffer(int id, int dataId) throws IOException, TemplateException {
|
|
| 53 |
+ Configuration configuration = _FreeMarkerInitializer.getContext(); |
|
| 54 |
+ |
|
| 55 |
+ Map<String, Object> input = new HashMap<>(); |
|
| 56 |
+ |
|
| 57 |
+ |
|
| 58 |
+ input.put("exchange", ExchangeCore.getNewOffer(id, dataId));
|
|
| 59 |
+ |
|
| 60 |
+ |
|
| 61 |
+ Writer output = new StringWriter(); |
|
| 62 |
+ Template template = configuration.getTemplate("exchanges/exchangeOffer.ftl");
|
|
| 63 |
+ template.setOutputEncoding("UTF-8");
|
|
| 64 |
+ template.process(input, output); |
|
| 65 |
+ |
|
| 66 |
+ return output.toString(); |
|
| 67 |
+ } |
|
| 68 |
+ |
|
| 69 |
+ //Interface qui permet la creation d'un echange défini |
|
| 70 |
+ public static String newExchange(int iduser1, int dataId, int iduser2, int pkm2) throws IOException, TemplateException {
|
|
| 71 |
+ Configuration configuration = _FreeMarkerInitializer.getContext(); |
|
| 72 |
+ |
|
| 73 |
+ Map<String, Object> input = new HashMap<>(); |
|
| 74 |
+ |
|
| 75 |
+ input.put("exchange", ExchangeCore.newExchangeOffer(iduser1, dataId,iduser2, pkm2));
|
|
| 76 |
+ |
|
| 77 |
+ |
|
| 78 |
+ Writer output = new StringWriter(); |
|
| 79 |
+ Template template = configuration.getTemplate("exchanges/newExchange.ftl");
|
|
| 80 |
+ template.setOutputEncoding("UTF-8");
|
|
| 81 |
+ template.process(input, output); |
|
| 82 |
+ |
|
| 83 |
+ return output.toString(); |
|
| 84 |
+ } |
|
| 85 |
+ |
|
| 86 |
+ //Affiche les echanges entrant d'un utilisateur |
|
| 87 |
+ public static String exchangeIn(int iduser) throws IOException, TemplateException |
|
| 88 |
+ {
|
|
| 89 |
+ Configuration configuration = _FreeMarkerInitializer.getContext(); |
|
| 90 |
+ |
|
| 91 |
+ Map<String, Object> input = new HashMap<>(); |
|
| 92 |
+ |
|
| 93 |
+ input.put("exchanges", ExchangeCore.getAllExchangeIn(iduser));
|
|
| 94 |
+ |
|
| 95 |
+ |
|
| 96 |
+ Writer output = new StringWriter(); |
|
| 97 |
+ Template template = configuration.getTemplate("exchanges/allExchangeIn.ftl");
|
|
| 98 |
+ template.setOutputEncoding("UTF-8");
|
|
| 99 |
+ template.process(input, output); |
|
| 100 |
+ |
|
| 101 |
+ return output.toString(); |
|
| 102 |
+ } |
|
| 103 |
+ |
|
| 104 |
+ //Affiche les echanges sortant d'un utilisateur |
|
| 105 |
+ public static String exchangeOut(int iduser, boolean actualUser) throws IOException, TemplateException |
|
| 106 |
+ {
|
|
| 107 |
+ Configuration configuration = _FreeMarkerInitializer.getContext(); |
|
| 108 |
+ |
|
| 109 |
+ Map<String, Object> input = new HashMap<>(); |
|
| 110 |
+ |
|
| 111 |
+ input.put("exchanges", ExchangeCore.getAllExchangeOut(iduser, actualUser));
|
|
| 112 |
+ |
|
| 113 |
+ |
|
| 114 |
+ Writer output = new StringWriter(); |
|
| 115 |
+ Template template; |
|
| 116 |
+ if(actualUser) |
|
| 117 |
+ template = configuration.getTemplate("exchanges/allMyExchangeOut.ftl");
|
|
| 118 |
+ else |
|
| 119 |
+ template = configuration.getTemplate("exchanges/allExchangeOut.ftl");
|
|
| 120 |
+ template.setOutputEncoding("UTF-8");
|
|
| 121 |
+ template.process(input, output); |
|
| 122 |
+ |
|
| 123 |
+ return output.toString(); |
|
| 124 |
+ } |
|
| 125 |
+ |
|
| 126 |
+ //Affiche l'interface pour creer un échange indéfini |
|
| 127 |
+ public static String myNewExchange(int userId, int dataId) throws IOException, TemplateException |
|
| 128 |
+ {
|
|
| 129 |
+ Configuration configuration = _FreeMarkerInitializer.getContext(); |
|
| 130 |
+ |
|
| 131 |
+ Map<String, Object> input = new HashMap<>(); |
|
| 132 |
+ |
|
| 133 |
+ input.put("user", UserCore.getUserById(userId));
|
|
| 134 |
+ input.put("pokemon", PokemonCore.getPokemonByDataId(dataId));
|
|
| 135 |
+ |
|
| 136 |
+ |
|
| 137 |
+ Writer output = new StringWriter(); |
|
| 138 |
+ Template template = configuration.getTemplate("exchanges/myNewExchange.ftl");
|
|
| 139 |
+ template.setOutputEncoding("UTF-8");
|
|
| 140 |
+ template.process(input, output); |
|
| 141 |
+ |
|
| 142 |
+ return output.toString(); |
|
| 143 |
+ } |
|
| 144 |
+} |
|
| 0 | 145 |
\ No newline at end of file |
| ... | ... |
@@ -0,0 +1,88 @@ |
| 1 |
+package com.uca.gui; |
|
| 2 |
+ |
|
| 3 |
+import com.uca.core.PokemonCore; |
|
| 4 |
+import freemarker.template.Configuration; |
|
| 5 |
+import freemarker.template.Template; |
|
| 6 |
+import freemarker.template.TemplateException; |
|
| 7 |
+ |
|
| 8 |
+import java.io.IOException; |
|
| 9 |
+import java.io.StringWriter; |
|
| 10 |
+import java.io.Writer; |
|
| 11 |
+import java.util.HashMap; |
|
| 12 |
+import java.util.Map; |
|
| 13 |
+ |
|
| 14 |
+ |
|
| 15 |
+public class PokemonGUI {
|
|
| 16 |
+ //Plus utilisé |
|
| 17 |
+ public static String getPokemonByUser(int id) throws IOException, TemplateException {
|
|
| 18 |
+ Configuration configuration = _FreeMarkerInitializer.getContext(); |
|
| 19 |
+ |
|
| 20 |
+ Map<String, Object> input = new HashMap<>(); |
|
| 21 |
+ |
|
| 22 |
+ input.put("pokemons", PokemonCore.getPokemonByUser(id));
|
|
| 23 |
+ |
|
| 24 |
+ Writer output = new StringWriter(); |
|
| 25 |
+ Template template = configuration.getTemplate("users/poketest.ftl");
|
|
| 26 |
+ template.setOutputEncoding("UTF-8");
|
|
| 27 |
+ template.process(input, output); |
|
| 28 |
+ |
|
| 29 |
+ return output.toString(); |
|
| 30 |
+ } |
|
| 31 |
+ |
|
| 32 |
+ //Affiche la page montrant le nouveau pokemon obtenu lors de la premiere connexion journalière |
|
| 33 |
+ public static String getNewPokemon(int userId) throws IOException, TemplateException {
|
|
| 34 |
+ Configuration configuration = _FreeMarkerInitializer.getContext(); |
|
| 35 |
+ |
|
| 36 |
+ Map<String, Object> input = new HashMap<>(); |
|
| 37 |
+ |
|
| 38 |
+ input.put("pokemon", PokemonCore.getNewPokemon(userId));
|
|
| 39 |
+ |
|
| 40 |
+ Writer output = new StringWriter(); |
|
| 41 |
+ Template template = configuration.getTemplate("pokemons/newPokemon.ftl");
|
|
| 42 |
+ template.setOutputEncoding("UTF-8");
|
|
| 43 |
+ template.process(input, output); |
|
| 44 |
+ |
|
| 45 |
+ return output.toString(); |
|
| 46 |
+ } |
|
| 47 |
+ |
|
| 48 |
+ //Affiche l'interface permettant de choisir un pokemon a échangé dans un échange défini |
|
| 49 |
+ public static String getPokemonForNewExchangeOffer(int userId1, int useriId2, int pkmId) throws IOException, TemplateException |
|
| 50 |
+ {
|
|
| 51 |
+ Configuration configuration = _FreeMarkerInitializer.getContext(); |
|
| 52 |
+ |
|
| 53 |
+ Map<String, Object> input = new HashMap<>(); |
|
| 54 |
+ |
|
| 55 |
+ |
|
| 56 |
+ input.put("pokemons", PokemonCore.getPokemonForExchange(useriId2, 0,0,false));
|
|
| 57 |
+ input.put("pkm1", pkmId);
|
|
| 58 |
+ input.put("user1", userId1);
|
|
| 59 |
+ |
|
| 60 |
+ |
|
| 61 |
+ Writer output = new StringWriter(); |
|
| 62 |
+ Template template = configuration.getTemplate("pokemons/pokemonForNewExchange.ftl");
|
|
| 63 |
+ template.setOutputEncoding("UTF-8");
|
|
| 64 |
+ template.process(input, output); |
|
| 65 |
+ |
|
| 66 |
+ return output.toString(); |
|
| 67 |
+ } |
|
| 68 |
+ |
|
| 69 |
+ //Affiche les pokemon selectionnable lorsque l'on essaye de répondre a une offre d'échange indéfini |
|
| 70 |
+ public static String getPokemonForExchange(int exchange, int onwerId, int id, int lvl, Boolean shiny) throws IOException, TemplateException |
|
| 71 |
+ {
|
|
| 72 |
+ Configuration configuration = _FreeMarkerInitializer.getContext(); |
|
| 73 |
+ |
|
| 74 |
+ Map<String, Object> input = new HashMap<>(); |
|
| 75 |
+ |
|
| 76 |
+ |
|
| 77 |
+ input.put("pokemons", PokemonCore.getPokemonForExchange(onwerId, id, lvl, shiny));
|
|
| 78 |
+ input.put("exchange", exchange);
|
|
| 79 |
+ |
|
| 80 |
+ |
|
| 81 |
+ Writer output = new StringWriter(); |
|
| 82 |
+ Template template = configuration.getTemplate("pokemons/pokemonForExchange.ftl");
|
|
| 83 |
+ template.setOutputEncoding("UTF-8");
|
|
| 84 |
+ template.process(input, output); |
|
| 85 |
+ |
|
| 86 |
+ return output.toString(); |
|
| 87 |
+ } |
|
| 88 |
+} |
| ... | ... |
@@ -0,0 +1,82 @@ |
| 1 |
+package com.uca.gui; |
|
| 2 |
+ |
|
| 3 |
+import com.uca.core.UserCore; |
|
| 4 |
+import com.uca.core.PokemonCore; |
|
| 5 |
+import freemarker.template.Configuration; |
|
| 6 |
+import freemarker.template.Template; |
|
| 7 |
+import freemarker.template.TemplateException; |
|
| 8 |
+ |
|
| 9 |
+ |
|
| 10 |
+import java.io.IOException; |
|
| 11 |
+import java.io.StringWriter; |
|
| 12 |
+import java.io.Writer; |
|
| 13 |
+import java.util.HashMap; |
|
| 14 |
+import java.util.Map; |
|
| 15 |
+ |
|
| 16 |
+public class UserGUI {
|
|
| 17 |
+ |
|
| 18 |
+ //Plus utilisé |
|
| 19 |
+ public static String getAllUsers() throws IOException, TemplateException {
|
|
| 20 |
+ Configuration configuration = _FreeMarkerInitializer.getContext(); |
|
| 21 |
+ |
|
| 22 |
+ Map<String, Object> input = new HashMap<>(); |
|
| 23 |
+ input.put("users", UserCore.getAllUsers());
|
|
| 24 |
+ |
|
| 25 |
+ |
|
| 26 |
+ Writer output = new StringWriter(); |
|
| 27 |
+ Template template = configuration.getTemplate("users/users.ftl");
|
|
| 28 |
+ template.setOutputEncoding("UTF-8");
|
|
| 29 |
+ template.process(input, output); |
|
| 30 |
+ |
|
| 31 |
+ return output.toString(); |
|
| 32 |
+ } |
|
| 33 |
+ |
|
| 34 |
+ //Renvoie la liste des joueur ayant pour id ou pseudo search |
|
| 35 |
+ public static String searchUser(String search) throws IOException, TemplateException {
|
|
| 36 |
+ Configuration configuration = _FreeMarkerInitializer.getContext(); |
|
| 37 |
+ Map<String, Object> input = new HashMap<>(); |
|
| 38 |
+ input.put("users", UserCore.userSearch(search));
|
|
| 39 |
+ |
|
| 40 |
+ |
|
| 41 |
+ Writer output = new StringWriter(); |
|
| 42 |
+ Template template = configuration.getTemplate("users/searchUsers.ftl");
|
|
| 43 |
+ template.setOutputEncoding("UTF-8");
|
|
| 44 |
+ template.process(input, output); |
|
| 45 |
+ |
|
| 46 |
+ return output.toString(); |
|
| 47 |
+ } |
|
| 48 |
+ |
|
| 49 |
+ //Renvoie le profile d'un utilisateur différent de celui connecté |
|
| 50 |
+ public static String getUserById(int id) throws IOException, TemplateException {
|
|
| 51 |
+ Configuration configuration = _FreeMarkerInitializer.getContext(); |
|
| 52 |
+ |
|
| 53 |
+ Map<String, Object> input = new HashMap<>(); |
|
| 54 |
+ input.put("user", UserCore.getUserById(id));
|
|
| 55 |
+ input.put("pokemons", PokemonCore.getPokemonByUser(id));
|
|
| 56 |
+ input.put("userinfo", UserCore.getUserInfo(id));
|
|
| 57 |
+ |
|
| 58 |
+ Writer output = new StringWriter(); |
|
| 59 |
+ Template template = configuration.getTemplate("users/profile.ftl");
|
|
| 60 |
+ template.setOutputEncoding("UTF-8");
|
|
| 61 |
+ template.process(input, output); |
|
| 62 |
+ |
|
| 63 |
+ return output.toString(); |
|
| 64 |
+ } |
|
| 65 |
+ |
|
| 66 |
+ //Renvoie le profil de l'utilisateur connecrté |
|
| 67 |
+ public static String getMyProfileById(int id) throws IOException, TemplateException {
|
|
| 68 |
+ Configuration configuration = _FreeMarkerInitializer.getContext(); |
|
| 69 |
+ |
|
| 70 |
+ Map<String, Object> input = new HashMap<>(); |
|
| 71 |
+ input.put("user", UserCore.getUserById(id));
|
|
| 72 |
+ input.put("pokemons", PokemonCore.getPokemonByUser(id));
|
|
| 73 |
+ input.put("userinfo", UserCore.getUserInfo(id));
|
|
| 74 |
+ |
|
| 75 |
+ Writer output = new StringWriter(); |
|
| 76 |
+ Template template = configuration.getTemplate("users/myprofile.ftl");
|
|
| 77 |
+ template.setOutputEncoding("UTF-8");
|
|
| 78 |
+ template.process(input, output); |
|
| 79 |
+ |
|
| 80 |
+ return output.toString(); |
|
| 81 |
+ } |
|
| 82 |
+} |
| ... | ... |
@@ -0,0 +1,35 @@ |
| 1 |
+package com.uca.gui; |
|
| 2 |
+ |
|
| 3 |
+import freemarker.template.Configuration; |
|
| 4 |
+import freemarker.template.Template; |
|
| 5 |
+import freemarker.template.TemplateException; |
|
| 6 |
+ |
|
| 7 |
+ |
|
| 8 |
+import java.io.IOException; |
|
| 9 |
+import java.io.StringWriter; |
|
| 10 |
+import java.io.Writer; |
|
| 11 |
+import java.util.HashMap; |
|
| 12 |
+import java.util.Map; |
|
| 13 |
+ |
|
| 14 |
+import java.nio.file.Files; |
|
| 15 |
+import java.nio.file.Paths; |
|
| 16 |
+ |
|
| 17 |
+public class UtilGUI |
|
| 18 |
+{
|
|
| 19 |
+ //Renvoie la frontpage du sit (actuellement la page de login) |
|
| 20 |
+ public static String frontPage() throws IOException, TemplateException |
|
| 21 |
+ {
|
|
| 22 |
+ Configuration configuration = _FreeMarkerInitializer.getContext(); |
|
| 23 |
+ |
|
| 24 |
+ Map<String, Object> input = new HashMap<>(); |
|
| 25 |
+ |
|
| 26 |
+ |
|
| 27 |
+ Writer output = new StringWriter(); |
|
| 28 |
+ Template template = configuration.getTemplate("login.ftl");
|
|
| 29 |
+ template.setOutputEncoding("UTF-8");
|
|
| 30 |
+ template.process(input, output); |
|
| 31 |
+ |
|
| 32 |
+ return output.toString(); |
|
| 33 |
+ } |
|
| 34 |
+ |
|
| 35 |
+} |
|
| 0 | 36 |
\ No newline at end of file |
| ... | ... |
@@ -0,0 +1,21 @@ |
| 1 |
+package com.uca.gui; |
|
| 2 |
+ |
|
| 3 |
+import com.uca.StartServer; |
|
| 4 |
+import freemarker.template.Configuration; |
|
| 5 |
+import freemarker.template.TemplateExceptionHandler; |
|
| 6 |
+ |
|
| 7 |
+import java.util.Locale; |
|
| 8 |
+ |
|
| 9 |
+public class _FreeMarkerInitializer {
|
|
| 10 |
+ |
|
| 11 |
+ public static Configuration getContext() {
|
|
| 12 |
+ //Configure FreeMarker |
|
| 13 |
+ Configuration configuration = new Configuration(Configuration.VERSION_2_3_30); |
|
| 14 |
+ configuration.setClassForTemplateLoading(StartServer.class, "/views"); |
|
| 15 |
+ configuration.setDefaultEncoding("UTF-8");
|
|
| 16 |
+ configuration.setLocale(Locale.FRANCE); |
|
| 17 |
+ configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); |
|
| 18 |
+ |
|
| 19 |
+ return configuration; |
|
| 20 |
+ } |
|
| 21 |
+} |
| ... | ... |
@@ -0,0 +1,37 @@ |
| 1 |
+package com.uca.util; |
|
| 2 |
+ |
|
| 3 |
+import java.io.BufferedReader; |
|
| 4 |
+import java.io.IOException; |
|
| 5 |
+import java.io.InputStream; |
|
| 6 |
+import java.io.InputStreamReader; |
|
| 7 |
+import java.io.Reader; |
|
| 8 |
+import java.net.URL; |
|
| 9 |
+import java.nio.charset.Charset; |
|
| 10 |
+ |
|
| 11 |
+import org.json.JSONException; |
|
| 12 |
+import org.json.JSONObject; |
|
| 13 |
+ |
|
| 14 |
+//Tout est dans le nom |
|
| 15 |
+public class JsonReader {
|
|
| 16 |
+ |
|
| 17 |
+ private static String readAll(Reader rd) throws IOException {
|
|
| 18 |
+ StringBuilder sb = new StringBuilder(); |
|
| 19 |
+ int cp; |
|
| 20 |
+ while ((cp = rd.read()) != -1) {
|
|
| 21 |
+ sb.append((char) cp); |
|
| 22 |
+ } |
|
| 23 |
+ return sb.toString(); |
|
| 24 |
+ } |
|
| 25 |
+ |
|
| 26 |
+ public static JSONObject readJsonFromUrl(String url) throws IOException, JSONException {
|
|
| 27 |
+ InputStream is = new URL(url).openStream(); |
|
| 28 |
+ try {
|
|
| 29 |
+ BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
|
|
| 30 |
+ String jsonText = readAll(rd); |
|
| 31 |
+ JSONObject json = new JSONObject(jsonText); |
|
| 32 |
+ return json; |
|
| 33 |
+ } finally {
|
|
| 34 |
+ is.close(); |
|
| 35 |
+ } |
|
| 36 |
+ } |
|
| 37 |
+} |
|
| 0 | 38 |
\ No newline at end of file |
| ... | ... |
@@ -0,0 +1,27 @@ |
| 1 |
+package com.uca.util; |
|
| 2 |
+ |
|
| 3 |
+import java.util.concurrent.Executors; |
|
| 4 |
+import java.util.concurrent.ScheduledExecutorService; |
|
| 5 |
+import java.util.concurrent.TimeUnit; |
|
| 6 |
+ |
|
| 7 |
+import com.uca.core.UserCore; |
|
| 8 |
+ |
|
| 9 |
+//Met a jour les 5 lvl up des utilisateur toute les 24h |
|
| 10 |
+public class Scheduler {
|
|
| 11 |
+ private ScheduledExecutorService scheduler; |
|
| 12 |
+ |
|
| 13 |
+ public Scheduler() {
|
|
| 14 |
+ this.scheduler = Executors.newSingleThreadScheduledExecutor(); |
|
| 15 |
+ } |
|
| 16 |
+ |
|
| 17 |
+ public void start() |
|
| 18 |
+ {
|
|
| 19 |
+ this.scheduler.scheduleAtFixedRate(() -> {
|
|
| 20 |
+ resetLvlUp(); |
|
| 21 |
+ },0, 24, TimeUnit.HOURS); |
|
| 22 |
+ } |
|
| 23 |
+ |
|
| 24 |
+ private void resetLvlUp() {
|
|
| 25 |
+ UserCore.updateLvlUp(); |
|
| 26 |
+ } |
|
| 27 |
+} |
|
| 0 | 28 |
\ No newline at end of file |
| ... | ... |
@@ -0,0 +1,78 @@ |
| 1 |
+<!DOCTYPE html> |
|
| 2 |
+<html lang = "fr"> |
|
| 3 |
+<head> |
|
| 4 |
+ <meta charset="utf-8"> |
|
| 5 |
+ <meta name="viewport" content="width=device-width, initial-scale=1"> |
|
| 6 |
+ <link rel="stylesheet" type="text/css" href="style.css" media="screen"> |
|
| 7 |
+ |
|
| 8 |
+ |
|
| 9 |
+ <title></title> |
|
| 10 |
+ |
|
| 11 |
+ |
|
| 12 |
+ |
|
| 13 |
+</head> |
|
| 14 |
+ |
|
| 15 |
+<body> |
|
| 16 |
+ |
|
| 17 |
+ <div class="container"> |
|
| 18 |
+ <div class = logsign> |
|
| 19 |
+ <form action="/signup" method="post" id="signup" class = form> |
|
| 20 |
+ <h1>Signup</h1> |
|
| 21 |
+ <div class="field"> |
|
| 22 |
+ <label for="lastname">Pseudo :</label> |
|
| 23 |
+ <input type="text" id="pseudo" name="pseudo" placeholder="Enter you pseudo" > |
|
| 24 |
+ <small></small> |
|
| 25 |
+ </div> |
|
| 26 |
+ |
|
| 27 |
+ <div class="field"> |
|
| 28 |
+ <label for="userpwd">Password :</label> |
|
| 29 |
+ <input type="password" id="userpwd" name="userpwd" placeholder="Entrez votre mot de passe ici" > |
|
| 30 |
+ <small></small> |
|
| 31 |
+ </div> |
|
| 32 |
+ |
|
| 33 |
+ <div class="field"> |
|
| 34 |
+ <label for="usermail">Email:</label> |
|
| 35 |
+ <input type="text" id="usermail" name="usermail" placeholder="Enter your email address" > |
|
| 36 |
+ <small></small> |
|
| 37 |
+ </div> |
|
| 38 |
+ <div class="field"> |
|
| 39 |
+ <button type="submit" class="full">Signin</button> |
|
| 40 |
+ </div> |
|
| 41 |
+ <div id="zoneSignup"> |
|
| 42 |
+ <span class="Style1"></span> |
|
| 43 |
+ </div> |
|
| 44 |
+ </form> |
|
| 45 |
+ |
|
| 46 |
+ |
|
| 47 |
+ <form action="/login" method="post" id="login" class = form> |
|
| 48 |
+ <h1>Login</h1> |
|
| 49 |
+ |
|
| 50 |
+ <div class="field"> |
|
| 51 |
+ <label for="usermail">Email:</label> |
|
| 52 |
+ <input type="text" id="usermail" name="usermail" placeholder="Enter your email address" > |
|
| 53 |
+ <small></small> |
|
| 54 |
+ </div> |
|
| 55 |
+ |
|
| 56 |
+ <div class="field"> |
|
| 57 |
+ <label for="userpwd">Password :</label> |
|
| 58 |
+ <input type="password" id="userpwd" name="userpwd" placeholder="Entrez votre mot de passe ici" > |
|
| 59 |
+ <small></small> |
|
| 60 |
+ </div> |
|
| 61 |
+ |
|
| 62 |
+ |
|
| 63 |
+ <div class="field"> |
|
| 64 |
+ <button type="submit" class="full">Login</button> |
|
| 65 |
+ </div> |
|
| 66 |
+ <div id="zone"> |
|
| 67 |
+ <span class="Style1"></span> |
|
| 68 |
+ </div> |
|
| 69 |
+ </form> |
|
| 70 |
+ </div> |
|
| 71 |
+ |
|
| 72 |
+ |
|
| 73 |
+ </div> |
|
| 74 |
+ |
|
| 75 |
+ |
|
| 76 |
+ |
|
| 77 |
+</body> |
|
| 78 |
+</html> |
|
| 0 | 79 |
\ No newline at end of file |
| ... | ... |
@@ -0,0 +1,78 @@ |
| 1 |
+body{
|
|
| 2 |
+ display: block; |
|
| 3 |
+ margin: 0; |
|
| 4 |
+} |
|
| 5 |
+ |
|
| 6 |
+ul{
|
|
| 7 |
+ list-style-type: disc; |
|
| 8 |
+ margin-block-start: 0; |
|
| 9 |
+ margin-block-end: 0; |
|
| 10 |
+ padding-inline-start: 0; |
|
| 11 |
+} |
|
| 12 |
+ |
|
| 13 |
+.profil{
|
|
| 14 |
+ position: fixed; |
|
| 15 |
+ height: 300px; |
|
| 16 |
+ width: 98vw; |
|
| 17 |
+ margin : 1vw; |
|
| 18 |
+ border: 2px solid black; |
|
| 19 |
+ bottom: 0; |
|
| 20 |
+ z-index: 10; |
|
| 21 |
+ background-color: lightgray; |
|
| 22 |
+} |
|
| 23 |
+ |
|
| 24 |
+.pkList{
|
|
| 25 |
+ display: grid; |
|
| 26 |
+ grid-template-columns: repeat(6, 1fr); |
|
| 27 |
+ column-gap: 1vw; |
|
| 28 |
+ row-gap: 1vh; |
|
| 29 |
+ margin: 1vw; |
|
| 30 |
+} |
|
| 31 |
+ |
|
| 32 |
+.pkListItem > img{
|
|
| 33 |
+ width: 75%; |
|
| 34 |
+ height: auto; |
|
| 35 |
+ align-content: center; |
|
| 36 |
+} |
|
| 37 |
+ |
|
| 38 |
+li{
|
|
| 39 |
+ list-style-type: none; |
|
| 40 |
+} |
|
| 41 |
+ |
|
| 42 |
+.pkListItem |
|
| 43 |
+{
|
|
| 44 |
+ text-align: center; |
|
| 45 |
+ border : 2px solid black; |
|
| 46 |
+ max-width: 15vw; |
|
| 47 |
+ height: auto; |
|
| 48 |
+} |
|
| 49 |
+ |
|
| 50 |
+.exchange{
|
|
| 51 |
+ display: flex; /* afficher les éléments en ligne */ |
|
| 52 |
+ flex-wrap: wrap; /* permettre aux éléments de passer à la ligne si nécessaire */ |
|
| 53 |
+ justify-content: space-between; /* aligner les éléments en début et fin de ligne */ |
|
| 54 |
+ align-items: center; /* centrer verticalement les éléments */ |
|
| 55 |
+ padding: 10px; /* ajouter un peu d'espace autour de chaque élément */ |
|
| 56 |
+ border: 1px solid #ccc; /* ajouter une bordure pour séparer chaque élément */ |
|
| 57 |
+ margin-bottom: 10px; /* ajouter un peu d'espace entre chaque élément */ |
|
| 58 |
+} |
|
| 59 |
+ |
|
| 60 |
+.exchange{
|
|
| 61 |
+ dsiplay:block; |
|
| 62 |
+} |
|
| 63 |
+ |
|
| 64 |
+.exchangeForm |
|
| 65 |
+{
|
|
| 66 |
+ display: inline-flex; |
|
| 67 |
+} |
|
| 68 |
+ |
|
| 69 |
+.left{
|
|
| 70 |
+ float:left; |
|
| 71 |
+ max-width: 50%; |
|
| 72 |
+ margin:1vw; |
|
| 73 |
+} |
|
| 74 |
+ |
|
| 75 |
+nav{
|
|
| 76 |
+ margin:1vw; |
|
| 77 |
+ float:right; |
|
| 78 |
+} |
| ... | ... |
@@ -0,0 +1,72 @@ |
| 1 |
+<#ftl encoding="utf-8"> |
|
| 2 |
+<!DOCTYPE html> |
|
| 3 |
+<html> |
|
| 4 |
+<head> |
|
| 5 |
+<link rel="stylesheet" type="text/css" href="/style.css" media="screen"> |
|
| 6 |
+ |
|
| 7 |
+<title></title> |
|
| 8 |
+</head> |
|
| 9 |
+<body xmlns="http://www.w3.org/1999/html"> |
|
| 10 |
+ |
|
| 11 |
+<ul> |
|
| 12 |
+ <#list exchanges as exchange> |
|
| 13 |
+ |
|
| 14 |
+ <li class = exchange> |
|
| 15 |
+ <div class = pokemon> |
|
| 16 |
+ <p>By ${(exchange.user1.pseudo)!} </p>
|
|
| 17 |
+ <img src = ${(exchange.pkm1.sprite)!} alt = ${(exchange.pkm1.name)!}</img>
|
|
| 18 |
+ <h3>${(exchange.pkm1.name)!}</h3>
|
|
| 19 |
+ <p>${(exchange.pkm1.lvl)!}</p>
|
|
| 20 |
+ </div> |
|
| 21 |
+ <div class = "pokemon"> |
|
| 22 |
+ <#if exchange.dataPkm2?has_content> |
|
| 23 |
+ <p>By ${(exchange.user2.pseudo)!} </p>
|
|
| 24 |
+ <img src = ${(exchange.dataPkm2.sprite)!} alt = ${(exchange.dataPkm2.name)!}</img>
|
|
| 25 |
+ <h3>${(exchange.dataPkm2.name)!}</h3>
|
|
| 26 |
+ <p>${(exchange.dataPkm2.lvl)!}</p>
|
|
| 27 |
+ </div> |
|
| 28 |
+ <form action = "/exchange/${(exchange.id)!}/accepted" method = "POST">
|
|
| 29 |
+ <button>Accept</button> |
|
| 30 |
+ </form> |
|
| 31 |
+ <#else> |
|
| 32 |
+ <form action = "/exchange/${(exchange.id)!}/selectPokemon" method = "GET" >
|
|
| 33 |
+ <#if exchange.idPkm2?? && exchange.idPkm2.id == 0> |
|
| 34 |
+ <input type="hidden" name="pkmId" value="0"> |
|
| 35 |
+ <img src = "/pokemonSprite/0.png" alt = "Any pokemon"</img> <br> |
|
| 36 |
+ <#else> |
|
| 37 |
+ <input type="hidden" name="pkmId" value="${exchange.idPkm2.id}">
|
|
| 38 |
+ <img src = "${(exchange.idPkm2.sprite)!}" alt = "${(exchange.idPkm2.name)!}"</img>
|
|
| 39 |
+ </#if> |
|
| 40 |
+ <input type="hidden" name="pkmShiny" value="${exchange.idPkm2.shiny?c}">
|
|
| 41 |
+ <#if exchange.idPkm2?? && exchange.idPkm2.name?has_content> |
|
| 42 |
+ |
|
| 43 |
+ <#if exchange.idPkm2.shiny> |
|
| 44 |
+ <h3>Shiny ${(exchange.idPkm2.name)!}</h3>
|
|
| 45 |
+ <#else> |
|
| 46 |
+ <h3>${(exchange.idPkm2.name)!}</h3>
|
|
| 47 |
+ </#if> |
|
| 48 |
+ <#else> |
|
| 49 |
+ <h3>Any pokemon</h3> |
|
| 50 |
+ </#if> |
|
| 51 |
+ <#if exchange.idPkm2?? && exchange.idPkm2.lvl == 0> |
|
| 52 |
+ <input type="hidden" name="pkmLvl" value="0"> |
|
| 53 |
+ <h3>Any level</h3> |
|
| 54 |
+ <#else> |
|
| 55 |
+ <input type="hidden" name="pkmLvl" value="${exchange.idPkm2.lvl}">
|
|
| 56 |
+ <h3>At least level ${(exchange.idPkm2.lvl)!}</h3>
|
|
| 57 |
+ </#if> |
|
| 58 |
+ |
|
| 59 |
+ <button>Choose</button> |
|
| 60 |
+ </form> |
|
| 61 |
+ </div> |
|
| 62 |
+ <div></div> |
|
| 63 |
+ </#if> |
|
| 64 |
+ |
|
| 65 |
+ </div> |
|
| 66 |
+ </li> |
|
| 67 |
+ </#list> |
|
| 68 |
+</ul> |
|
| 69 |
+ |
|
| 70 |
+</body> |
|
| 71 |
+ |
|
| 72 |
+</html> |
| ... | ... |
@@ -0,0 +1,42 @@ |
| 1 |
+<#ftl encoding="utf-8"> |
|
| 2 |
+<!DOCTYPE html> |
|
| 3 |
+<html> |
|
| 4 |
+<head> |
|
| 5 |
+<link rel="stylesheet" type="text/css" href="/style.css" media="screen"> |
|
| 6 |
+ |
|
| 7 |
+<title></title> |
|
| 8 |
+</head> |
|
| 9 |
+<body xmlns="http://www.w3.org/1999/html"> |
|
| 10 |
+ |
|
| 11 |
+<ul> |
|
| 12 |
+ <#list exchanges as exchange> |
|
| 13 |
+ |
|
| 14 |
+ <li class = exchange> |
|
| 15 |
+ <div class = pokemon> |
|
| 16 |
+ <p>From ${(exchange.user1.pseudo)!} </p>
|
|
| 17 |
+ <img src = ${(exchange.pkm1.sprite)!} alt = ${(exchange.pkm1.name)!}</img>
|
|
| 18 |
+ <h3>${(exchange.pkm1.name)!}</h3>
|
|
| 19 |
+ <p>${(exchange.pkm1.lvl)!}</p>
|
|
| 20 |
+ </div> |
|
| 21 |
+ <div class = "pokemon"> |
|
| 22 |
+ <p>Your pokemon </p> |
|
| 23 |
+ <img src = ${(exchange.dataPkm2.sprite)!} alt = ${(exchange.dataPkm2.name)!}</img>
|
|
| 24 |
+ <h3>${(exchange.dataPkm2.name)!}</h3>
|
|
| 25 |
+ <p>${(exchange.dataPkm2.lvl)!}</p>
|
|
| 26 |
+ </div> |
|
| 27 |
+ <div> |
|
| 28 |
+ |
|
| 29 |
+ <form action = "/exchange/${(exchange.id)!}/accepted" method = "POST">
|
|
| 30 |
+ <button>Accept</button> |
|
| 31 |
+ </form> |
|
| 32 |
+ <form action = "/exchange/${(exchange.id)!}/refused" method = "POST">
|
|
| 33 |
+ <button>Refuse</button> |
|
| 34 |
+ </form> |
|
| 35 |
+ </div> |
|
| 36 |
+ </li> |
|
| 37 |
+ </#list> |
|
| 38 |
+</ul> |
|
| 39 |
+ |
|
| 40 |
+</body> |
|
| 41 |
+ |
|
| 42 |
+</html> |
| ... | ... |
@@ -0,0 +1,72 @@ |
| 1 |
+<#ftl encoding="utf-8"> |
|
| 2 |
+<!DOCTYPE html> |
|
| 3 |
+<html> |
|
| 4 |
+<head> |
|
| 5 |
+<link rel="stylesheet" type="text/css" href="/style.css" media="screen"> |
|
| 6 |
+ |
|
| 7 |
+<title></title> |
|
| 8 |
+</head> |
|
| 9 |
+<body xmlns="http://www.w3.org/1999/html"> |
|
| 10 |
+ |
|
| 11 |
+<ul> |
|
| 12 |
+ <#list exchanges as exchange> |
|
| 13 |
+ |
|
| 14 |
+ <li class = exchange> |
|
| 15 |
+ <div class = pokemon> |
|
| 16 |
+ <p>By ${(exchange.user1.pseudo)!} </p>
|
|
| 17 |
+ <img src = ${(exchange.pkm1.sprite)!} alt = ${(exchange.pkm1.name)!}</img>
|
|
| 18 |
+ <h3>${(exchange.pkm1.name)!}</h3>
|
|
| 19 |
+ <p>${(exchange.pkm1.lvl)!}</p>
|
|
| 20 |
+ </div> |
|
| 21 |
+ <div class = "pokemon"> |
|
| 22 |
+ <#if exchange.dataPkm2?has_content> |
|
| 23 |
+ <p>By ${(exchange.user2.pseudo)!} </p>
|
|
| 24 |
+ <img src = ${(exchange.dataPkm2.sprite)!} alt = ${(exchange.dataPkm2.name)!}</img>
|
|
| 25 |
+ <h3>${(exchange.dataPkm2.name)!}</h3>
|
|
| 26 |
+ <p>${(exchange.dataPkm2.lvl)!}</p>
|
|
| 27 |
+ </div> |
|
| 28 |
+ <form action = "/exchange/${(exchange.id)!}/accepted" method = "POST">
|
|
| 29 |
+ <button>Accept</button> |
|
| 30 |
+ </form> |
|
| 31 |
+ <#else> |
|
| 32 |
+ <form action = "/exchange/${(exchange.id)!}/selectPokemon" method = "GET" >
|
|
| 33 |
+ <#if exchange.idPkm2?? && exchange.idPkm2.id == 0> |
|
| 34 |
+ <input type="hidden" name="pkmId" value="0"> |
|
| 35 |
+ <img src = "/pokemonSprite/0.png" alt = "Any pokemon"</img> <br> |
|
| 36 |
+ <#else> |
|
| 37 |
+ <input type="hidden" name="pkmId" value="${exchange.idPkm2.id}">
|
|
| 38 |
+ <img src = "${(exchange.idPkm2.sprite)!}" alt = "${(exchange.idPkm2.name)!}"</img>
|
|
| 39 |
+ </#if> |
|
| 40 |
+ <input type="hidden" name="pkmShiny" value="${exchange.idPkm2.shiny?c}">
|
|
| 41 |
+ <#if exchange.idPkm2?? && exchange.idPkm2.name?has_content> |
|
| 42 |
+ |
|
| 43 |
+ <#if exchange.idPkm2.shiny> |
|
| 44 |
+ <h3>Shiny ${(exchange.idPkm2.name)!}</h3>
|
|
| 45 |
+ <#else> |
|
| 46 |
+ <h3>${(exchange.idPkm2.name)!}</h3>
|
|
| 47 |
+ </#if> |
|
| 48 |
+ <#else> |
|
| 49 |
+ <h3>Any pokemon</h3> |
|
| 50 |
+ </#if> |
|
| 51 |
+ <#if exchange.idPkm2?? && exchange.idPkm2.lvl == 0> |
|
| 52 |
+ <input type="hidden" name="pkmLvl" value="0"> |
|
| 53 |
+ <h3>Any level</h3> |
|
| 54 |
+ <#else> |
|
| 55 |
+ <input type="hidden" name="pkmLvl" value="${exchange.idPkm2.lvl}">
|
|
| 56 |
+ <h3>At least level ${(exchange.idPkm2.lvl)!}</h3>
|
|
| 57 |
+ </#if> |
|
| 58 |
+ |
|
| 59 |
+ <button>Choose</button> |
|
| 60 |
+ </form> |
|
| 61 |
+ </div> |
|
| 62 |
+ <div></div> |
|
| 63 |
+ </#if> |
|
| 64 |
+ |
|
| 65 |
+ </div> |
|
| 66 |
+ </li> |
|
| 67 |
+ </#list> |
|
| 68 |
+</ul> |
|
| 69 |
+ |
|
| 70 |
+</body> |
|
| 71 |
+ |
|
| 72 |
+</html> |
| ... | ... |
@@ -0,0 +1,73 @@ |
| 1 |
+<#ftl encoding="utf-8"> |
|
| 2 |
+<!DOCTYPE html> |
|
| 3 |
+<html> |
|
| 4 |
+<head> |
|
| 5 |
+<link rel="stylesheet" type="text/css" href="/style.css" media="screen"> |
|
| 6 |
+ |
|
| 7 |
+<title></title> |
|
| 8 |
+</head> |
|
| 9 |
+<body xmlns="http://www.w3.org/1999/html"> |
|
| 10 |
+ |
|
| 11 |
+<ul> |
|
| 12 |
+ <#list exchanges as exchange> |
|
| 13 |
+ |
|
| 14 |
+ <li class = exchange> |
|
| 15 |
+ <div class = pokemon> |
|
| 16 |
+ <p>By ${(exchange.user1.pseudo)!} </p>
|
|
| 17 |
+ <img src = ${(exchange.pkm1.sprite)!} alt = ${(exchange.pkm1.name)!}</img>
|
|
| 18 |
+ <h3>${(exchange.pkm1.name)!}</h3>
|
|
| 19 |
+ <p>${(exchange.pkm1.lvl)!}</p>
|
|
| 20 |
+ </div> |
|
| 21 |
+ <div class = "pokemon"> |
|
| 22 |
+ <#if exchange.dataPkm2?has_content> |
|
| 23 |
+ <p>By ${(exchange.user2.pseudo)!} </p>
|
|
| 24 |
+ <img src = ${(exchange.dataPkm2.sprite)!} alt = ${(exchange.dataPkm2.name)!}</img>
|
|
| 25 |
+ <h3>${(exchange.dataPkm2.name)!}</h3>
|
|
| 26 |
+ <p>${(exchange.dataPkm2.lvl)!}</p>
|
|
| 27 |
+ </div> |
|
| 28 |
+ <#else> |
|
| 29 |
+ <form action = "/exchange/${(exchange.id)!}/selectPokemon" method = "GET" >
|
|
| 30 |
+ <#if exchange.idPkm2?? && exchange.idPkm2.id == 0> |
|
| 31 |
+ <input type="hidden" name="pkmId" value="0"> |
|
| 32 |
+ <img src = "/pokemonSprite/0.png" alt = "Any pokemon"</img> <br> |
|
| 33 |
+ <#else> |
|
| 34 |
+ <input type="hidden" name="pkmId" value="${exchange.idPkm2.id}">
|
|
| 35 |
+ <img src = "${(exchange.idPkm2.sprite)!}" alt = "${(exchange.idPkm2.name)!}"</img>
|
|
| 36 |
+ </#if> |
|
| 37 |
+ <input type="hidden" name="pkmShiny" value="${exchange.idPkm2.shiny?c}">
|
|
| 38 |
+ <#if exchange.idPkm2?? && exchange.idPkm2.name?has_content> |
|
| 39 |
+ |
|
| 40 |
+ <#if exchange.idPkm2.shiny> |
|
| 41 |
+ <h3>Shiny ${(exchange.idPkm2.name)!}</h3>
|
|
| 42 |
+ <#else> |
|
| 43 |
+ <h3>${(exchange.idPkm2.name)!}</h3>
|
|
| 44 |
+ </#if> |
|
| 45 |
+ <#else> |
|
| 46 |
+ <h3>Any pokemon</h3> |
|
| 47 |
+ </#if> |
|
| 48 |
+ <#if exchange.idPkm2?? && exchange.idPkm2.lvl == 0> |
|
| 49 |
+ <input type="hidden" name="pkmLvl" value="0"> |
|
| 50 |
+ <h3>Any level</h3> |
|
| 51 |
+ <#else> |
|
| 52 |
+ <input type="hidden" name="pkmLvl" value="${exchange.idPkm2.lvl}">
|
|
| 53 |
+ <h3>At least level ${(exchange.idPkm2.lvl)!}</h3>
|
|
| 54 |
+ </#if> |
|
| 55 |
+ |
|
| 56 |
+ <button>Choose</button> |
|
| 57 |
+ </form> |
|
| 58 |
+ </div> |
|
| 59 |
+ </#if> |
|
| 60 |
+ <div> |
|
| 61 |
+ <form action = "/exchange/${(exchange.id)!}/canceled" method = "POST">
|
|
| 62 |
+ <button>Cancel</button> |
|
| 63 |
+ </form> |
|
| 64 |
+ </div> |
|
| 65 |
+ |
|
| 66 |
+ </div> |
|
| 67 |
+ </li> |
|
| 68 |
+ </#list> |
|
| 69 |
+</ul> |
|
| 70 |
+ |
|
| 71 |
+</body> |
|
| 72 |
+ |
|
| 73 |
+</html> |
| ... | ... |
@@ -0,0 +1,70 @@ |
| 1 |
+<#ftl encoding="utf-8"> |
|
| 2 |
+<!DOCTYPE html> |
|
| 3 |
+<html> |
|
| 4 |
+<head> |
|
| 5 |
+<link rel="stylesheet" type="text/css" href="/style.css" media="screen"> |
|
| 6 |
+ |
|
| 7 |
+<title></title> |
|
| 8 |
+</head> |
|
| 9 |
+<body xmlns="http://www.w3.org/1999/html"> |
|
| 10 |
+ |
|
| 11 |
+ |
|
| 12 |
+<div class = exchange> |
|
| 13 |
+ <div class = pokemon> |
|
| 14 |
+ <p>By ${(exchange.user1.pseudo)!} </p>
|
|
| 15 |
+ <img src = ${(exchange.pkm1.sprite)!} alt = ${(exchange.pkm1.name)!}</img>
|
|
| 16 |
+ <h3>${(exchange.pkm1.name)!}</h3>
|
|
| 17 |
+ <p>${(exchange.pkm1.lvl)!}</p>
|
|
| 18 |
+ </div> |
|
| 19 |
+ <div class = "pokemon"> |
|
| 20 |
+ <#if exchange.dataPkm2?has_content> |
|
| 21 |
+ <p>By ${(exchange.user2.pseudo)!} </p>
|
|
| 22 |
+ <img src = ${(exchange.dataPkm2.sprite)!} alt = ${(exchange.dataPkm2.name)!}</img>
|
|
| 23 |
+ <h3>${(exchange.dataPkm2.name)!}</h3>
|
|
| 24 |
+ <p>${(exchange.dataPkm2.lvl)!}</p>
|
|
| 25 |
+ </div> |
|
| 26 |
+ <form action = "/exchange/${(exchange.id)!}/accepted" method = "POST">
|
|
| 27 |
+ <button>Accept</button> |
|
| 28 |
+ </form> |
|
| 29 |
+ <#else> |
|
| 30 |
+ |
|
| 31 |
+ |
|
| 32 |
+ <#if exchange.idPkm2?? && exchange.idPkm2.id == 0> |
|
| 33 |
+ <input type="hidden" name="pkmId" value="0"> |
|
| 34 |
+ <img src = "/pokemonSprite/0.png" alt = "Any pokemon"</img> <br> |
|
| 35 |
+ <#else> |
|
| 36 |
+ <input type="hidden" name="pkmId" value="${exchange.idPkm2.id}">
|
|
| 37 |
+ <img src = "${(exchange.idPkm2.sprite)!}" alt = "${(exchange.idPkm2.name)!}"</img>
|
|
| 38 |
+ </#if> |
|
| 39 |
+ <input type="hidden" name="pkmShiny" value="${exchange.idPkm2.shiny?c}">
|
|
| 40 |
+ <#if exchange.idPkm2?? && exchange.idPkm2.name?has_content> |
|
| 41 |
+ |
|
| 42 |
+ <#if exchange.idPkm2.shiny> |
|
| 43 |
+ <h3>Shiny ${(exchange.idPkm2.name)!}</h3>
|
|
| 44 |
+ <#else> |
|
| 45 |
+ <h3>${(exchange.idPkm2.name)!}</h3>
|
|
| 46 |
+ </#if> |
|
| 47 |
+ <#else> |
|
| 48 |
+ <h3>Any pokemon</h3> |
|
| 49 |
+ </#if> |
|
| 50 |
+ <#if exchange.idPkm2?? && exchange.idPkm2.lvl == 0> |
|
| 51 |
+ <input type="hidden" name="pkmLvl" value="0"> |
|
| 52 |
+ <h3>Any level</h3> |
|
| 53 |
+ <#else> |
|
| 54 |
+ <input type="hidden" name="pkmLvl" value="${exchange.idPkm2.lvl}">
|
|
| 55 |
+ <h3>At least level ${(exchange.idPkm2.lvl)!}</h3>
|
|
| 56 |
+ </#if> |
|
| 57 |
+ <form action = "/exchange/${(exchange.id)!}/selectPokemon" method = "GET" >
|
|
| 58 |
+ <button name = "exchangeId" value = "${(exchange.id)!}">Choose</button>
|
|
| 59 |
+ </form> |
|
| 60 |
+ </div> |
|
| 61 |
+ <div></div> |
|
| 62 |
+ </#if> |
|
| 63 |
+ |
|
| 64 |
+ </div> |
|
| 65 |
+ |
|
| 66 |
+</div> |
|
| 67 |
+ |
|
| 68 |
+</body> |
|
| 69 |
+ |
|
| 70 |
+</html> |
| ... | ... |
@@ -0,0 +1,64 @@ |
| 1 |
+<#ftl encoding="utf-8"> |
|
| 2 |
+<!DOCTYPE html> |
|
| 3 |
+<html> |
|
| 4 |
+<head> |
|
| 5 |
+<link rel="stylesheet" type="text/css" href="/style.css" media="screen"> |
|
| 6 |
+ |
|
| 7 |
+<title></title> |
|
| 8 |
+</head> |
|
| 9 |
+<body xmlns="http://www.w3.org/1999/html"> |
|
| 10 |
+ |
|
| 11 |
+ |
|
| 12 |
+<div class = exchange> |
|
| 13 |
+ <div class = pokemon> |
|
| 14 |
+ <p>By ${(exchange.user1.pseudo)!} </p>
|
|
| 15 |
+ <img src = ${(exchange.pkm1.sprite)!} alt = ${(exchange.pkm1.name)!}</img>
|
|
| 16 |
+ <h3>${(exchange.pkm1.name)!}</h3>
|
|
| 17 |
+ <p>${(exchange.pkm1.lvl)!}</p>
|
|
| 18 |
+ </div> |
|
| 19 |
+ <div> |
|
| 20 |
+ <#if exchange.dataPkm2?has_content> |
|
| 21 |
+ <img src = ${(exchange.dataPkm2.sprite)!} alt = ${(exchange.dataPkm2.name)!}</img>
|
|
| 22 |
+ <h3>${(exchange.dataPkm2.name)!}</h3>
|
|
| 23 |
+ <p>${(exchange.dataPkm2.lvl)!}</p>
|
|
| 24 |
+ <#else> |
|
| 25 |
+ <form action = "/exchange/${(exchange.id)!}/selectPokemon" method = "GET" >
|
|
| 26 |
+ <#if exchange.idPkm2?? && exchange.idPkm2.id == 0> |
|
| 27 |
+ <input type="hidden" name="pkmId" value="0"> |
|
| 28 |
+ <img src = "/pokemonSprite/0.png" alt = "Any pokemon"</img> <br> |
|
| 29 |
+ <#else> |
|
| 30 |
+ <input type="hidden" name="pkmId" value="${exchange.idPkm2.id}">
|
|
| 31 |
+ <img src = "${(exchange.idPkm2.sprite)!}" alt = "${(exchange.idPkm2.name)!}"</img>
|
|
| 32 |
+ </#if> |
|
| 33 |
+ <input type="hidden" name="pkmShiny" value="${exchange.idPkm2.shiny?c}">
|
|
| 34 |
+ <#if exchange.idPkm2?? && exchange.idPkm2.name?has_content> |
|
| 35 |
+ |
|
| 36 |
+ <#if exchange.idPkm2.shiny> |
|
| 37 |
+ <h3>Shiny ${(exchange.idPkm2.name)!}</h3>
|
|
| 38 |
+ <#else> |
|
| 39 |
+ <h3>${(exchange.idPkm2.name)!}</h3>
|
|
| 40 |
+ </#if> |
|
| 41 |
+ <#else> |
|
| 42 |
+ <h3>Any pokemon</h3> |
|
| 43 |
+ </#if> |
|
| 44 |
+ <#if exchange.idPkm2?? && exchange.idPkm2.lvl == 0> |
|
| 45 |
+ <input type="hidden" name="pkmLvl" value="0"> |
|
| 46 |
+ <h3>Any level</h3> |
|
| 47 |
+ <#else> |
|
| 48 |
+ <input type="hidden" name="pkmLvl" value="${exchange.idPkm2.lvl}">
|
|
| 49 |
+ <h3>At least level ${(exchange.idPkm2.lvl)!}</h3>
|
|
| 50 |
+ </#if> |
|
| 51 |
+ <button name = "exchangeId" value = "${(exchange.id)!}">Choose</button>
|
|
| 52 |
+ </form> |
|
| 53 |
+ </#if> |
|
| 54 |
+ |
|
| 55 |
+ </div> |
|
| 56 |
+ <form action = "/exchange/${(exchange.id)!}/accepted" method = "POST">
|
|
| 57 |
+ <input type="hidden" name="dataId" value="${exchange.dataPkm2.dataId}">
|
|
| 58 |
+ <button>Accept</button> |
|
| 59 |
+ </form> |
|
| 60 |
+</div> |
|
| 61 |
+ |
|
| 62 |
+</body> |
|
| 63 |
+ |
|
| 64 |
+</html> |
| ... | ... |
@@ -0,0 +1,51 @@ |
| 1 |
+<#ftl encoding="utf-8"> |
|
| 2 |
+<!DOCTYPE html> |
|
| 3 |
+<html> |
|
| 4 |
+<head> |
|
| 5 |
+<link rel="stylesheet" type="text/css" href="/style.css" media="screen"> |
|
| 6 |
+ |
|
| 7 |
+<title></title> |
|
| 8 |
+</head> |
|
| 9 |
+<body xmlns="http://www.w3.org/1999/html"> |
|
| 10 |
+ |
|
| 11 |
+ |
|
| 12 |
+<div class = exchange> |
|
| 13 |
+ <div class = pokemon> |
|
| 14 |
+ <p>From you </p> |
|
| 15 |
+ <img src = ${(pokemon.sprite)!} alt = ${(pokemon.name)!}</img>
|
|
| 16 |
+ <h3>${(pokemon.name)!}</h3>
|
|
| 17 |
+ <p>${(pokemon.lvl)!}</p>
|
|
| 18 |
+ </div> |
|
| 19 |
+ <div> |
|
| 20 |
+ <form action = "/user/${user.login}/exchangeOut/new" method = "POST" >
|
|
| 21 |
+ <p>Pokemon</p> |
|
| 22 |
+ <div class = exchangeForm> |
|
| 23 |
+ <input type="text" name="pkmName" placeholder = "Enter the name of the pokemon you want"> |
|
| 24 |
+ <input type="checkbox" name="anyPkm" value = "true"> |
|
| 25 |
+ <p>Any</p> |
|
| 26 |
+ </div> |
|
| 27 |
+ |
|
| 28 |
+ <p>Pokemon level</p> |
|
| 29 |
+ <div class = exchangeForm> |
|
| 30 |
+ <input type="text" name="pkmLvl" placeholder = "Enter the minimum level of the pokemon you want"> |
|
| 31 |
+ |
|
| 32 |
+ <input type="checkbox" name="anyLvl" value = "true"> |
|
| 33 |
+ <p>Any</p> |
|
| 34 |
+ </div> |
|
| 35 |
+ |
|
| 36 |
+ |
|
| 37 |
+ <p>Shiny</p> |
|
| 38 |
+ <input type="checkbox" name="pkmShiny" value = "true"> |
|
| 39 |
+ |
|
| 40 |
+ </div> |
|
| 41 |
+ <div> |
|
| 42 |
+ <input type="hidden" name="dataId" value = "${(pokemon.dataId)!}">
|
|
| 43 |
+ <input type="hidden" name="userId" value = "${(user.login)!}">
|
|
| 44 |
+ <button>Post</button> |
|
| 45 |
+ </div> |
|
| 46 |
+ </form> |
|
| 47 |
+</div> |
|
| 48 |
+ |
|
| 49 |
+</body> |
|
| 50 |
+ |
|
| 51 |
+</html> |
| ... | ... |
@@ -0,0 +1,44 @@ |
| 1 |
+<#ftl encoding="utf-8"> |
|
| 2 |
+<!DOCTYPE html> |
|
| 3 |
+<html> |
|
| 4 |
+<head> |
|
| 5 |
+<link rel="stylesheet" type="text/css" href="/style.css" media="screen"> |
|
| 6 |
+ |
|
| 7 |
+<title></title> |
|
| 8 |
+</head> |
|
| 9 |
+<body xmlns="http://www.w3.org/1999/html"> |
|
| 10 |
+ |
|
| 11 |
+ |
|
| 12 |
+<div class = exchange> |
|
| 13 |
+ <div class = pokemon> |
|
| 14 |
+ <p>From ${(exchange.user1.pseudo)!} </p>
|
|
| 15 |
+ <img src = ${(exchange.pkm1.sprite)!} alt = ${(pokemon.name)!}</img>
|
|
| 16 |
+ <h3>${(exchange.pkm1.name)!}</h3>
|
|
| 17 |
+ <p>${(exchange.pkm1.lvl)!}</p>
|
|
| 18 |
+ </div> |
|
| 19 |
+ <div> |
|
| 20 |
+ <#if exchange.dataPkm2?has_content> |
|
| 21 |
+ <img src = ${(exchange.dataPkm2.sprite)!} alt = ${(exchange.dataPkm2.name)!}</img>
|
|
| 22 |
+ <h3>${(exchange.dataPkm2.name)!}</h3>
|
|
| 23 |
+ <p>${(exchange.dataPkm2.lvl)!}</p>
|
|
| 24 |
+ <#else> |
|
| 25 |
+ <form action = "/user/${exchange.user1.login}/pokemon/${exchange.pkm1.dataId}/exchange/choosePkm" method = "GET" >
|
|
| 26 |
+ <img src = "/pokemonSprite/0.png" alt = "Any pokemon"</img> <br> |
|
| 27 |
+ <h3>Any pokemon</h3> |
|
| 28 |
+ <h3>Any level</h3> |
|
| 29 |
+ |
|
| 30 |
+ <button>Choose</button> |
|
| 31 |
+ </form> |
|
| 32 |
+ </#if> |
|
| 33 |
+ </div> |
|
| 34 |
+ <div> |
|
| 35 |
+ <form action = "/user/${exchange.user1.login}/pokemon/${exchange.pkm1.dataId}/exchange/valided/${(exchange.dataPkm2.dataId)!}" method = "POST">
|
|
| 36 |
+ |
|
| 37 |
+ <button>Post</button> |
|
| 38 |
+ </form> |
|
| 39 |
+ </div> |
|
| 40 |
+</div> |
|
| 41 |
+ |
|
| 42 |
+</body> |
|
| 43 |
+ |
|
| 44 |
+</html> |
| ... | ... |
@@ -0,0 +1,78 @@ |
| 1 |
+<!DOCTYPE html> |
|
| 2 |
+<html lang = "fr"> |
|
| 3 |
+<head> |
|
| 4 |
+ <meta charset="utf-8"> |
|
| 5 |
+ <meta name="viewport" content="width=device-width, initial-scale=1"> |
|
| 6 |
+ <link rel="stylesheet" type="text/css" href="style.css" media="screen"> |
|
| 7 |
+ |
|
| 8 |
+ |
|
| 9 |
+ <title></title> |
|
| 10 |
+ |
|
| 11 |
+ |
|
| 12 |
+ |
|
| 13 |
+</head> |
|
| 14 |
+ |
|
| 15 |
+<body> |
|
| 16 |
+ |
|
| 17 |
+ <div class="container"> |
|
| 18 |
+ <div class = logsign> |
|
| 19 |
+ <form action="/signup" method="post" id="signup" class = form> |
|
| 20 |
+ <h1>Signup</h1> |
|
| 21 |
+ <div class="field"> |
|
| 22 |
+ <label for="lastname">Pseudo :</label> |
|
| 23 |
+ <input type="text" id="pseudo" name="pseudo" placeholder="Enter you pseudo" > |
|
| 24 |
+ <small></small> |
|
| 25 |
+ </div> |
|
| 26 |
+ |
|
| 27 |
+ <div class="field"> |
|
| 28 |
+ <label for="userpwd">Password :</label> |
|
| 29 |
+ <input type="password" id="userpwd" name="userpwd" placeholder="Entrez votre mot de passe ici" > |
|
| 30 |
+ <small></small> |
|
| 31 |
+ </div> |
|
| 32 |
+ |
|
| 33 |
+ <div class="field"> |
|
| 34 |
+ <label for="usermail">Email:</label> |
|
| 35 |
+ <input type="text" id="usermail" name="usermail" placeholder="Enter your email address" > |
|
| 36 |
+ <small></small> |
|
| 37 |
+ </div> |
|
| 38 |
+ <div class="field"> |
|
| 39 |
+ <button type="submit" class="full">Signin</button> |
|
| 40 |
+ </div> |
|
| 41 |
+ <div id="zoneSignup"> |
|
| 42 |
+ <span class="Style1"></span> |
|
| 43 |
+ </div> |
|
| 44 |
+ </form> |
|
| 45 |
+ |
|
| 46 |
+ |
|
| 47 |
+ <form action="/login" method="post" id="login" class = form> |
|
| 48 |
+ <h1>Login</h1> |
|
| 49 |
+ |
|
| 50 |
+ <div class="field"> |
|
| 51 |
+ <label for="usermail">Email:</label> |
|
| 52 |
+ <input type="text" id="usermail" name="usermail" placeholder="Enter your email address" > |
|
| 53 |
+ <small></small> |
|
| 54 |
+ </div> |
|
| 55 |
+ |
|
| 56 |
+ <div class="field"> |
|
| 57 |
+ <label for="userpwd">Password :</label> |
|
| 58 |
+ <input type="password" id="userpwd" name="userpwd" placeholder="Entrez votre mot de passe ici" > |
|
| 59 |
+ <small></small> |
|
| 60 |
+ </div> |
|
| 61 |
+ |
|
| 62 |
+ |
|
| 63 |
+ <div class="field"> |
|
| 64 |
+ <button type="submit" class="full">Login</button> |
|
| 65 |
+ </div> |
|
| 66 |
+ <div id="zone"> |
|
| 67 |
+ <span class="Style1"></span> |
|
| 68 |
+ </div> |
|
| 69 |
+ </form> |
|
| 70 |
+ </div> |
|
| 71 |
+ |
|
| 72 |
+ |
|
| 73 |
+ </div> |
|
| 74 |
+ |
|
| 75 |
+ |
|
| 76 |
+ |
|
| 77 |
+</body> |
|
| 78 |
+</html> |
|
| 0 | 79 |
\ No newline at end of file |
| ... | ... |
@@ -0,0 +1,26 @@ |
| 1 |
+<#ftl encoding="utf-8"> |
|
| 2 |
+<!DOCTYPE html> |
|
| 3 |
+<html> |
|
| 4 |
+<head> |
|
| 5 |
+<link rel="stylesheet" type="text/css" href="/style.css" media="screen"> |
|
| 6 |
+ |
|
| 7 |
+<title>New pokemon</title> |
|
| 8 |
+</head> |
|
| 9 |
+ |
|
| 10 |
+<body xmlns="http://www.w3.org/1999/html"> |
|
| 11 |
+ |
|
| 12 |
+ |
|
| 13 |
+ |
|
| 14 |
+ |
|
| 15 |
+<div class = pkListItem> |
|
| 16 |
+ <img src = ${(pokemon.sprite)!} alt = ${(pokemon.name)!}</img> <br>
|
|
| 17 |
+ <h3>${(pokemon.name)!}</h3>
|
|
| 18 |
+ <form action = "/userRedirect" method = "GET"> |
|
| 19 |
+ <button>Ok</button> |
|
| 20 |
+ </form> |
|
| 21 |
+ |
|
| 22 |
+</div> |
|
| 23 |
+ |
|
| 24 |
+ |
|
| 25 |
+</body> |
|
| 26 |
+</html> |
| ... | ... |
@@ -0,0 +1,27 @@ |
| 1 |
+<#ftl encoding="utf-8"> |
|
| 2 |
+<!DOCTYPE html> |
|
| 3 |
+<html> |
|
| 4 |
+<head> |
|
| 5 |
+<link rel="stylesheet" type="text/css" href="/style.css" media="screen"> |
|
| 6 |
+ |
|
| 7 |
+<title></title> |
|
| 8 |
+</head> |
|
| 9 |
+<body xmlns="http://www.w3.org/1999/html"> |
|
| 10 |
+ |
|
| 11 |
+<ul class = pkList> |
|
| 12 |
+ <#list pokemons as pokemon> |
|
| 13 |
+ <li class = pkListItem> |
|
| 14 |
+ <img src = ${(pokemon.sprite)!} alt = ${(pokemon.name)!}</img> <br>
|
|
| 15 |
+ <h3>${(pokemon.name)!}</h3>
|
|
| 16 |
+ <p>${(pokemon.lvl)!}</p>
|
|
| 17 |
+ <form action = "/exchange/${(exchange)!}/offer" method = "POST">
|
|
| 18 |
+ <input type="hidden" name="exchangeId" value="${(exchange)!}">
|
|
| 19 |
+ <button name = "dataId" value = "${(pokemon.dataId)!}">Select</button>
|
|
| 20 |
+ </form> |
|
| 21 |
+ </li> |
|
| 22 |
+ </#list> |
|
| 23 |
+</ul> |
|
| 24 |
+ |
|
| 25 |
+</body> |
|
| 26 |
+ |
|
| 27 |
+</html> |
| ... | ... |
@@ -0,0 +1,26 @@ |
| 1 |
+<#ftl encoding="utf-8"> |
|
| 2 |
+<!DOCTYPE html> |
|
| 3 |
+<html> |
|
| 4 |
+<head> |
|
| 5 |
+<link rel="stylesheet" type="text/css" href="/style.css" media="screen"> |
|
| 6 |
+ |
|
| 7 |
+<title></title> |
|
| 8 |
+</head> |
|
| 9 |
+<body xmlns="http://www.w3.org/1999/html"> |
|
| 10 |
+ |
|
| 11 |
+<ul class = pkList> |
|
| 12 |
+ <#list pokemons as pokemon> |
|
| 13 |
+ <li class = pkListItem> |
|
| 14 |
+ <img src = ${(pokemon.sprite)!} alt = ${(pokemon.name)!}</img> <br>
|
|
| 15 |
+ <h3>${(pokemon.name)!}</h3>
|
|
| 16 |
+ <p>${(pokemon.lvl)!}</p>
|
|
| 17 |
+ <form action = "/user/${(user1)!}/pokemon/${(pkm1)!}/exchange/selected/${(pokemon.dataId)!}" method = "POST">
|
|
| 18 |
+ <button>Select</button> |
|
| 19 |
+ </form> |
|
| 20 |
+ </li> |
|
| 21 |
+ </#list> |
|
| 22 |
+</ul> |
|
| 23 |
+ |
|
| 24 |
+</body> |
|
| 25 |
+ |
|
| 26 |
+</html> |
| ... | ... |
@@ -0,0 +1,65 @@ |
| 1 |
+<#ftl encoding="utf-8"> |
|
| 2 |
+<!DOCTYPE html> |
|
| 3 |
+<html> |
|
| 4 |
+<head> |
|
| 5 |
+<link rel="stylesheet" type="text/css" href="/style.css" media="screen"> |
|
| 6 |
+ |
|
| 7 |
+<title>${user.pseudo}</title>
|
|
| 8 |
+</head> |
|
| 9 |
+ |
|
| 10 |
+<body xmlns="http://www.w3.org/1999/html"> |
|
| 11 |
+ |
|
| 12 |
+<ul class = pkList> |
|
| 13 |
+ <#list pokemons as pokemon> |
|
| 14 |
+ <li class = pkListItem> |
|
| 15 |
+ <img src = ${(pokemon.sprite)!} alt = ${(pokemon.name)!}</img> <br>
|
|
| 16 |
+ <h3>${(pokemon.name)!}</h3>
|
|
| 17 |
+ <p>${(pokemon.lvl)!}</p>
|
|
| 18 |
+ <form action = "/lvlup" method = "POST"> |
|
| 19 |
+ <input type="hidden" name="userid" value="${(user.login)!}">
|
|
| 20 |
+ <button class="btn-own" name = "dataid" value = "${(pokemon.dataId)!}">Lvl up</button>
|
|
| 21 |
+ </form> |
|
| 22 |
+ <form action = "/user/${(user.login)}/pokemon/${(pokemon.dataId)!}/exchange" method = "GET">
|
|
| 23 |
+ <button>Exchange</button> |
|
| 24 |
+ </form> |
|
| 25 |
+ </li> |
|
| 26 |
+ </#list> |
|
| 27 |
+</ul> |
|
| 28 |
+ |
|
| 29 |
+<div class = profil> |
|
| 30 |
+ <div class = left> |
|
| 31 |
+ <h2>My profile</h2> |
|
| 32 |
+ <p> |
|
| 33 |
+ ${(user.login)!} - ${(user.pseudo)!}<br>
|
|
| 34 |
+ </p> |
|
| 35 |
+ |
|
| 36 |
+ <h3>Number of pokemon : ${(userinfo.pkm)!}</h3>
|
|
| 37 |
+ |
|
| 38 |
+ <h3>Number of distinct pokemon : ${(userinfo.distinctPkm)!}</h3>
|
|
| 39 |
+ |
|
| 40 |
+ <h3>Number of shiny pokemon : ${(userinfo.shiny)!}</h3>
|
|
| 41 |
+ </div> |
|
| 42 |
+ |
|
| 43 |
+ <nav> |
|
| 44 |
+ <ul> |
|
| 45 |
+ <li> |
|
| 46 |
+ <a href = "/user/${(user.login)!}/exchangeIn">My incoming exchanges</a>
|
|
| 47 |
+ </li> |
|
| 48 |
+ <li> |
|
| 49 |
+ <a href = "/user/${(user.login)!}/exchangeOut">My outcoming exchanges</a>
|
|
| 50 |
+ </li> |
|
| 51 |
+ <li> |
|
| 52 |
+ <h4>User search</h4> |
|
| 53 |
+ <form id="searchForm" action = "/userSearch" method = "GET"> |
|
| 54 |
+ <input type="text" name="search" placeholder="Enter the id or pseudo"> |
|
| 55 |
+ <button type="submit" form="searchForm">Search</button> |
|
| 56 |
+ </form> |
|
| 57 |
+ </li> |
|
| 58 |
+ </ul> |
|
| 59 |
+ </nav> |
|
| 60 |
+</div> |
|
| 61 |
+ |
|
| 62 |
+</body> |
|
| 63 |
+</html> |
|
| 64 |
+ |
|
| 65 |
+ |
| ... | ... |
@@ -0,0 +1,51 @@ |
| 1 |
+<#ftl encoding="utf-8"> |
|
| 2 |
+<!DOCTYPE html> |
|
| 3 |
+<html> |
|
| 4 |
+<head> |
|
| 5 |
+<link rel="stylesheet" type="text/css" href="/style.css" media="screen"> |
|
| 6 |
+ |
|
| 7 |
+<title>${user.pseudo}</title>
|
|
| 8 |
+</head> |
|
| 9 |
+ |
|
| 10 |
+<body xmlns="http://www.w3.org/1999/html"> |
|
| 11 |
+ |
|
| 12 |
+<ul class = pkList> |
|
| 13 |
+ <#list pokemons as pokemon> |
|
| 14 |
+ <li class = pkListItem> |
|
| 15 |
+ <img src = ${(pokemon.sprite)!} alt = ${(pokemon.name)!}</img> <br>
|
|
| 16 |
+ <h3>${(pokemon.name)!}</h3>
|
|
| 17 |
+ <p>${(pokemon.lvl)!}</p>
|
|
| 18 |
+ <form action = "/lvlup" method = "POST"> |
|
| 19 |
+ <input type="hidden" name="userid" value="${(user.login)!}">
|
|
| 20 |
+ <button class="btn-own" name = "dataid" value = "${(pokemon.dataId)!}">Lvl up</button>
|
|
| 21 |
+ </form> |
|
| 22 |
+ <form action = "/user/${(user.login)!}/pokemon/${(pokemon.dataId)!}/exchange" method = "GET">
|
|
| 23 |
+ <button>Exchange</button> |
|
| 24 |
+ </form> |
|
| 25 |
+ </li> |
|
| 26 |
+ </#list> |
|
| 27 |
+</ul> |
|
| 28 |
+ |
|
| 29 |
+<div class = profil> |
|
| 30 |
+ <div class = left> |
|
| 31 |
+ <h2>${(user.pseudo)!}'s profile</h2>
|
|
| 32 |
+ <p> |
|
| 33 |
+ ${(user.login)!} - ${(user.pseudo)!}
|
|
| 34 |
+ </p> |
|
| 35 |
+ |
|
| 36 |
+ <h3>Number of pokemon : ${(userinfo.pkm)!}</h3>
|
|
| 37 |
+ |
|
| 38 |
+ <h3>Number of distinct pokemon : ${(userinfo.distinctPkm)!}</h3>
|
|
| 39 |
+ |
|
| 40 |
+ <h3>Number of shiny pokemon : ${(userinfo.shiny)!}</h3>
|
|
| 41 |
+ </div> |
|
| 42 |
+ |
|
| 43 |
+ <nav> |
|
| 44 |
+ <a href = "/user/${(user.login)!}/exchangeOut">Available exchange</a>
|
|
| 45 |
+ </nav> |
|
| 46 |
+</div> |
|
| 47 |
+ |
|
| 48 |
+</body> |
|
| 49 |
+</html> |
|
| 50 |
+ |
|
| 51 |
+ |
| ... | ... |
@@ -0,0 +1,18 @@ |
| 1 |
+<#ftl encoding="utf-8"> |
|
| 2 |
+ |
|
| 3 |
+<body xmlns="http://www.w3.org/1999/html"> |
|
| 4 |
+ |
|
| 5 |
+<ul> |
|
| 6 |
+ <#list users as user> |
|
| 7 |
+ <li> |
|
| 8 |
+ <h3>${(user.login)!} - ${(user.pseudo)!} </h3>
|
|
| 9 |
+ <form action = "/user/${user.login}" method = "GET">
|
|
| 10 |
+ <button>Go</button> |
|
| 11 |
+ </form> |
|
| 12 |
+ </li> |
|
| 13 |
+ </#list> |
|
| 14 |
+</ul> |
|
| 15 |
+ |
|
| 16 |
+</body> |
|
| 17 |
+ |
|
| 18 |
+</html> |
| ... | ... |
@@ -0,0 +1,13 @@ |
| 1 |
+<#ftl encoding="utf-8"> |
|
| 2 |
+ |
|
| 3 |
+<body xmlns="http://www.w3.org/1999/html"> |
|
| 4 |
+ |
|
| 5 |
+<ul> |
|
| 6 |
+ <#list users as user> |
|
| 7 |
+ <li>${(user.login)!} - ${(user.pseudo)!} ${(user.email)!} ${(user.hashpswd)!} ${(user.lastCoDate?string("dd/MM/yyyy"))!}</li>
|
|
| 8 |
+ </#list> |
|
| 9 |
+</ul> |
|
| 10 |
+ |
|
| 11 |
+</body> |
|
| 12 |
+ |
|
| 13 |
+</html> |