Commit d7cc07a9 authored by Robin Borgogno's avatar Robin Borgogno

online

parents 8d87d952 a9b1f5fb
...@@ -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");
...@@ -105,7 +107,37 @@ class UserController extends Controller { ...@@ -105,7 +107,37 @@ class UserController extends Controller {
$firstname = $userValues->USER_FIRSTNAME; $firstname = $userValues->USER_FIRSTNAME;
} }
$user = User::updateUser(array("id" => $id, "login" => $login,"email" => $email,"lastname" => $lastname,"firstname" => $firstname)); if(array_key_exists('USER_ROCK',$data)){
$rock = $userValues->USER_ROCK + $data['USER_ROCK'];
}else{
$rock = $userValues->USER_ROCK ;
}
if(array_key_exists('USER_PAPER',$data)){
$paper = $userValues->USER_PAPER + $data['USER_PAPER'];
}else{
$paper = $userValues->USER_PAPER ;
}
if(array_key_exists('USER_SCISSORS',$data)){
$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{
$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));
$response = new Response(200,json_encode($user)); $response = new Response(200,json_encode($user));
return $response; return $response;
} }
......
...@@ -13,7 +13,7 @@ User::addSqlQuery('USER_BY_ID', ...@@ -13,7 +13,7 @@ User::addSqlQuery('USER_BY_ID',
'SELECT * FROM USER WHERE USER_ID=:user_id'); 'SELECT * FROM USER WHERE USER_ID=:user_id');
User::addSqlQuery('USER_UPDATE', User::addSqlQuery('USER_UPDATE',
"UPDATE USER SET USER_LOGIN=:login, USER_EMAIL=:email, USER_LASTNAME=:lastname, USER_FIRSTNAME=:firstname 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 WHERE USER_ID=:id");
User::addSqlQuery('USER_DELETE', User::addSqlQuery('USER_DELETE',
"DELETE FROM USER WHERE USER_ID=:id"); "DELETE FROM USER WHERE USER_ID=:id");
......
...@@ -4,6 +4,8 @@ import router from './router' ...@@ -4,6 +4,8 @@ import router from './router'
Vue.config.productionTip = false Vue.config.productionTip = false
sessionStorage.setItem('APIURL', 'http://localhost/projet-cdaw/backend/MVC/api.php')
new Vue({ new Vue({
router, router,
render: h => h(App) render: h => h(App)
......
...@@ -34,7 +34,7 @@ export default { ...@@ -34,7 +34,7 @@ export default {
name: 'AdminPrivate', name: 'AdminPrivate',
methods: { methods: {
createIdGame: async function(){ createIdGame: async function(){
const url = "http://localhost/felten/projet-cdaw/backend/MVC/api.php/game" const url = sessionStorage.getItem('APIURL') + "/game"
let data = { let data = {
"GAME_DESC": "testHTML", "GAME_DESC": "testHTML",
...@@ -69,7 +69,7 @@ export default { ...@@ -69,7 +69,7 @@ export default {
await this.JoueurPresent() await this.JoueurPresent()
}, },
ajoutAdminGame: async function(){ ajoutAdminGame: async function(){
const url = "http://localhost/felten/projet-cdaw/backend/MVC/api.php/gameuser" const url = sessionStorage.getItem('APIURL') + "/gameuser"
console.log(game.id) console.log(game.id)
let data = { let data = {
"GAME_ID": game.id, "GAME_ID": game.id,
...@@ -83,7 +83,7 @@ export default { ...@@ -83,7 +83,7 @@ export default {
await fetch(url,params) await fetch(url,params)
}, },
JoueurPresent: async function(){ JoueurPresent: async function(){
let url = "http://localhost/felten/projet-cdaw/backend/MVC/api.php/gameuser/game" let url = sessionStorage.getItem('APIURL') + "/gameuser/game"
console.log(game.id) console.log(game.id)
url += "/" + game.id; url += "/" + game.id;
var params = { var params = {
......
...@@ -39,7 +39,7 @@ const user = require("../model/user.js") ...@@ -39,7 +39,7 @@ const user = require("../model/user.js")
export default { export default {
name: "RockPaperScissors", name: "RockPaperScissors",
data: function () { data: function () {
return { oponentScore: 0, myScore: 0 } return { oponentScore: 0, myScore: 0 , rock : 0, paper : 0, scissors: 0}
}, },
methods: { methods: {
select: async function (value) { select: async function (value) {
...@@ -51,7 +51,7 @@ export default { ...@@ -51,7 +51,7 @@ export default {
havePlayed = true havePlayed = true
document.getElementById(value).classList.add("selected") document.getElementById(value).classList.add("selected")
await fetch( await fetch(
`http://localhost/felten/projet-cdaw/backend/MVC/api.php/result/${gameID}`, sessionStorage.getItem('APIURL') + `/result/${gameID}`,
{ {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
...@@ -64,7 +64,7 @@ export default { ...@@ -64,7 +64,7 @@ export default {
}, },
getResult: async function(gameID,value) { getResult: async function(gameID,value) {
const res = await fetch( const res = await fetch(
`http://localhost/felten/projet-cdaw/backend/MVC/api.php/result/${gameID}`, sessionStorage.getItem('APIURL') + `/result/${gameID}`,
{ {
method: "GET" method: "GET"
} }
...@@ -90,6 +90,7 @@ export default { ...@@ -90,6 +90,7 @@ export default {
} }
const valueAgainst = result[i]['RESULT_AWNSER'] const valueAgainst = result[i]['RESULT_AWNSER']
if(value === "paper"){ if(value === "paper"){
this.paper += 1
if(valueAgainst === "rock"){ if(valueAgainst === "rock"){
this.myScore +=1 this.myScore +=1
} }
...@@ -97,6 +98,7 @@ export default { ...@@ -97,6 +98,7 @@ export default {
this.oponentScore +=1 this.oponentScore +=1
} }
}else if(value === "rock"){ }else if(value === "rock"){
this.rock +=1
if(valueAgainst === "paper"){ if(valueAgainst === "paper"){
this.oponentScore+=1 this.oponentScore+=1
} }
...@@ -104,6 +106,7 @@ export default { ...@@ -104,6 +106,7 @@ export default {
this.myScore +=1 this.myScore +=1
} }
}else{ }else{
this.scissors+=1
if(valueAgainst === "paper"){ if(valueAgainst === "paper"){
this.myScore +=1 this.myScore +=1
} }
...@@ -113,13 +116,44 @@ export default { ...@@ -113,13 +116,44 @@ export default {
} }
if(this.myScore >= 3){ if(this.myScore >= 3){
alert("Vous avez gagné !") alert("Vous avez gagné !")
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 ...")
let win=0
let lost=1
this.updateUser(win, lost)
this.$router.push("/") this.$router.push("/")
} }
}, },
updateUser: async function(win, lost){
if(user.id<1000000){
let rock = this.rock
let paper = this.paper
let scissors = this.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}),
}
)
}
}
,
resetGame: async function(result) { resetGame: async function(result) {
let i = 0; let i = 0;
...@@ -127,7 +161,7 @@ export default { ...@@ -127,7 +161,7 @@ export default {
i = 1 i = 1
} }
await fetch( await fetch(
'http://localhost/felten/projet-cdaw/backend/MVC/api.php/result', sessionStorage.getItem('APIURL') + '/result',
{ {
method: "DELETE", method: "DELETE",
body: JSON.stringify({USER_ID: result[i]['USER_ID']}) body: JSON.stringify({USER_ID: result[i]['USER_ID']})
......
...@@ -138,11 +138,7 @@ export default { ...@@ -138,11 +138,7 @@ export default {
}, },
call: function(data){ call: function(data){
// Felten config const url = sessionStorage.getItem('APIURL') + "/user"
// const url = "http://localhost/projet-cdaw/backend/MVC/api.php/user"
// Robin config
const url = "http://localhost/felten/projet-cdaw/backend/MVC/api.php/user"
var params = { var params = {
method: 'POST', method: 'POST',
......
...@@ -24,7 +24,7 @@ export default { ...@@ -24,7 +24,7 @@ export default {
if((Number(this.idgame) != this.idgame || Number(this.idgame) < 0 )){ if((Number(this.idgame) != this.idgame || Number(this.idgame) < 0 )){
return return
} }
const url = "http://localhost/felten/projet-cdaw/backend/MVC/api.php/gameuser" const url = sessionStorage.getItem('APIURL') + "/gameuser"
let data = { let data = {
"GAME_ID": this.idgame, "GAME_ID": this.idgame,
......
...@@ -96,11 +96,7 @@ export default { ...@@ -96,11 +96,7 @@ export default {
}, },
call: function(login, password){ call: function(login, password){
// Felten config const url = sessionStorage.getItem('APIURL') + "/login"
// const url = "http://localhost/projet-cdaw/backend/MVC/api.php/login"
// Robin config
const url = "http://localhost/felten/projet-cdaw/backend/MVC/api.php/login"
let data = { let data = {
login: login, login: login,
......
...@@ -37,7 +37,7 @@ export default { ...@@ -37,7 +37,7 @@ export default {
return game.id return game.id
}, },
JoueurPresent: async function(){ JoueurPresent: async function(){
let url = "http://localhost/felten/projet-cdaw/backend/MVC/api.php/gameuser/game" let url = sessionStorage.getItem('APIURL') + "/gameuser/game"
console.log(game.id) console.log(game.id)
url += "/" + game.id; url += "/" + game.id;
var params = { var params = {
......
...@@ -138,7 +138,7 @@ export default { ...@@ -138,7 +138,7 @@ export default {
}, },
call: function(data){ call: function(data){
const url = "http://localhost/projet-cdaw/backend/MVC/api.php/user" const url = sessionStorage.getItem('APIURL') + "/user"
var params = { var params = {
method: 'POST', method: 'POST',
......
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