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

Stats

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