From 262af83b3bf20e49a4abfe5fc2da3c26d7654809 Mon Sep 17 00:00:00 2001 From: badr Date: Wed, 18 Oct 2023 17:04:21 +0200 Subject: [PATCH 01/11] fix some routes --- index.php | 63 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/index.php b/index.php index 1c77f50..6a538d5 100644 --- a/index.php +++ b/index.php @@ -20,8 +20,12 @@ $servicePartida = new ServicePartida(); $serviceUsuario = new ServiceUser(); $serviceJSON = new ServiceJSON(); +if (!empty($decode['email']) && !empty($decode['pass'])){ -$checkPersona = $serviceUsuario->login($decode['email'], $decode['pass']); + $checkPersona = $serviceUsuario->login($decode['email'], $decode['pass']); +}else{ + $checkPersona = false; +} if ($checkPersona) { $getUser = $serviceUsuario->getUser($decode['email'], $decode['pass']); @@ -42,7 +46,7 @@ $serviceUsuario->getUserById($ruta[3]); } else { $code = 402; - $msg = "PARAMETER REQUIRED"; + $msg = "PARAMETER ID REQUIRED"; $serviceJSON->send($code, $msg); } break; @@ -52,24 +56,28 @@ } break; - case 'POST': + case 'POST':{ + //ruta /admin/user if (!empty($ruta[2]) && $ruta[2] == 'user') { if(!empty($decode["user"])){ - + $newUser = new Usuario(); $newUser->setUser($decode["user"]); $serviceUsuario->createUser($newUser); + + }elseif(!empty($decode["getNewPassword"])){ + $email = $decode["getNewPassword"]["email"]; + $pass = $decode["getNewPassword"]["pass"]; + $serviceUsuario->newPassword($email, $pass); }else { noParameters($serviceJSON); } } else { noParameters($serviceJSON); } - if(!empty($decode["getNewPassword"])){ - $email = $decode["getNewPassword"]["email"]; - $pass = $decode["getNewPassword"]["pass"]; - $serviceUsuario->newPassword($email, $pass); - } + + + } break; case 'PUT':{ if(!empty($decode["update"])){ @@ -92,12 +100,17 @@ } } } - if ($user->getRole() >= 0 && $ruta[1] == 'jugar' || $ruta[1] == 'ranking') { + //caulquier otra ruta que no sea admin, luego dentro comprobaré las rutas + if (!empty($ruta[1])) { switch ($requestMethod) { case 'GET': switch ($ruta[1]) { case 'jugar':{ - $servicePartida->createPartida($user->getId()); + if(!empty($ruta[2]) && !empty($ruta[3])){ + $servicePartida->createPartida($user->getId(),$ruta[2], $ruta[3]); + }else{ + $servicePartida->createPartida($user->getId()); + } } break; case 'ranking':{ @@ -105,33 +118,37 @@ } break; case 'surrender':{ - $servicePartida->surrender($idUser); + $servicePartida->surrender($user->getId()); } + break; default: notFound($serviceJSON); + break; } break; case 'POST': - switch ($ruta[1]) { - case 'jugar': - $servicePartida->uncoverCasilla($user->getId()); - break; - default:{ - notFound($serviceJSON); + if($ruta[1] == 'jugar') { + echo $decode["pos"]; + $servicePartida->uncoverCasilla($user->getId(), $decode["pos"]); } - break; + else{ + notFound($serviceJSON); + } + break; + default:{ + notSupported($serviceJSON); } break; - default: - notSupported($serviceJSON); } } } else { // en caso de que el usuario no tenga credenciales if (!empty($ruta[1]) && $ruta[1] == 'signup') { - $serviceUsuario->createUser($decode["user"]); + $user = new Usuario(); + $user->setUser($decode["user"]); + $serviceUsuario->createUser($user); - //en caso de que el usuario tenga credenciales + //en caso de que el usuario tenga credenciales //pero no sepa su contraseña }elseif(!empty($ruta[1]) && $ruta[1] == 'password'){ if(!empty($decode["getNewPassword"])){ From e29aa204592a157c6079473fe86fda30af80af6c Mon Sep 17 00:00:00 2001 From: badr Date: Wed, 18 Oct 2023 17:14:26 +0200 Subject: [PATCH 02/11] add funcs and resolve some bugs in funcs --- Controller/Service/ServicePartida.php | 174 +++++++++++++++++++------- 1 file changed, 128 insertions(+), 46 deletions(-) diff --git a/Controller/Service/ServicePartida.php b/Controller/Service/ServicePartida.php index c7446ab..276d9c9 100644 --- a/Controller/Service/ServicePartida.php +++ b/Controller/Service/ServicePartida.php @@ -1,87 +1,169 @@ getRanking(); - + $cod = 200; $mesg = "OK"; - + $serviceJSON = new ServiceJSON(); $serviceJSON->send($cod, $mesg, $rank); } - public function uncoverCasilla($idUser, $size=null, $position=null){ + public function uncoverCasilla($idUser, $posicion) + { $partida = new ConexionPartida(); - - $tablero= $this->getTableroInvisible($idUser); - $cod = 200; - $mesg = "OK"; $serviceJSON = new ServiceJSON(); - $serviceJSON->send($cod, $mesg); + + $checkLastResultado = $partida->getLastPartida($idUser); + if ($checkLastResultado["resultado"] == 0) { + + $tab = $partida->getPartidaByUserId($idUser); + $tablero = $tab->getTFinal(); + $board = explode(",", $tablero); + $invisible = explode(",", $tab->getTVacio()); + + + if ($this->countUncovered($board) != $this->countUncovered($invisible)) { + + $additionalMsg = "BOX SUCCESSFULLY UNCOVERED"; + $normalizePosicion = $posicion - 1; + $numFlags = 0; + + if ($board[$normalizePosicion] > 0) { + $cod = 404; + $mesg = "FOUND THE FLAG, YOU LOST"; + $serviceJSON->send($cod, $mesg, $board); + $partida->updatePartidaRendirse($idUser); + $numFlags = strval($board[$normalizePosicion]); + } elseif ($board[$normalizePosicion + 1] > 0 && $board[$normalizePosicion - 1]) { + $cod = 200; + $mesg = "BE CAREFUL WITH THE RIGHT AND LEFT"; + $serviceJSON->send($cod, $mesg, $additionalMsg); + $numFlags = 2; + } elseif ($board[$normalizePosicion + 1] > 0) { + $cod = 200; + $mesg = "BE CAREFUL WITH THE RIGHT"; + $serviceJSON->send($cod, $mesg, $additionalMsg); + $numFlags = 1; + } elseif ($board[$normalizePosicion - 1]) { + + $cod = 200; + $mesg = "BE CAREFUL WITH THE LEFT"; + $serviceJSON->send($cod, $mesg, $additionalMsg); + $numFlags = 1; + } else { + $cod = 200; + $mesg = "BOX SUCCESSFULLY UNCOVERED"; + $serviceJSON->send($cod, $mesg); + } + + $invisible[$normalizePosicion] = strlen($numFlags); + print_r($invisible); + + $rtnInvisible = implode(",", $invisible); + $board[$normalizePosicion] = $numFlags; + $partida->setPosicion($idUser, $rtnInvisible); + } else { + $cod = 200; + $mesg = "YOU HAVE MARKED ALL THE FLAGS, YOU HAVE WON"; + $serviceJSON->send($cod, $mesg); + } + } else { + $cod = 404; + $mesg = "NOT FOUND BOARD FOR PLAYING"; + $serviceJSON = new ServiceJSON(); + $serviceJSON->send($cod, $mesg); + } } - public function createPartida($idUser, $size=null, $numFlags = null){ - + public function createPartida($idUser, $size = null, $numFlags = null) + { + $partida = new ConexionPartida(); $serviceJSON = new ServiceJSON(); - + /** * check para poder crear una partida si no la tiene el usuario * o si ya ha finalizado su última partida */ - $checkLastResultado = $partida->getLastPartida($idUser); - if($checkLastResultado["resultado"] != 0){ - if(empty($size) && empty($numFlags)){ - $size = Constantes::$Casilla_size; - $numFlags = Constantes::$Casillas_flags; - } - - //array con todas las flags - $tab1 = FactoryPartida::createTablero($size, $numFlags); - - //array oculto - $tab2 = array_fill(0, $size, "*"); - - $partida->insertNewPartida($idUser, $tab1, $tab2); - - $tablero= $this->getTableroInvisible($idUser); - - $cod = 201; - $mesg = "BOARD CREATED"; - $serviceJSON->send($cod, $mesg, $tablero); - - }else{ - $cod = 401; - $mesg = "BOARD NOT CREATED"; - $extra = "YOU ALREADY HAVE A BOARD CREATED"; - $serviceJSON->send($cod, $mesg, $extra); + $checkLastResultado = $partida->getLastPartida($idUser); + + if ($checkLastResultado == null || $checkLastResultado["resultado"] != 0) { + if (empty($size) && empty($numFlags)) { + $size = Constantes::$Casilla_size; + $numFlags = Constantes::$Casillas_flags; } - + + //array con todas las flags + $tab1 = FactoryPartida::createTablero($size, $numFlags); + + //array oculto + $tab2 = array_fill(0, $size, "*"); + + $partida->insertNewPartida($idUser, $tab1, $tab2); + + $tablero = $this->getTableroInvisible($idUser); + + $cod = 201; + $mesg = "BOARD CREATED"; + $serviceJSON->send($cod, $mesg, $tablero["jugando"]); + } else { + $cod = 401; + $mesg = "BOARD NOT CREATED"; + $extra = "YOU ALREADY HAVE A BOARD CREATED"; + $serviceJSON->send($cod, $mesg, $extra); + } } - public function surrender($idUser){ + public function surrender($idUser) + { $partida = new ConexionPartida(); $serviceJSON = new ServiceJSON(); - + $partida->updatePartidaRendirse($idUser); $tablero = $partida->getTableroResuelto($idUser); $cod = 201; $mesg = "OK"; $serviceJSON->send($cod, $mesg, $tablero["resuelto"]); - } - public function getTableroInvisible($idUser){ + public function getTableroInvisible($idUser) + { $partida = new ConexionPartida(); return $partida->getTableroInvisible($idUser); } -} \ No newline at end of file + + public function countUncovered($tableroFinal) + { + $rtnNumFlags = 0; + foreach ($tableroFinal as $key => $value) { + if ($value == 1) { + $rtnNumFlags++; + } + } + return $rtnNumFlags; + } + + public function countFlags($tableroFinal) + { + $rtnNumFlags = 0; + foreach ($tableroFinal as $key => $value) { + if ($value == 0) { + $rtnNumFlags++; + } + } + return $rtnNumFlags; + } +} From 359bfc18633e8f43d1a5c329826030704b74efdd Mon Sep 17 00:00:00 2001 From: badr Date: Wed, 18 Oct 2023 22:48:55 +0200 Subject: [PATCH 03/11] resolve all bugs of funcs --- Controller/Service/ServicePartida.php | 119 ++++++++++++++++---------- 1 file changed, 72 insertions(+), 47 deletions(-) diff --git a/Controller/Service/ServicePartida.php b/Controller/Service/ServicePartida.php index 276d9c9..f52c0c2 100644 --- a/Controller/Service/ServicePartida.php +++ b/Controller/Service/ServicePartida.php @@ -3,6 +3,7 @@ require_once './Controller/Conexion/ConexionPartida.php'; require_once __DIR__ . '../../../Constantes.php'; require_once './Controller/Service/ServiceJSON.php'; +require_once __DIR__.'/ServiceUser.php'; class ServicePartida { @@ -13,68 +14,85 @@ public function getRanking() $rank = $partida->getRanking(); + $rtnRank["nombre"] = $rank[0]; + $rtnRank["patidasGanadas"] = $rank[1]; + $cod = 200; $mesg = "OK"; $serviceJSON = new ServiceJSON(); - $serviceJSON->send($cod, $mesg, $rank); + $serviceJSON->send($cod, $mesg, $rtnRank ); } public function uncoverCasilla($idUser, $posicion) { $partida = new ConexionPartida(); $serviceJSON = new ServiceJSON(); + $conexionUsuario = new ServiceUser(); $checkLastResultado = $partida->getLastPartida($idUser); - if ($checkLastResultado["resultado"] == 0) { - + if ($checkLastResultado->getResultado() == 0) { + $tab = $partida->getPartidaByUserId($idUser); $tablero = $tab->getTFinal(); $board = explode(",", $tablero); $invisible = explode(",", $tab->getTVacio()); - - - if ($this->countUncovered($board) != $this->countUncovered($invisible)) { + $countBoard = $this->countUncovered($board); + $countInvisible = $this->countUncovered($invisible); + if ($countInvisible != $countBoard) { $additionalMsg = "BOX SUCCESSFULLY UNCOVERED"; + $normalizePosicion = $posicion - 1; + if($this->checkRange($normalizePosicion, count($board), 0)){ $numFlags = 0; + $cod = 200; + $msg = "OK"; if ($board[$normalizePosicion] > 0) { $cod = 404; - $mesg = "FOUND THE FLAG, YOU LOST"; - $serviceJSON->send($cod, $mesg, $board); + $msg = "FOUND THE FLAG, YOU LOST"; + + $additionalMsg = implode(",", $board); + $partida->updatePartidaRendirse($idUser); $numFlags = strval($board[$normalizePosicion]); - } elseif ($board[$normalizePosicion + 1] > 0 && $board[$normalizePosicion - 1]) { - $cod = 200; - $mesg = "BE CAREFUL WITH THE RIGHT AND LEFT"; - $serviceJSON->send($cod, $mesg, $additionalMsg); + + } elseif($normalizePosicion < count($board)-1 && $normalizePosicion > 0 && $board[$normalizePosicion + 1] > 2 && $board[$normalizePosicion - 1]>2) { + $additionalMsg = "BE CAREFUL WITH THE RIGHT AND LEFT"; $numFlags = 2; - } elseif ($board[$normalizePosicion + 1] > 0) { - $cod = 200; - $mesg = "BE CAREFUL WITH THE RIGHT"; - $serviceJSON->send($cod, $mesg, $additionalMsg); + } elseif ($normalizePosicion < count($board)-1 && $board[$normalizePosicion + 1] >2) { + $additionalMsg = "BE CAREFUL WITH THE RIGHT"; $numFlags = 1; - } elseif ($board[$normalizePosicion - 1]) { - $cod = 200; - $mesg = "BE CAREFUL WITH THE LEFT"; - $serviceJSON->send($cod, $mesg, $additionalMsg); + } elseif ($normalizePosicion> 0 && $board[$normalizePosicion - 1]>2) { + $additionalMsg = "BE CAREFUL WITH THE LEFT"; $numFlags = 1; + } else { - $cod = 200; - $mesg = "BOX SUCCESSFULLY UNCOVERED"; - $serviceJSON->send($cod, $mesg); + $additionalMsg = "BOX SUCCESSFULLY UNCOVERED"; } - $invisible[$normalizePosicion] = strlen($numFlags); - print_r($invisible); + + $invisible[$normalizePosicion] = $numFlags; $rtnInvisible = implode(",", $invisible); $board[$normalizePosicion] = $numFlags; - $partida->setPosicion($idUser, $rtnInvisible); + $rtnBoard = implode(",", $board); + + + $partida->setPosicionJugando($idUser, $rtnInvisible); + $partida->setPosicionResuelto($idUser, $rtnBoard); + + $serviceJSON->send($cod, $msg, [$additionalMsg, $rtnInvisible]); + }else{ + $cod = 400; + $mesg = "POSITION OUT OF RANGE"; + $serviceJSON->send($cod, $mesg); + } } else { + $partida->setWin($idUser); + $conexionUsuario->setCountGanadaPartida($idUser); $cod = 200; $mesg = "YOU HAVE MARKED ALL THE FLAGS, YOU HAVE WON"; $serviceJSON->send($cod, $mesg); @@ -82,7 +100,6 @@ public function uncoverCasilla($idUser, $posicion) } else { $cod = 404; $mesg = "NOT FOUND BOARD FOR PLAYING"; - $serviceJSON = new ServiceJSON(); $serviceJSON->send($cod, $mesg); } } @@ -92,6 +109,7 @@ public function createPartida($idUser, $size = null, $numFlags = null) $partida = new ConexionPartida(); $serviceJSON = new ServiceJSON(); + $conexionUsuario = new ServiceUser(); /** * check para poder crear una partida si no la tiene el usuario @@ -100,7 +118,7 @@ public function createPartida($idUser, $size = null, $numFlags = null) $checkLastResultado = $partida->getLastPartida($idUser); - if ($checkLastResultado == null || $checkLastResultado["resultado"] != 0) { + if ($checkLastResultado->getResultado() != 0) { if (empty($size) && empty($numFlags)) { $size = Constantes::$Casilla_size; $numFlags = Constantes::$Casillas_flags; @@ -115,15 +133,15 @@ public function createPartida($idUser, $size = null, $numFlags = null) $partida->insertNewPartida($idUser, $tab1, $tab2); $tablero = $this->getTableroInvisible($idUser); - + $conexionUsuario->setCountJugadaPartida($idUser); $cod = 201; $mesg = "BOARD CREATED"; - $serviceJSON->send($cod, $mesg, $tablero["jugando"]); + $serviceJSON->send($cod, $mesg, ["board" => $tablero["jugando"]]); } else { $cod = 401; $mesg = "BOARD NOT CREATED"; $extra = "YOU ALREADY HAVE A BOARD CREATED"; - $serviceJSON->send($cod, $mesg, $extra); + $serviceJSON->send($cod, $mesg, ["alert" => $extra, "board" => $checkLastResultado->getTVacio()]); } } @@ -131,13 +149,23 @@ public function surrender($idUser) { $partida = new ConexionPartida(); $serviceJSON = new ServiceJSON(); + $statusPartida = $partida->getLastPartida($idUser); + $resultadoPartida = $statusPartida->getResultado(); + + $additionalMsg = null; + if ($resultadoPartida == 0) { + $code = 201; + $msg = "OK"; + + $partida->updatePartidaRendirse($idUser); + $tablero = $partida->getTableroResuelto($idUser); + $additionalMsg = $tablero["resuelto"]; + } elseif ($resultadoPartida == 1 || $resultadoPartida == -1) { + $code = 400; + $msg = "THE LAST BOARD IS ALREADY FINISHED"; + } - $partida->updatePartidaRendirse($idUser); - $tablero = $partida->getTableroResuelto($idUser); - - $cod = 201; - $mesg = "OK"; - $serviceJSON->send($cod, $mesg, $tablero["resuelto"]); + $serviceJSON->send($code, $msg, $additionalMsg); } public function getTableroInvisible($idUser) { @@ -149,21 +177,18 @@ public function countUncovered($tableroFinal) { $rtnNumFlags = 0; foreach ($tableroFinal as $key => $value) { - if ($value == 1) { + if ($value == 1 || $value == 2 || $value == 0) { $rtnNumFlags++; } } return $rtnNumFlags; } - public function countFlags($tableroFinal) - { - $rtnNumFlags = 0; - foreach ($tableroFinal as $key => $value) { - if ($value == 0) { - $rtnNumFlags++; - } - } - return $rtnNumFlags; + + + public function checkRange($normalizePosicion, $max,$min){ + + return $normalizePosicion>=$min && $normalizePosicion<=$max; + } } From 97d94e48f0a17d848f14d51b1c7b4106bf3f2a0c Mon Sep 17 00:00:00 2001 From: badr Date: Wed, 18 Oct 2023 22:49:22 +0200 Subject: [PATCH 04/11] resolve all bugs of funcs and add funcs --- Controller/Service/ServiceUser.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Controller/Service/ServiceUser.php b/Controller/Service/ServiceUser.php index f663610..9a75226 100644 --- a/Controller/Service/ServiceUser.php +++ b/Controller/Service/ServiceUser.php @@ -140,6 +140,23 @@ public function checkId($idUser){ return $user->getId(); } + public function setCountJugadaPartida($idUser){ + $userConexion = new ConexionUsuario(); + $user = $userConexion->getUserById($idUser); + $jugadas = $user->getPartidasJugadas(); + $jugadas++; + echo $jugadas; + $userConexion->updateCountJugadaPartida($idUser, $jugadas); + } + + public function setCountGanadaPartida($idUser){ + $userConexion = new ConexionUsuario(); + $user = $userConexion->getUserById($idUser); + $ganadas = $user->getPartidasGanadas(); + $ganadas++; + $userConexion->updateCountGanadaPartida($idUser, $ganadas); + } + public function newPassword($email, $newPass = null) { $serviceJSON = new ServiceJSON(); @@ -152,9 +169,10 @@ public function newPassword($email, $newPass = null) $conexionUsuario = new ConexionUsuario(); $conexionUsuario->updatePassword($email, $hasPash); + + $nombre = $conexionUsuario->getEmail($email); - $mail = new Mail(); - $mail->sendmail(); + Mail::sendmail($email, $nombre["nombre"], $newPass); $code = 202; $mesg = "UPDATED PASSWORD"; From 4992475b012c00add6d9d69fa469a260caaffa08 Mon Sep 17 00:00:00 2001 From: badr Date: Wed, 18 Oct 2023 22:49:42 +0200 Subject: [PATCH 05/11] fix bugs --- index.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/index.php b/index.php index 6a538d5..62b56f6 100644 --- a/index.php +++ b/index.php @@ -45,9 +45,7 @@ if (!empty($ruta[3])) { $serviceUsuario->getUserById($ruta[3]); } else { - $code = 402; - $msg = "PARAMETER ID REQUIRED"; - $serviceJSON->send($code, $msg); + noParameters($serviceJSON); } break; } @@ -128,7 +126,6 @@ break; case 'POST': if($ruta[1] == 'jugar') { - echo $decode["pos"]; $servicePartida->uncoverCasilla($user->getId(), $decode["pos"]); } else{ @@ -141,9 +138,9 @@ break; } } -} else { // en caso de que el usuario no tenga credenciales - if (!empty($ruta[1]) && $ruta[1] == 'signup') { +} elseif(!empty($ruta[1]) && $ruta[1] == 'signup') { + $user = new Usuario(); $user->setUser($decode["user"]); $serviceUsuario->createUser($user); @@ -151,17 +148,20 @@ //en caso de que el usuario tenga credenciales //pero no sepa su contraseña }elseif(!empty($ruta[1]) && $ruta[1] == 'password'){ + if(!empty($decode["getNewPassword"])){ $email = $decode["getNewPassword"]["email"]; $pass = $decode["getNewPassword"]["pass"]; $serviceUsuario->newPassword($email, $pass); + }else{ + noParameters($serviceJSON); } + } else{ - $code = 401; - $msg = "ERROR USER CREDENTIALS"; - $serviceJSON->send($code, $msg); + notFound($serviceJSON); } -} + + function notFound($serviceJSON) From ad0062803223e9a972c49a198ce1146c4c062492 Mon Sep 17 00:00:00 2001 From: badr Date: Wed, 18 Oct 2023 22:50:21 +0200 Subject: [PATCH 06/11] fix send func --- Controller/Mail/Mail.php | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/Controller/Mail/Mail.php b/Controller/Mail/Mail.php index 1266787..6b082a8 100644 --- a/Controller/Mail/Mail.php +++ b/Controller/Mail/Mail.php @@ -4,15 +4,12 @@ use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\SMTP; - -require_once 'phpmailer/src/Exception.php'; -require_once 'phpmailer/src/PHPMailer.php'; -require_once 'phpmailer/src/SMTP.php'; - +require_once __DIR__.'/phpmailer/src/Exception.php'; +require_once __DIR__.'/phpmailer/src/PHPMailer.php'; +require_once __DIR__.'/phpmailer/src/SMTP.php'; class Mail { - public function sendmail($destinomail, $destinonombre, $asunto, $newPass) + static function sendmail($email, $name, $newpass) { - try { $mail = new PHPMailer(); //Configuración del servidor @@ -29,7 +26,7 @@ public function sendmail($destinomail, $destinonombre, $asunto, $newPass) $mail->setFrom(Constantes::$MAILUsername, Constantes::$MAILFromName); //Destinatarios - $mail->addAddress($destinomail, $destinonombre); //Añadir un destinatario, el nombre es opcional + $mail->addAddress($email, $name); //Añadir un destinatario, el nombre es opcional //Destinatarios opcionales // $mail->addReplyTo('info@example.com', 'Information'); //Responder a @@ -41,14 +38,15 @@ public function sendmail($destinomail, $destinonombre, $asunto, $newPass) //Nombre opcional $mail->isHTML(true); //Establecer el formato de correo electrónico en HTMl - $mail->Subject = $asunto; - $mail->Body = ` ¡Su nueva contraseña es: $newPass`; - $mail->AltBody = 'Desde Gitignore Tech esperemos que disfrute de su cuenta'; + $mail->Subject = "New Password!"; + $mail->Body = "Su nueva contraseña es: $newpass
Desde Gitignore Tech esperemos que disfrute de su cuenta"; + $mail->send(); //Enviar correo eletrónico + echo "llego hasta aquí"; } catch (Exception $e) { - + echo $e; } } } From 73c57e3577a6ae40102cb2262ac568be5a21cd6f Mon Sep 17 00:00:00 2001 From: badr Date: Wed, 18 Oct 2023 22:51:21 +0200 Subject: [PATCH 07/11] change flags 1 for 9 --- Factories/FactoryPartida.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Factories/FactoryPartida.php b/Factories/FactoryPartida.php index 002bc20..7d92d18 100644 --- a/Factories/FactoryPartida.php +++ b/Factories/FactoryPartida.php @@ -6,7 +6,7 @@ static function createTablero($size, $numFlags){ $tablero = array_fill(0,$size,0); while (0 < $numFlags) { - $tablero[rand(0,$size-1)]=1; + $tablero[rand(0,$size-1)]=9; $numFlags--; } From 163abfb5493df138a513a1bf2976400f8100ae96 Mon Sep 17 00:00:00 2001 From: badr Date: Wed, 18 Oct 2023 22:52:31 +0200 Subject: [PATCH 08/11] add some funcs and fix bugs --- Controller/Conexion/ConexionPartida.php | 116 ++++++++++++++++++++---- 1 file changed, 97 insertions(+), 19 deletions(-) diff --git a/Controller/Conexion/ConexionPartida.php b/Controller/Conexion/ConexionPartida.php index 6ac6587..ef3e04e 100644 --- a/Controller/Conexion/ConexionPartida.php +++ b/Controller/Conexion/ConexionPartida.php @@ -25,27 +25,42 @@ public function getPartidas() echo json_encode($rtn); } - public function getPartida($id) + public function getPartidaByUserId($idUser) { $con = new Conexion(); $con->conectar(); - $consulta = "SELECT * FROM PARTIDA WHERE id = ?"; + $consulta = "SELECT * FROM ". Constantes::$TABLE_partida." WHERE idUsuario = ? and resultado = 0"; - $stmt = mysqli_prepare(Conexion::$conexion, $consulta); - mysqli_stmt_bind_param($stmt, "i", $id); - mysqli_stmt_execute($stmt); + $stmt = Conexion::$conexion->prepare($consulta); + + $stmt->bind_param("i", $idUser); + + $stmt->execute(); + $resultados = $stmt->get_result(); + + $partida=$resultados->fetch_array(); + + $rtnPartida = new Partida(); + $rtnPartida->setPartida($partida); - $resultados = mysqli_stmt_get_result($stmt); $con->desconectar(); + + return $rtnPartida; + } - $rtn = []; + public function setWin($idUser){ + $con = new Conexion(); + $con->conectar(); + + $consulta = "UPDATE ". Constantes::$TABLE_partida." SET resultado = 1 WHERE idUsuario = ? and resultado = 0"; + $stmt = Conexion::$conexion->prepare($consulta); - while ($fila = mysqli_fetch_row($resultados)) { - $rtn[] = $fila[0] . "," . $fila[1] . "," . $fila[2] . "," . $fila[3]; - } + $stmt->bind_param("i", $idUser); - echo json_encode($rtn); + $stmt->execute(); + + $con->desconectar(); } public function updatePartidaRendirse($idUser) @@ -63,6 +78,34 @@ public function updatePartidaRendirse($idUser) $con->desconectar(); } + public function setPosicionJugando($idUser, $tablero) + { + $con = new Conexion(); + $con->conectar(); + + $consulta = "UPDATE ". Constantes::$TABLE_partida." SET jugando = ? WHERE idUsuario = ? and resultado = 0"; + $stmt = Conexion::$conexion->prepare($consulta); + $stmt->bind_param("si",$tablero, $idUser); + + $stmt->execute(); + + $con->desconectar(); + } + + public function setPosicionResuelto($idUser, $tablero) + { + $con = new Conexion(); + $con->conectar(); + + $consulta = "UPDATE ". Constantes::$TABLE_partida." SET resuelto = ? WHERE idUsuario = ? and resultado = 0"; + $stmt = Conexion::$conexion->prepare($consulta); + $stmt->bind_param("si",$tablero, $idUser); + + $stmt->execute(); + + $con->desconectar(); + } + public function insertPosPartida() { $con = new Conexion(); @@ -85,12 +128,12 @@ public function getTableroInvisible($idUser) $stmt->execute(); $resultados = $stmt->get_result(); - $rtnUser=$resultados->fetch_array(); - + $partida=$resultados->fetch_array(); + $con->desconectar(); - return $rtnUser; + return $partida; } public function getTableroJugando($idUser) @@ -120,7 +163,8 @@ public function getRanking() $con = new Conexion(); $con->conectar(); - $consulta = "SELECT USUARIO.nombre, count(resuelto) as ganadas FROM PARTIDA inner join USUARIO ON PARTIDA.idUsuario = USUARIO.ID where resuelto=1 GROUP by idUsuario order by ganadas"; + $consulta = "SELECT USUARIO.nombre, count(resuelto) as ganadas FROM PARTIDA inner join USUARIO ON PARTIDA.idUsuario = USUARIO.ID where resuelto=1 GROUP by idUsuario order by ganadas desc"; + $stmt = mysqli_prepare(Conexion::$conexion, $consulta); mysqli_stmt_execute($stmt); @@ -129,7 +173,7 @@ public function getRanking() $rtn = mysqli_fetch_row($resultados); - return json_encode($rtn); + return $rtn; } @@ -157,7 +201,7 @@ public function getLastPartida($idUser){ $con = new Conexion(); $con->conectar(); - $consulta = "SELECT resultado FROM ". Constantes::$TABLE_partida." where idUsuario = ? order by ID desc"; + $consulta = "SELECT * FROM ". Constantes::$TABLE_partida." where idUsuario = ? order by ID desc"; $stmt = Conexion::$conexion->prepare($consulta); @@ -166,11 +210,45 @@ public function getLastPartida($idUser){ $stmt->execute(); $resultados = $stmt->get_result(); - $rtnResultado = $resultados->fetch_array(); + $partida = $resultados->fetch_array(); + + $rtnPartida = new Partida(); + + $rtnPartida->setPartida($partida); + + // $rtnPartida = null; + // if($rtnPartida != null){ + // $rtnPartida = new Partida(); + // $rtnPartida->setPartida($partida); + // } + + $con->desconectar(); + return $rtnPartida; + } + + public function getTableroByIdUser($idUser){ + $con = new Conexion(); + $con->conectar(); + + $consulta = "SELECT * FROM ". Constantes::$TABLE_partida." WHERE idUsuario = ?"; + + $stmt = Conexion::$conexion->prepare($consulta); + + $stmt->bind_param("i", $idUser); + + $stmt->execute(); + $resultados = $stmt->get_result(); + + $partida=$resultados->fetch_array(); + + $rtnPartida = new Partida(); + $rtnPartida->setPartida($partida); + + $con->desconectar(); - return $rtnResultado; + return $rtnPartida; } public function getTableroResuelto($idUser){ From b7690e1988ac92e6613711554400702563c66ba0 Mon Sep 17 00:00:00 2001 From: badr Date: Wed, 18 Oct 2023 22:54:52 +0200 Subject: [PATCH 09/11] add some funcs and fix bugs --- Controller/Conexion/ConexionUsuario.php | 30 ++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/Controller/Conexion/ConexionUsuario.php b/Controller/Conexion/ConexionUsuario.php index 111604a..daf0469 100644 --- a/Controller/Conexion/ConexionUsuario.php +++ b/Controller/Conexion/ConexionUsuario.php @@ -1,6 +1,6 @@ conectar(); + + $consulta = "UPDATE ". Constantes::$TABLE_usuario." SET partidasJugadas = ? WHERE ID = ?"; + $stmt = Conexion::$conexion->prepare($consulta); + + $stmt->bind_param("ii", $jugadas, $idUser); + + $stmt->execute(); + + $con->desconectar(); + } + + public function updateCountGanadaPartida($idUser, $jugadas){ + $con = new Conexion(); + $con->conectar(); + + $consulta = "UPDATE ". Constantes::$TABLE_usuario." SET partidasGanadas = ? WHERE ID = ?"; + $stmt = Conexion::$conexion->prepare($consulta); + + $stmt->bind_param("ii", $jugadas, $idUser); + + $stmt->execute(); + + $con->desconectar(); + } } From 31aac4dc8e64ec8077390bd3986555980d36a497 Mon Sep 17 00:00:00 2001 From: badr Date: Wed, 18 Oct 2023 22:55:29 +0200 Subject: [PATCH 10/11] add empty parameter if needed --- Controller/Service/ServiceJSON.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Controller/Service/ServiceJSON.php b/Controller/Service/ServiceJSON.php index 92ea034..5e357e6 100644 --- a/Controller/Service/ServiceJSON.php +++ b/Controller/Service/ServiceJSON.php @@ -11,6 +11,6 @@ public function send($code, $msg, $extra=null){ echo json_encode($rtnArr); } - header("HTTP/1.1 $code $msg"); + header("HTTP/1.1 $code $msg"); } } From 723a8907f03232bb1b9dc89fcd6da143b0de8b00 Mon Sep 17 00:00:00 2001 From: badr Date: Wed, 18 Oct 2023 22:55:55 +0200 Subject: [PATCH 11/11] add some funcs --- Controller/Partida.php | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/Controller/Partida.php b/Controller/Partida.php index bf1b738..5c0b077 100644 --- a/Controller/Partida.php +++ b/Controller/Partida.php @@ -1,19 +1,31 @@ $id.''..''..''..''...; + // } - $this->id = $id; - $this->idUsuario = $idUsuario; + public function setPartida($arrValues){ + $this->setIdUsuario($arrValues["idUsuario"]); + $this->setTVacio($arrValues["jugando"]); + $this->setTFinal($arrValues["resuelto"]); + $this->setResultado($arrValues["resultado"]); + } + public function setPartida2($arrValues){ + $this->setIdUsuario($arrValues["idUsuario"]); + $this->setTVacio($arrValues["tVacio"]); + $this->setTFinal($arrValues["tFinal"]); + $this->setResultado($arrValues["resultado"]); } - + public function getId() { return $this->id; } @@ -46,11 +58,11 @@ public function setTFinal($value) { $this->tFinal = $value; } - public function getResultad() { + public function getResultado() { return $this->resultado; } - public function setResultad($value) { + public function setResultado($value) { $this->resultado = $value; } }