From 74870650f9fd7fa61922be6b617f921848005734 Mon Sep 17 00:00:00 2001 From: badr Date: Wed, 4 Oct 2023 11:10:52 +0200 Subject: [PATCH 1/6] =?UTF-8?q?reconfiguraci=C3=B3n=20proyecto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controller/Constantes.php => Constantes.php | 4 +++- Controller/Conexion/Conexion.php | 4 ++-- Controller/Conexion/ConexionPartida.php | 2 +- Controller/Conexion/ConexionPersona.php | 1 + 4 files changed, 7 insertions(+), 4 deletions(-) rename Controller/Constantes.php => Constantes.php (87%) diff --git a/Controller/Constantes.php b/Constantes.php similarity index 87% rename from Controller/Constantes.php rename to Constantes.php index 7db909b..bdc086b 100644 --- a/Controller/Constantes.php +++ b/Constantes.php @@ -1,5 +1,7 @@ Date: Tue, 10 Oct 2023 22:59:08 +0200 Subject: [PATCH 2/6] fix constantes --- .vscode/settings.json | 5 +++++ Constantes.php | 5 +---- Controller/Conexion/Conexion.php | 2 +- Controller/Conexion/ConexionPersona.php | 2 +- Controller/Partida.php | 7 +++---- index.php | 7 +++---- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index d606c73..f8ab1d0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,5 +9,10 @@ "mesg", "otro", "soporte" + ], + "cSpell.ignoreWords": [ + "buscaminas", + "lado", + "nada" ] } \ No newline at end of file diff --git a/Constantes.php b/Constantes.php index bdc086b..5607bb1 100644 --- a/Constantes.php +++ b/Constantes.php @@ -1,12 +1,9 @@ nada * 1 -> al lado - * 2 -> le has + * 2 -> le has dado */ $code = 0; if( $this->tablero[$pos] == '*'){ $code = 2; - }else if($this->tablero[$pos-1] == '*' || $this->tablero[$pos+1] == '*'){ + }elseif($this->tablero[$pos-1] == '*' || $this->tablero[$pos+1] == '*'){ $code = 1; } diff --git a/index.php b/index.php index 9baa5be..fb1a689 100644 --- a/index.php +++ b/index.php @@ -24,8 +24,7 @@ case 'GET': { $persona = new Persona(); - $checkPersona = $persona->checkLogin($decode['email'], $decode['pass']); - + // $checkPersona = $persona->checkLogin($decode['email'], $decode['pass']); if ($checkPersona) { $partida = new Partida(); @@ -44,14 +43,14 @@ switch ($cod) { case 0: case 1: - $partida->getTableroInvisible($idUser); + // $partida->getTableroInvisible($idUser); break; case 2: break; default: { - $partida->getTableroInvisible($idUser); + // $partida->getTableroInvisible($idUser); } break; } From 5358a4353357ef44ebbed2bbfb88efa8b5483f7a Mon Sep 17 00:00:00 2001 From: badr Date: Tue, 10 Oct 2023 23:08:35 +0200 Subject: [PATCH 3/6] refactor project --- .../Conexion/{ConexionPersona.php => ConexionUsuario.php} | 4 +++- Controller/{Partida.php => Usuario.php} | 4 ++-- index.php | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) rename Controller/Conexion/{ConexionPersona.php => ConexionUsuario.php} (96%) rename Controller/{Partida.php => Usuario.php} (97%) diff --git a/Controller/Conexion/ConexionPersona.php b/Controller/Conexion/ConexionUsuario.php similarity index 96% rename from Controller/Conexion/ConexionPersona.php rename to Controller/Conexion/ConexionUsuario.php index 42444e3..42889f7 100644 --- a/Controller/Conexion/ConexionPersona.php +++ b/Controller/Conexion/ConexionUsuario.php @@ -2,7 +2,7 @@ require __DIR__.'../Conexion.php'; -class ConexionPersona{ +class ConexionUsuario{ public function checkLogin($email,$pass){ $con = new Conexion(); $con->conectar(); @@ -31,4 +31,6 @@ public function checkLogin($email,$pass){ return $check; } + + } diff --git a/Controller/Partida.php b/Controller/Usuario.php similarity index 97% rename from Controller/Partida.php rename to Controller/Usuario.php index de7c043..5707a26 100644 --- a/Controller/Partida.php +++ b/Controller/Usuario.php @@ -2,7 +2,7 @@ require_once __DIR__.'/Conexion/Conexion.php'; -class Partida{ +class Usuario{ private $tablero; @@ -35,4 +35,4 @@ public function crearTablero($size, $numMinas){ $this->tablero =$rtnVec; } -} \ No newline at end of file +} diff --git a/index.php b/index.php index fb1a689..601cc58 100644 --- a/index.php +++ b/index.php @@ -25,8 +25,9 @@ $persona = new Persona(); // $checkPersona = $persona->checkLogin($decode['email'], $decode['pass']); + if ($checkPersona) { - $partida = new Partida(); + $partida = new Usuario(); if (!empty($v[1] && !empty($v[2]))) { From 8f85841933bd45d333b065b9603c38bfc6431b6b Mon Sep 17 00:00:00 2001 From: badr Date: Tue, 10 Oct 2023 23:49:20 +0200 Subject: [PATCH 4/6] add function change pw --- Controller/Conexion/ConexionUsuario.php | 28 ++++++++++++++++++++++--- Controller/{Persona.php => Partida.php} | 2 +- Controller/Usuario.php | 23 +++++++++++++++++++- index.php | 13 +++++++----- 4 files changed, 56 insertions(+), 10 deletions(-) rename Controller/{Persona.php => Partida.php} (50%) diff --git a/Controller/Conexion/ConexionUsuario.php b/Controller/Conexion/ConexionUsuario.php index 42889f7..bea3e90 100644 --- a/Controller/Conexion/ConexionUsuario.php +++ b/Controller/Conexion/ConexionUsuario.php @@ -11,13 +11,15 @@ public function checkLogin($email,$pass){ $stmt = mysqli_prepare(Conexion::$conexion, $consulta); - mysqli_stmt_bind_param($stmt, "ss", $email, $pass); + $parsePw = md5($pass); + + mysqli_stmt_bind_param($stmt, "ss", $email, $parsePw); mysqli_stmt_execute($stmt); $resultados = mysqli_stmt_get_result($stmt); $rtn = []; - $i = 0; + while ($fila = mysqli_fetch_row($resultados)) { $rtn[] = [$fila[1],$fila[2]]; } @@ -32,5 +34,25 @@ public function checkLogin($email,$pass){ return $check; } - + public function updatePassword($id, $newPw){ + $con = new Conexion(); + $con->conectar(); + + $consulta = "UPDATE USUARIO SET pass = ? WHERE id = ? "; + + $stmt = mysqli_prepare(Conexion::$conexion, $consulta); + + $hashPw = md5($newPw); + + mysqli_stmt_bind_param($stmt, "si", $hashPw, $id); + + mysqli_stmt_execute($stmt); + + $con->desconectar(); + + } + + + + } diff --git a/Controller/Persona.php b/Controller/Partida.php similarity index 50% rename from Controller/Persona.php rename to Controller/Partida.php index 1c7fe80..c540390 100644 --- a/Controller/Persona.php +++ b/Controller/Partida.php @@ -1,6 +1,6 @@ id = $id; + $this->email= $email; + $this->pass = $pass; + } public function darManotazo($pos){ /** @@ -34,5 +47,13 @@ public function crearTablero($size, $numMinas){ $this->tablero =$rtnVec; } + + public function changePassword($newPw){ + $conexionUsuario = new ConexionUsuario(); + + $conexionUsuario->updatePassword(1, $newPw); + } } + + diff --git a/index.php b/index.php index 601cc58..f6a9f51 100644 --- a/index.php +++ b/index.php @@ -2,7 +2,7 @@ require_once './Controller/Partida.php'; -require_once './Controller/Persona.php'; +require_once './Controller/Usuario.php'; header("Content-Type:application/json"); @@ -15,21 +15,24 @@ $v = explode('/', $paths); unset($v[0]); +print_r($decode); $cod = 200; $mesg = "todo bien"; +$partida = new Usuario(1, $decode['email'], $decode['pass']); +$partida->changePassword("1234"); + switch ($requestMethod) { case 'GET': { - $persona = new Persona(); - // $checkPersona = $persona->checkLogin($decode['email'], $decode['pass']); + $conexionUsuario = new ConexionUsuario(); + $checkPersona = $conexionUsuario->checkLogin($decode['email'], $decode['pass']); if ($checkPersona) { - $partida = new Usuario(); - if (!empty($v[1] && !empty($v[2]))) { + $partida = new Usuario($v[1], $v[2]); $partida->crearTablero($v[1], $v[2]); From 9d41336ee79baceb8d11d696d9bf1a895541ee0d Mon Sep 17 00:00:00 2001 From: badr Date: Wed, 11 Oct 2023 08:58:24 +0200 Subject: [PATCH 5/6] fix some bugs --- Controller/Conexion/ConexionPartida.php | 24 +++++++++++++++++++++++- index.php | 6 +----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Controller/Conexion/ConexionPartida.php b/Controller/Conexion/ConexionPartida.php index 203c8ed..6bed9e2 100644 --- a/Controller/Conexion/ConexionPartida.php +++ b/Controller/Conexion/ConexionPartida.php @@ -2,7 +2,7 @@ require __DIR__.'/Controller/Conexion.php'; class ConexionPartida{ - public function getPartida(){ + public function getPartidas(){ $con = new Conexion(); $con->conectar(); @@ -23,6 +23,28 @@ public function getPartida(){ echo json_encode($rtn); } + public function getPartida($id){ + $con = new Conexion(); + $con->conectar(); + + $consulta = "SELECT * FROM PARTIDA WHERE id = ?"; + + $stmt = mysqli_prepare(Conexion::$conexion, $consulta); + mysqli_stmt_bind_param($stmt, "i", $id); + mysqli_stmt_execute($stmt); + + $resultados = mysqli_stmt_get_result($stmt); + $con->desconectar(); + + $rtn= []; + + while ($fila = mysqli_fetch_row($resultados)) { + $rtn[] = $fila[0].",". $fila[1].",".$fila[2].",".$fila[3]; + } + + echo json_encode($rtn); + } + public function updatePartida($posicion){ $con = new Conexion(); $con->conectar(); diff --git a/index.php b/index.php index f6a9f51..003ac8f 100644 --- a/index.php +++ b/index.php @@ -15,14 +15,10 @@ $v = explode('/', $paths); unset($v[0]); -print_r($decode); $cod = 200; $mesg = "todo bien"; -$partida = new Usuario(1, $decode['email'], $decode['pass']); -$partida->changePassword("1234"); - switch ($requestMethod) { case 'GET': { @@ -32,7 +28,7 @@ if ($checkPersona) { if (!empty($v[1] && !empty($v[2]))) { - $partida = new Usuario($v[1], $v[2]); + $user = new Usuario(1,$decode['email'], $decode['pass']); $partida->crearTablero($v[1], $v[2]); From ccab36a5edb0790abebda4bd64ca9aaf46941194 Mon Sep 17 00:00:00 2001 From: badr Date: Wed, 11 Oct 2023 08:59:13 +0200 Subject: [PATCH 6/6] add create user function --- Controller/Conexion/ConexionUsuario.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Controller/Conexion/ConexionUsuario.php b/Controller/Conexion/ConexionUsuario.php index bea3e90..465f8a0 100644 --- a/Controller/Conexion/ConexionUsuario.php +++ b/Controller/Conexion/ConexionUsuario.php @@ -52,6 +52,22 @@ public function updatePassword($id, $newPw){ } + function createUser($email, $pass, $nombre){ + $con = new Conexion(); + $con->conectar(); + + $consulta = "INSERT INTO USUARIO (email, pass, nombre) VALUES (?, ?, ?)"; + + $stmt = mysqli_prepare(Conexion::$conexion, $consulta); + + $hashPw = md5($pass); + + mysqli_stmt_bind_param($stmt, "sss", $email, $hashPw, $nombre); + + mysqli_stmt_execute($stmt); + + $con->desconectar(); + }