Commit d7cc07a9 authored by Robin Borgogno's avatar Robin Borgogno

online

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