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

Stats

parent 1bf70669
......@@ -39,6 +39,8 @@ class UserController extends Controller {
$id = $this->request->getURIParams()[0];
return $this->deleteUser($id);
break;
case 'OPTIONS':
return Response::okresponse(json_encode("OPTIONS"));
}
return Response::errorResponse("unsupported parameters or method in user");
......@@ -106,24 +108,36 @@ class UserController extends Controller {
}
if(array_key_exists('USER_ROCK',$data)){
$rock = $data['USER_ROCK'];
}else{
$rock = $userValues->USER_ROCK + $data['USER_ROCK'];
}else{
$rock = $userValues->USER_ROCK ;
}
if(array_key_exists('USER_PAPER',$data)){
$paper = $data['USER_PAPER'] ;
}else{
$paper = $userValues->USER_PAPER + $data['USER_PAPER'];
}else{
$paper = $userValues->USER_PAPER ;
}
if(array_key_exists('USER_SCISSORS',$data)){
$scissors = $data['USER_SCISSORS'] ;
$scissors = $userValues->USER_SCISSORS + $data['USER_SCISSORS'] ;
}else{
$scissors = $userValues->USER_SCISSORS;
}
if(array_key_exists('USER_WIN',$data)){
$win = $userValues->USER_WIN + $data['USER_WIN'] ;
}else{
$win = $userValues->USER_WIN;
}
if(array_key_exists('USER_LOST',$data)){
$lost = $userValues->USER_LOST + $data['USER_LOST'] ;
}else{
$scissors = $userValues->USER_SCISSORS + $data['USER_SCISSORS'];
$lost = $userValues->USER_LOST;
}
$user = User::updateUser(array("id" => $id, "login" => $login,"email" => $email,"lastname" => $lastname,"firstname" => $firstname, "paper" => $paper, "scissors" => $scissors, "rock" => $rock));
$user = User::updateUser(array("id" => $id, "login" => $login,"email" => $email,"lastname" => $lastname,"firstname" => $firstname, "paper" => $paper, "scissors" => $scissors, "rock" => $rock, "win" => $win, "win" => $win));
$response = new Response(200,json_encode($user));
return $response;
}
......
......@@ -118,27 +118,41 @@ export default {
}
if(this.myScore >= 3){
alert("Vous avez gagné !")
this.updateUser()
console.log(user.token)
let win=1
let lost=0
this.updateUser(win, lost)
this.$router.push("/")
}
else if(this.oponentScore >= 3){
alert("Vous avez perdu ...")
this.updateUser()
let win=0
let lost=1
this.updateUser(win, lost)
this.$router.push("/")
}
},
updateUser: async function(){
let rock = this.rock
let paper = this.paper
let scissors = this.scissors
updateUser: async function(win, lost){
if(user.id<1000000){
let rock = this.rock
let paper = this.paper
let scissors = this.scissors
await fetch(
sessionStorage.getItem('APIURL') + `/user/${user.id}`,
{
method: "PUT",
body: JSON.stringify({USER_PAPER: paper, USER_ROCK: rock, USER_SCISSORS: scissors}),
}
)
console.log("ID : " +user.id)
console.log("TOKEN : " + user.token)
await fetch(
sessionStorage.getItem('APIURL') + `/user/${user.id}`,
{
method: "PUT",
headers: {
'Authorization': 'Bearer '+ user.token,
'Content-Type': 'application/json'
},
body: JSON.stringify({USER_PAPER: paper, USER_ROCK: rock, USER_SCISSORS: scissors, USER_LOST: lost, USER_WIN:win}),
}
)
}
}
,
......
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