Commit e94f5fe2 authored by thibaut-felten's avatar thibaut-felten

Statistiques

parent 9d25bcbe
......@@ -137,7 +137,7 @@ class UserController extends Controller {
$lost = $userValues->USER_LOST;
}
$user = User::updateUser(array("id" => $id, "login" => $login,"email" => $email,"lastname" => $lastname,"firstname" => $firstname, "paper" => $paper, "scissors" => $scissors, "rock" => $rock, "win" => $win, "win" => $win));
$user = User::updateUser(array("id" => $id, "login" => $login,"email" => $email,"lastname" => $lastname,"firstname" => $firstname, "paper" => $paper, "scissors" => $scissors, "rock" => $rock, "win" => $win, "lost" => $lost));
$response = new Response(200,json_encode($user));
return $response;
}
......
......@@ -13,7 +13,7 @@ User::addSqlQuery('USER_BY_ID',
'SELECT * FROM USER WHERE USER_ID=:user_id');
User::addSqlQuery('USER_UPDATE',
"UPDATE USER SET USER_LOGIN=:login, USER_EMAIL=:email, USER_LASTNAME=:lastname, USER_FIRSTNAME=:firstname, USER_ROCK=:rock, USER_SCISSORS=:scissors, USER_PAPER=:paper WHERE USER_ID=:id");
"UPDATE USER SET USER_LOGIN=:login, USER_EMAIL=:email, USER_LASTNAME=:lastname, USER_FIRSTNAME=:firstname, USER_ROCK=:rock, USER_SCISSORS=:scissors, USER_PAPER=:paper, USER_WIN=:win, USER_LOST=:lost WHERE USER_ID=:id");
User::addSqlQuery('USER_DELETE',
"DELETE FROM USER WHERE USER_ID=:id");
......
let user = {
token: "",
name: "",
id: Math.floor(Math.random() * 1000000 + 1000000)
id: Math.floor(Math.random() * 1000000 + 1000000),
win:0,
lost:0,
paper:0,
scissors:0,
rock:0
}
module.exports = user
\ No newline at end of file
......@@ -64,6 +64,11 @@ const routes = [
path: "/online",
name: "Online",
component: () => import(/* webpackChunkName: "login" */ '../views/Online.vue')
},
{
path: "/stats",
name: "Stats",
component: () => import(/* webpackChunkName: "login" */ '../views/stats.vue')
}
]
......
......@@ -6,6 +6,9 @@
<button class="btn-login play">
<router-link to="/choixPartie">Jouer</router-link>
</button>
<button class="btn-login play">
<router-link v-if="user.id<1000000" to="/stats">Statistiques</router-link>
</button>
</div>
</div>
</div>
......@@ -27,7 +30,7 @@
}
.play{
margin: 25%;
margin: 10%;
}
.accueil{
......
......@@ -136,7 +136,7 @@ export default {
let paper = this.paper
let scissors = this.scissors
console.log("ID : " +user.id)
console.log("ID : " + user.id)
console.log("TOKEN : " + user.token)
await fetch(
sessionStorage.getItem('APIURL') + `/user/${user.id}`,
......@@ -150,9 +150,7 @@ export default {
}
)
}
}
,
resetGame: async function(result) {
......
......@@ -113,7 +113,10 @@ export default {
.then(response => {
user.token = response.jwt_token
user.id = response.data.id
user.login = response.data.login
user.name = response.data.name
user.first = response.data.firstname
user.last = response.data.lastname
user.email = response.data.email
})
.then(this.$router.push("/"))
}
......
......@@ -21,14 +21,6 @@
<label for="Email"> Email </label>
<input v-model="email" type="email" name="Email" required>
</div>
<div class="row lmargin">
<label for="Password"> Mot de passe </label>
<input v-model="password" type="password" name="Password" required>
</div>
<div class="row lmargin">
<label for="ConfirmPassword"> Confirmer MdP </label>
<input v-model="confirmpassword" type="password" name="ConfirmPassword" required>
</div>
<div class="row lmargin">
<button type="submit" class="btn"> Valider </button>
</div>
......@@ -102,9 +94,7 @@ export default {
firstname:"",
lastname:"",
login:"",
email:"",
password:"",
confirmpassword:""
email:""
}
},
methods: {
......@@ -113,35 +103,27 @@ export default {
let lastname = this.lastname
let login = this.login
let email = this.email
let password = this.password
let confirm = this.confirmpassword
if(confirm !== password){
window.alert("Les mots de passe ne correspondent pas")
return false
}else{
var bcrypt = require('bcryptjs');
var salt = "$2a$08$c0GzKSB8g6.rZLF98GJvQu"
var hash = bcrypt.hashSync(password, salt)
let data = {
"USER_FIRSTNAME": firstname,
"USER_FIRSTNAME":firstname,
"USER_LASTNAME":lastname,
"USER_LOGIN":login,
"USER_EMAIL":email,
"USER_PASSWORD":hash,
"USER_ROLE":1
"USER_EMAIL":email
}
this.call(data)
}
},
call: function(data){
const url = sessionStorage.getItem('APIURL') + "/user"
const url = sessionStorage.getItem('APIURL') + `/user/${user.id}`
var params = {
method: 'POST',
method: 'PUT',
headers: {
'Authorization': 'Bearer '+ user.token,
'Content-Type': 'application/json'
},
body : JSON.stringify(data) };
console.log(params.body.lastname)
......
<template>
<div class="stats">
<LoginNavbar></LoginNavbar>
<div class="row _centered">
<div class="column _600">
<h1>Statistiques des parties</h1>
<table>
<tr>
<th>Victoires</th>
<td>{{user.win}}</td>
</tr>
<tr>
<th>Défaites</th>
<td>{{user.lost}}</td>
</tr>
<tr>
<th>Pierres</th>
<td>{{user.rock}}</td>
</tr>
<tr>
<th>Papiers</th>
<td>{{user.paper}}</td>
</tr>
<tr>
<th>Ciseaux</th>
<td>{{user.scissors}}</td>
</tr>
</table>
</div>
</div>
</div>
</template>
<style scoped>
._600{
max-width: 600px;
}
._centered{
justify-content: center;
}
.stats{
height: 100%;
margin: 0 auto;
max-width: 1200px;
}
</style>
<script>
const user = require("../model/user.js")
export default {
name: 'Stats',
components: {
LoginNavbar
},
data: function(){
return {
user
}
},
methods: {
getStats: async function() {
await fetch(
sessionStorage.getItem('APIURL') + `/user/${user.id}`,
{
method: "GET",
}
)
.then(response=>response.json())
.then(response => {
user.paper = response[0].USER_PAPER
user.rock = response[0].USER_ROCK
user.scissors = response[0].USER_SCISSORS
user.win = response[0].USER_WIN
user.lost = response[0].USER_LOST
}
)
}
},
beforeMount(){
this.getStats();
},
}
import LoginNavbar from '../components/LoginNavbar.vue'
</script>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment