public function EnviarCorreo($Nombre, $ape1, $Correo, $URL, $Subject, $Mensaje) { try { $mail = new PHPMailer(); $mail->isSMTP(); $mail->SMTPSecure = 'tls'; $mail->Host = $this->host; $mail->Port = $this->port; $mail->SMTPAuth = true; $mail->Username = $this->usernameFrom; $mail->Password = $this->pass; $mail->SMTPDebug = 0; //$mail->Debugoutput = 'html'; $mail->addAddress($correo, $Nombre); $mail->From = $this->usernameFrom; $mail->FromName = $this->{$FromName}; $mail->addReplyTo($this->usernameFrom, $this->{$ReplyTo}); $mail->Subject = $Subject; $mail->WordWrap = 50; $mail->msgHTML($Mensaje); $mail->isHTML(true); $mail->send(); } catch (phpmailerException $me) { Utils::escribeLog("Error: " . $me->getMessage() . " | Fichero: " . $me->getFile() . " | Línea: " . $me->getLine() . " [Error al enviar correo]", "debug"); return false; } catch (Exception $e) { Utils::escribeLog("Error: " . $e->getMessage() . " | Fichero: " . $e->getFile() . " | Línea: " . $e->getLine() . " [Error al enviar correo]", "debug"); return false; } return true; }
public static function nuevoCliente($nom_empresa, $nombre, $apellido, $email, $telefono) { require_once 'Trabajador.php'; $retVal = 1; //0->KO / 1->OK / 2->Existe el cliente /3-> Cliente insertado correo KO Utils::escribeLog("Inicio nuevoUsuario", "debug"); $bd = Conexion::getInstance()->getDb(); try { //Antes de insertar comprobar que no exista el mismo nombre de empresa $sql = "SELECT Cliente_Id FROM Clientes WHERE Nombre=:nom_emp"; $comando = $bd->prepare($sql); $comando->execute(array(":nom_emp" => $nom_empresa)); } catch (PDOException $e) { Utils::escribeLog("Error: " . $e->getMessage() . " | Fichero: " . $e->getFile() . " | Línea: " . $e->getLine() . " [Usuario o email existentes]", "debug"); $retVal = 0; return $retVal; } $cuenta = $comando->rowCount(); if ($cuenta != 0) { Utils::escribeLog("nom_empresa y/o correo existentes en la BBDD -> KO", "debug"); $retVal = 2; return $retVal; } try { $bd->beginTransaction(); //insertar cliente $sql = "INSERT INTO Clientes(Nombre,Nombre_contacto,Apellido_contacto,Correo_contacto,Tel_contacto)VALUES\n\t\t\t(:nom_empresa,:nombre,:ape,:email,:tel)"; $comando = null; $comando = $bd->prepare($sql); $comando->execute(array(":nom_empresa" => $nom_empresa, ":nombre" => $nombre, ":ape" => $apellido, ":email" => $email, ":tel" => $telefono)); $bd->commit(); $idCli = $bd->lastInsertId(); } catch (PDOException $e) { Utils::escribeLog("Error: " . $e->getMessage() . " | Fichero: " . $e->getFile() . " | Línea: " . $e->getLine() . " [Error al insertar usuario]", "debug"); $retVal = 0; $bd->rollback(); return $retVal; } try { $key = Utils::random_string(50); Trabajador::nuevoTrabajador($nombre, $apellido, $key, $idCli, $email); } catch (PDOException $e) { Utils::escribeLog("Error: " . $e->getMessage() . " | Fichero: " . $e->getFile() . " | Línea: " . $e->getLine() . " [Error al insertar usuario]", "debug"); $retVal = 0; return $retVal; } return $retVal; //si todo va OK deveria devolver 1 }
public static function ModDispositivo($dis, $cli, $latit, $longit, $tip) { $bd = Conexion::getInstance()->getDb(); $retVal = 1; try { //$sql="UPDATE Trabajadores SET Activo='1' WHERE Trabajador_Id LIKE :id"; // $comando=$db->prepare($sql); //$comando->execute(array(':id'=>$TrabId)); //SET `Dispositivo_Id`=[value-1],`Cliente_Id`=[value-2],`Latitud`=[value-3],`Longitud`=[value-4],`Activo`=[value-5],`Barrio`=[value-6],`Tipo`=[value-7] $sql = "UPDATE Dispositivos SET Latitud=:lat,Longitud=:long,Tipo=:tip WHERE Dispositivo_Id=:dis"; $comando = $bd->prepare($sql); $comando->execute(array(":lat" => $latit, ":long" => $longit, ":tip" => $tip, ":dis" => $dis)); } catch (PDOException $e) { Utils::escribeLog("Error: " . $e->getMessage() . " | Fichero: " . $e->getFile() . " | Linea: " . $e->getLine() . " []", "debug"); $retVal = 0; return retVal; } if ($comando->rowCount() == 0) { Utils::escribeLog("Error al validar", "debug"); $retVal = 0; return $retVal; } return $retVal; }
public static function comprobarUsuario($idUsuario, $pass) { $retVal = 1; Utils::escribeLog('inicio comprobar usuario', 'debug'); //comprobar en bd try { $sql = "SELECT id_usuario,nombre,apellido1,validado FROM usuario WHERE id_usuario LIKE :id AND pass LIKE :pass"; $comando = Conexion::getInstance()->getDb()->prepare($sql); $comando->execute(array(":id" => $idUsuario, ":pass" => md5($pass))); } catch (PDOException $e) { Utils::escribeLog("Error: " . $e->getMessage() . " | Fichero: " . $e->getFile() . " | Línea: " . $e->getLine() . " ", "debug"); $retval = 0; return $retVal; } $cuenta = $comando->rowCount(); if ($cuenta == 0) { $retVal = 0; return $retVal; } $datos = $comando->fetch(PDO::FETCH_ASSOC); if ($datos['validado'] == 0) { $retVal = 2; return $retVal; } else { $_SESSION['id_usuario'] = $datos['id_usuario']; $_SESSION['nombre'] = $datos['nombre']; $_SESSION['apellido'] = $datos['apellido1']; return $retVal; } }
public static function ModDispositivo($dis, $cli, $latit, $longit, $act, $tip) { $bd = Conexion::getInstance()->getDb(); $retVal = 1; try { //comprobar si hay valores distintos $sql = "UPDATE Dispositivos SET Latitud=:lat,Longitud=:long,Tipo=:tip,Activo=:act WHERE Dispositivo_Id=:dis"; $comando = $bd->prepare($sql); $comando->execute(array(":lat" => $latit, ":long" => $longit, ":tip" => $tip, ":act" => $act, ":dis" => $dis)); } catch (PDOException $e) { Utils::escribeLog("Error: " . $e->getMessage() . " | Fichero: " . $e->getFile() . " | Linea: " . $e->getLine() . " []", "debug"); $retVal = 0; return $retVal; } if ($comando->rowCount() == 0) { Utils::escribeLog("Error al validar", "debug"); $retVal = 0; return $retVal; } return $retVal; }
public function enviarConfirmValidacion($Nombre, $ape1, $ape2 = "", $correo) { $retVal = true; Utils::escribeLog("Inicio PHPMailer confirmValidar", "debug"); $URL = $this->getURL(); try { $mail = new PHPMailer(); $mail->isSMTP(); $mail->SMTPSecure = 'tls'; $mail->Host = $this->host; $mail->Port = $this->port; $mail->SMTPAuth = true; $mail->Username = $this->usernameFrom; $mail->Password = $this->pass; $mail->SMTPDebug = 0; //$mail->Debugoutput = 'html'; $mail->addAddress($correo, $Nombre); $mail->From = $this->usernameFrom; $mail->FromName = 'Administrador TrackingApp'; $mail->addReplyTo($this->usernameFrom, 'Administrador de TrackingApp'); $mail->Subject = "Validacion de usuario realizado correctamente"; $mail->AltBody = "Validación correcta"; $mail->WordWrap = 50; //$urlValidar=getURLValidar($correo,$key); $mensaje = "<h2>Bienvenido/a " . $Nombre . " " . $ape1; if ($ape2 != "") { $mensaje .= " " . $ape2; } $mensaje .= ' a trackingApp</h2><p>Se ha confirmado correctamente su solicitud de validación de usuario en <b>TrackingApp</b></p> <p>Puede iniciar sesión y acceder a la aplicación desde aquí:</p> <p><a href="' . $URL . '">' . $URL . '</a></p>'; $mail->msgHTML($mensaje); $mail->isHTML(true); $mail->send(); } catch (phpmailerException $me) { Utils::escribeLog("Error: " . $me->getMessage() . " | Fichero: " . $me->getFile() . " | Línea: " . $me->getLine() . " [Error al enviar correo]", "debug"); return false; } catch (Exception $e) { Utils::escribeLog("Error: " . $e->getMessage() . " | Fichero: " . $e->getFile() . " | Línea: " . $e->getLine() . " [Error al enviar correo]", "debug"); } return $retVal; }
public function EnviarCorreo($Nombre, $Correo, $Subject, $Mensaje) { $res = array(); try { $mail = new PHPMailer(); $mail->isSMTP(); $mail->SMTPSecure = 'tls'; $mail->Host = $this->host; $mail->Port = $this->port; $mail->CharSet = 'UTF-8'; $mail->SMTPAuth = true; $mail->Username = $this->usernameFrom; $mail->Password = $this->pass; $mail->SMTPDebug = 0; //$mail->Debugoutput = 'html'; $mail->addAddress($Correo, $Nombre); $mail->From = $this->usernameFrom; $mail->FromName = $this->FromName; $mail->addReplyTo($this->usernameFrom, $this->ReplyTo); $mail->Subject = $Subject; $mail->WordWrap = 50; $mail->msgHTML($Mensaje); $mail->isHTML(true); if ($mail->send()) { $res['resultado'] = 1; $res['mensaje'] = "Envío correcto"; return $res; } else { $res['resultado'] = 0; $res['mensaje'] = $mail->ErrorInfo; return $res; } } catch (phpmailerException $me) { Utils::escribeLog("Error: " . $me->getMessage() . " | Fichero: " . $me->getFile() . " | Línea: " . $me->getLine() . " [Error al enviar correo]", "debug"); return false; } catch (Exception $e) { Utils::escribeLog("Error: " . $e->getMessage() . " | Fichero: " . $e->getFile() . " | Línea: " . $e->getLine() . " [Error al enviar correo]", "debug"); return false; } }
public static function changeCliente($nom_empresa, $coment, $nif, $nombre, $apellido, $correo, $telefono, $cliente, $compra) { $retVal = 1; $bd = Conexion::getInstance()->getDb(); try { $sql = "UPDATE Clientes SET Nombre=:nomempr,Comprado=:compra,Comentarios=:com,NIF=:nif,Nombre_contacto=:nom,Apellido_contacto=:apell,Correo_contacto=:cor,Tel_contacto=:tel WHERE Cliente_Id=:cli"; $comando = $bd->prepare($sql); $comando->execute(array(":nomempr" => $nom_empresa, ":compra" => $compra, ":com" => $coment, ":nif" => $nif, ":nom" => $nombre, ":apell" => $apellido, ":cor" => $correo, ":tel" => $telefono, ":cli" => $cliente)); } catch (PDOException $e) { Utils::escribeLog("Error: " . $e->getMessage() . " | Fichero: " . $e->getFile() . " | Línea: " . $e->getLine() . " [Usuario o email existentes]", "debug"); $retVal = 0; return $retVal; } if ($comando->rowCount() == 0) { Utils::escribeLog("Error al validar", "debug"); $retVal = 0; return $retVal; } return $retVal; }
public static function changeTrabajador($nom, $apel, $tel, $ema, $trabId) { $bd = Conexion::getInstance()->getDb(); $retVal = 1; try { //$sql="UPDATE Trabajadores SET Activo='1' WHERE Trabajador_Id LIKE :id"; // $comando=$db->prepare($sql); //$comando->execute(array(':id'=>$TrabId)); //SET `Dispositivo_Id`=[value-1],`Cliente_Id`=[value-2],`Latitud`=[value-3],`Longitud`=[value-4],`Activo`=[value-5],`Barrio`=[value-6],`Tipo`=[value-7] $sql = "UPDATE Trabajadores SET Nombre=:no, Apellido=:ape, Telefono=:te,Email=:em WHERE Trabajador_Id=:traId"; $comando = $bd->prepare($sql); $comando->execute(array(":no" => $nom, ":ape" => $apel, ":te" => $tel, ":em" => $ema, ":traId" => $trabId)); } catch (PDOException $e) { Utils::escribeLog("Error: " . $e->getMessage() . " | Fichero: " . $e->getFile() . " | Linea: " . $e->getLine() . " []", "debug"); $retVal = 0; return retVal; } if ($comando->rowCount() == 0) { Utils::escribeLog("Error al validar", "debug"); $retVal = 0; return $retVal; } return $retVal; }
} })->name('PaginaInicio'); //Añadir posicion $app->post('/addPos', function () use($app) { require_once 'Modelo/PosicionUsuario.php'; require_once 'Modelo/Utils.php'; sleep(1.5); $req = $app->request(); $id_usuario = $_SESSION['id_usuario']; $titulo = $req->post('titulo'); $lat = $req->post('lat'); $long = $req->post('long'); $resp = array(); if (!isset($titulo) && !isset($lat) && !isset($long)) { $result = false; Utils::escribeLog("titulo,latitud y longitud sin valor!!!!", "debug"); } else { $result = PosicionUsuario::nuevaPosicion($id_usuario, $titulo, $lat, $long); } if ($result) { $resp['estado'] = "ok"; $resp['mensaje'] = "Insertado correctamente"; } else { $resp['estado'] = "ko"; $resp['mensaje'] = "Fallo al insertar"; } echo json_encode($resp); }); //Traer posiciones del usuario $app->get('/getAllPos', function () use($app) { require_once 'Modelo/PosicionUsuario.php';
public static function nuevaPosicion($id_usuario, $titulo, $latitud, $longitud) { $retVal = true; //Utils::escribeLog("usu: ".$id_usuario." Titulo: ".$titulo." LAT: ".$latitud." LONG: ".$longitud,"debug"); try { //si la cuenta da 0 insertar $sql = "INSERT INTO posicion(id_usuario,titulo,latitud,longitud)VALUES(:id,:titulo,:lat,:long)"; $comando = Conexion::getInstance()->getDb()->prepare($sql); $comando->execute(array(":id" => $id_usuario, ":titulo" => $titulo, ":lat" => $latitud, ":long" => $longitud)); } catch (PDOException $e) { Utils::escribeLog("Error: " . $e->getMessage() . " | Fichero: " . $e->getFile() . " | Línea: " . $e->getLine() . " [Error al insertar posicion]", "debug"); $retVal = false; return $retVal; } $cuenta = $comando->rowCount(); if ($cuenta == 0) { $retVal = false; } return $retVal; }
public static function validarUsuario($correo, $key) { $retVal = 1; //0-> Fail , 1->OK, 2->Ya validado try { //Comprobar que el usuario no este validado. $sql = "SELECT id_usuario,nombre, apellido1,apellido2,email,key_usuario,validado FROM usuario WHERE email LIKE :correo and key_usuario LIKE :key"; $comando = Conexion::getInstance()->getDb()->prepare($sql); $comando->execute(array(":correo" => $correo, ":key" => $key)); } catch (PDOException $ex) { Utils::escribeLog("Error: " . $e->getMessage() . " | Fichero: " . $e->getFile() . " | Línea: " . $e->getLine() . " [Error al buscar el usuario para validar]", "debug"); $retVal = 0; return $retVal; } //comprobar filas $cuenta = $comando->rowCount(); if ($cuenta == 0) { Utils::escribeLog("No hay usuario para validar", "debug"); $retVal = 0; return $retVal; } //comprobar el estado de validado $result = $comando->fetch(PDO::FETCH_ASSOC); $id_usuario = $result['id_usuario']; $nombre = $result['nombre']; $ape1 = $result['apellido1']; $ape2 = $result['apellido2']; if ($result['validado'] === '1') { Utils::escribeLog("Ya está validado", "debug"); $retVal = 2; return $retVal; } //actualizar campo validado try { $sql = "UPDATE usuario SET validado='1' WHERE id_usuario LIKE :id"; $comando = Conexion::getInstance()->getDb()->prepare($sql); $comando->execute(array(':id' => $id_usuario)); } catch (PDOException $e) { $retVal = 0; Utils::escribeLog("Error: " . $e->getMessage() . " | Fichero: " . $e->getFile() . " | Línea: " . $e->getLine() . " [Error al buscar el usuario para validar]", "debug"); return $retVal; } //ver lineas afectadas if ($comando->rowCount() == 0) { Utils::escribeLog("Error al validar", "debug"); $retVal = 0; return $retVal; } //enviar correo de validado OK $CorreoUser = new CorreoUser(); $result = $CorreoUser->enviarConfirmValidacion($nombre, $ape1, $ape2 = "", $correo); if (!$result) { //Utils::escribeLog("Error: ".$e->getMessage()." | Fichero: ".$e->getFile()." | Línea: ".$e->getLine()." [Error al enviar correo]","debug"); $retVal = 3; return $retVal; } //Utils::escribeLog("Correo enviado OK","debug"); return $retVal; //si todo va OK deveria devolver 1 }
$app->config(array('debug' => true, 'templates.path' => 'Templates')); //Raiz de /app $app->map('/', function () use($app) { if (!isset($_SESSION['id_usuario'])) { //render login $app->render('tmp_login.php'); } else { //enviar al inicio $app->redirect($app->urlFor('PaginaInicio')); } })->via('GET')->name('Inicio'); //Registro $app->post('/registro', function () use($app) { require_once 'Modelos/Cliente.php'; require_once 'Modelos/Utils.php'; Utils::escribeLog("Inicio Registro", "debug"); $req = $app->request(); $nom_empresa = trim($req->post('nombre_empresa')); $nom = trim($req->post("nombre")); $ape = trim($req->post("apellido")); $telef = trim($req->post("telefono")); $email = trim($req->post("correo")); $result = Cliente::nuevoCliente($nom_empresa, $nom, $ape, $email, $telef); //0->KO / 1->OK / 2->Existe el usuario / 3->registro OK correo KO /*Códigos de mensajes= -err_reg_usr-->Error al registrar el usuario -usr_reg_OK-->Usuario registrado correctamente. -usr_em_exist-->Usuario o email existentes -usr_OK_em_F -->Usuario registrado, correo fallido */
public static function modTrabajador($nom, $apel, $tel, $ema, $idUsu, $imgURL = null) { $bd = Conexion::getInstance()->getDb(); $retVal = 1; if (is_null($imgURL)) { $sql = "UPDATE Trabajadores SET Nombre=:no, Apellido=:ape, Telefono=:te,Email=:em \n\t\t\t WHERE Trabajador_Id IN(SELECT Trabajador_Id\n\t\t\t\t\t\t\t\t\tFROM Usuarios\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\tWHERE Usuario_Id=:id)"; $variables = array(":no" => $nom, ":ape" => $apel, ":te" => $tel, ":em" => $ema, ":id" => $idUsu); } else { $sql = "UPDATE Trabajadores SET Nombre=:no, Apellido=:ape, Telefono=:te,Email=:em, Profile_ImageURL=:img \n\t\t\t\t WHERE Trabajador_Id IN(SELECT Trabajador_Id\n\t\t\t\t\t\t\t\t\t\tFROM Usuarios\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\tWHERE Usuario_Id=:id)"; $variables = array(":no" => $nom, ":ape" => $apel, ":te" => $tel, ":em" => $ema, "img" => $imgURL, ":id" => $idUsu); } try { $comando = $bd->prepare($sql); $comando->execute($variables); } catch (PDOException $e) { Utils::escribeLog("Error: " . $e->getMessage() . " | Fichero: " . $e->getFile() . " | Linea: " . $e->getLine() . " []", "debug"); $retVal = 0; return $retVal; } if ($comando->rowCount() == 0) { Utils::escribeLog("Error al validar", "debug"); $retVal = 0; return $retVal; } return $retVal; }
public static function validarUsuario($correo, $key) { $retVal = 1; //0-> Fail , 1->OK, 2->Ya validado $db = Conexion::getInstance()->getDb(); try { //Comprobar que el usuario no este validado. $sql = "SELECT usu.Usuario_Id, trab.Nombre,trab.Apellido,trab.Activo,trab.Trabajador_Id\n\t\t\t\t FROM Usuarios usu JOIN Trabajadores trab \n\t\t\t\t ON usu.Trabajador_Id=trab.Trabajador_Id\n\t\t\t\t WHERE trab.User_key like :key and trab.Email like :email"; $comando = $db->prepare($sql); $comando->execute(array(":key" => $key, ":email" => $correo)); } catch (PDOException $e) { Utils::escribeLog("Error: " . $e->getMessage() . " | Fichero: " . $e->getFile() . " | Línea: " . $e->getLine() . " [Error al buscar el usuario para validar]", "debug"); $retVal = 0; return $retVal; } //comprobar filas $cuenta = $comando->rowCount(); if ($cuenta == 0) { Utils::escribeLog("No hay usuario para validar", "debug"); $retVal = 0; return $retVal; } //comprobar el estado de validado $result = $comando->fetch(PDO::FETCH_ASSOC); //comprobar si el usuario ya está activo if ($result['Activo'] === '1') { Utils::escribeLog("Ya está validado", "debug"); $retVal = 2; return $retVal; } //obtenemos las variables $id_usuario = $result['Usuario_Id']; $nombre = $result['Nombre']; $ape1 = $result['Apellido']; $TrabId = $result['Trabajador_Id']; //actualizar campo validado try { $sql = "UPDATE Trabajadores SET Activo='1' WHERE Trabajador_Id LIKE :id"; $comando = $db->prepare($sql); $comando->execute(array(':id' => $TrabId)); } catch (PDOException $e) { $retVal = 0; Utils::escribeLog("Error: " . $e->getMessage() . " | Fichero: " . $e->getFile() . " | Línea: " . $e->getLine() . " [Error al buscar el usuario para validar]", "debug"); return $retVal; } //ver lineas afectadas if ($comando->rowCount() == 0) { Utils::escribeLog("Error al validar", "debug"); $retVal = 0; return $retVal; } //enviar correo de validado OK $CorreoUser = new CorreoUser(); $result = $CorreoUser->enviarConfirmValidacion($nombre, $ape1, $correo); if (!$result) { //Utils::escribeLog("Error: ".$e->getMessage()." | Fichero: ".$e->getFile()." | Línea: ".$e->getLine()." [Error al enviar correo]","debug"); $retVal = 3; return $retVal; } //Utils::escribeLog("Correo enviado OK","debug"); return $retVal; //si todo va OK deveria devolver 1 }